Created
November 18, 2025 01:05
-
-
Save luizbills/6abc9088183a1cd1cc2328ae1a1f7e08 to your computer and use it in GitHub Desktop.
Draw random asteroid shape in Litecanvas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| litecanvas({}) | |
| function init() { | |
| framerate(1) | |
| } | |
| function draw() { | |
| cls(0) | |
| // linedash([10,5]) | |
| // circ(W/2, H/2, 150, 2) | |
| shape(asteroid(W/2, H/2, 150)) | |
| fill(3) | |
| } | |
| function asteroid(x, y, radius) { | |
| const xy = [] | |
| const sides = randi(8,12) | |
| const a = TWO_PI / sides | |
| const r = radius/4 | |
| for (let i = 0; i < sides; i++) { | |
| const aa = rand(-0.25, 0.25) + (a * i) | |
| xy.push( | |
| x + (radius + rand(-r, r)) * cos(aa), | |
| y + (radius + rand(-r, r)) * sin(aa) | |
| ) | |
| } | |
| return xy | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Live Demo