autumn gist felülvizsgálása 4 months ago. Revízióhoz ugrás
1 file changed, 56 insertions
circles.nv(fájl létrehozva)
| @@ -0,0 +1,56 @@ | |||
| 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 | |
Újabb
Régebbi