Skip to content

Instantly share code, notes, and snippets.

@luizbills
Created November 18, 2025 01:05
Show Gist options
  • Select an option

  • Save luizbills/6abc9088183a1cd1cc2328ae1a1f7e08 to your computer and use it in GitHub Desktop.

Select an option

Save luizbills/6abc9088183a1cd1cc2328ae1a1f7e08 to your computer and use it in GitHub Desktop.
Draw random asteroid shape in Litecanvas
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
}
@luizbills
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment