aboutsummaryrefslogtreecommitdiffstats
path: root/examples/love.alv
blob: 0820085128141616c168cc2f6577856eb17e0e3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#(
  This example draws a rotating rectangle that follows the mouse cursor.
  The size changes when the left mouse button is held, and the color
  changes when space is pressed.
)
([1]import* love math time array)

([20]def
  #(cycle colors when space is pressed)
  fill-color ([21]switch ([22]key-presses "space")
    [0.3 0 0.9]
    [0 0.9 0.3]
    [0.9 0.3 0]
    [0.3 0.9 0]
    [0 0.3 0.9]
    [0.9 0 0.3])

  #(smooth out rgb channels individually)
  smooth-color ([36]map fill-color
    ([32]fn (i) ([33]smooth 0.1 i))))

([2]draw ([3]->>
  ([8]rectangle 'fill' 100 100)
  ([14]color smooth-color)
  ([15]scale ([34]smooth 0.2 ([16]switch ([17]mouse-down? 1) 0.5 1)))
  ([5]rotate ([9]ramp 2 tau)) #(rotate tau (2*PI) every 2 seconds)
  ([4]translate ([10]mouse-pos)) #(move to mouse cursor)
))