examples

stars-falling.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
world.frame()

times(50, () => {
  let star = display.star(random.pos(), random.num(15, 35))
  star.angle = random.num(0, 360)
  star.borderWidth = 2

  star.click((e) => {
    star.applyImpulse(0, -star.radius)
  })
})

update(() => {
  display.each("star", (elem) => {
    elem.color=color.hsb(elem.angle, 25, 75)
    elem.borderColor=color.hsb(elem.angle, 35, 95)
  })
})

ui.label("Hello")

btn = ui.button("Click me!", world.width/2, 100)
btn.action((e) => {
  display.each("star", (elem) => {
    physics.add(elem)
  })
})