examples

confetti.js

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
xpos = 0.5
range = (a,b) => (b-a)*Math.random() + a

times(350, () => {
  let c = display.circle(random.pos(), random.num(2,6))
  c.color = color.hsb(random.num(0,360), 75, 95)
  
  c.vx = range(0, 2) + 8 * xpos - 5
  c.vy = 0.7 * c.radius + range(-1, 1)
  c.dop = -(0.006 * range(1,4))
})

update(() => {
  xpos = input.x / display.width

  display.all((elem) => {
    elem.x += elem.vx
    elem.y += elem.vy
    elem.alpha += elem.dop

    if (elem.alpha == 0 || elem.y > display.height + elem.radius) {
      elem.vx = range(0, 2) + 8 * xpos - 5
      elem.vy = 0.7 * elem.radius + range(-1, 1)
      elem.alpha = 1
      elem.position = random.pos()
    }
  })
})