examples

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

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

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.replace()
    }
  })
})