circles.nv
· 1.6 KiB · Text
Raw
Playground
|| '@include' https://gist.casuallyblue.dev/autumn/056799f483464c668e0a6a2d9db099df/raw/HEAD/game.nv
'orbit speed' 0.003
'orbit width' 10
'' start a 400 by 400 game
'' create 400 circles
| '' create 0 circles |
| '' create $amount circles
| '' (@reduce @main = create { $amount 1 - } circles .)
'' (@reduce circles =
{ 40 400 40 - random }
{ 40 400 40 - random }
{ 2 15 random } .)
| '' game loop $dt
| '@graphics' clear #11111122
'' draw circles
'' next frame
| '' draw circles? 'circles' $x $y $radius
| '' calculate orbit for $x
'' draw circle $x $y $radius
| '' calculate orbit for $x
'orbit speed' $speed?
| '' (@reduce orbit = { time $speed * $x + } .)
| '' draw circle $x $y $radius
'orbit' $orbit
'orbit width' $width?
| 'drawn' $x $y $radius
'' (@reduce @graphics = draw circle size $radius at
{ $orbit cos $width * $x + }
{ $orbit sin $width * $y + } .)
| '' draw circles | '' reset circles
| '' reset circles? 'drawn' $x $y $radius | 'circles' $x $y $radius
| '' reset circles |
| '@graphics' draw circle size $width at $x $y '@@canvas context' $c?
| '@js' $c.beginPath();
const r = $width / 2;
$c.arc(Number($x) + r, Number($y) + r, r, 0, 2 * Math.PI);
$c.fillStyle = "white";
$c.fill();
| '' @reduce? '' {? '' time | '@js' f("numbers", "" + performance.now());
| '' @reduce? '' {? '' cos 'numbers' $a | '@js' f("numbers", "" + Math.cos(Number($a)));
| '' @reduce? '' {? '' sin 'numbers' $a | '@js' f("numbers", "" + Math.sin(Number($a)));
|| '@include' https://gist.casuallyblue.dev/autumn/e1c6774f800249be87a94240042135db/raw/HEAD/reduce.nv
| 1 | || '@include' https://gist.casuallyblue.dev/autumn/056799f483464c668e0a6a2d9db099df/raw/HEAD/game.nv |
| 2 | |
| 3 | 'orbit speed' 0.003 |
| 4 | 'orbit width' 10 |
| 5 | |
| 6 | '' start a 400 by 400 game |
| 7 | '' create 400 circles |
| 8 | |
| 9 | | '' create 0 circles | |
| 10 | |
| 11 | | '' create $amount circles |
| 12 | | '' (@reduce @main = create { $amount 1 - } circles .) |
| 13 | '' (@reduce circles = |
| 14 | { 40 400 40 - random } |
| 15 | { 40 400 40 - random } |
| 16 | { 2 15 random } .) |
| 17 | |
| 18 | | '' game loop $dt |
| 19 | | '@graphics' clear #11111122 |
| 20 | '' draw circles |
| 21 | '' next frame |
| 22 | |
| 23 | | '' draw circles? 'circles' $x $y $radius |
| 24 | | '' calculate orbit for $x |
| 25 | '' draw circle $x $y $radius |
| 26 | |
| 27 | | '' calculate orbit for $x |
| 28 | 'orbit speed' $speed? |
| 29 | | '' (@reduce orbit = { time $speed * $x + } .) |
| 30 | |
| 31 | | '' draw circle $x $y $radius |
| 32 | 'orbit' $orbit |
| 33 | 'orbit width' $width? |
| 34 | | 'drawn' $x $y $radius |
| 35 | '' (@reduce @graphics = draw circle size $radius at |
| 36 | { $orbit cos $width * $x + } |
| 37 | { $orbit sin $width * $y + } .) |
| 38 | |
| 39 | | '' draw circles | '' reset circles |
| 40 | |
| 41 | | '' reset circles? 'drawn' $x $y $radius | 'circles' $x $y $radius |
| 42 | |
| 43 | | '' reset circles | |
| 44 | |
| 45 | |
| 46 | | '@graphics' draw circle size $width at $x $y '@@canvas context' $c? |
| 47 | | '@js' $c.beginPath(); |
| 48 | const r = $width / 2; |
| 49 | $c.arc(Number($x) + r, Number($y) + r, r, 0, 2 * Math.PI); |
| 50 | $c.fillStyle = "white"; |
| 51 | $c.fill(); |
| 52 | |
| 53 | | '' @reduce? '' {? '' time | '@js' f("numbers", "" + performance.now()); |
| 54 | | '' @reduce? '' {? '' cos 'numbers' $a | '@js' f("numbers", "" + Math.cos(Number($a))); |
| 55 | | '' @reduce? '' {? '' sin 'numbers' $a | '@js' f("numbers", "" + Math.sin(Number($a))); |
| 56 | || '@include' https://gist.casuallyblue.dev/autumn/e1c6774f800249be87a94240042135db/raw/HEAD/reduce.nv |
| 57 |