Skip to content

Instantly share code, notes, and snippets.

@lucatronica
Last active February 20, 2022 20:42
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucatronica/197f3ab8839e0a6146c6c9b244926bd7 to your computer and use it in GitHub Desktop.
Save lucatronica/197f3ab8839e0a6146c6c9b244926bd7 to your computer and use it in GitHub Desktop.
function _draw()
cls(8)
srand(5)
-- Iterate every 8 square pixels of the screen.
-- The `.5` is to make sure the points are at the center of each pixel.
-- We'll draw one wall of the maze in each square.
for y=.5,129,8 do
for x=.5,129,8 do
-- Progress in the rotation cycle. One rotation is [0..1]
a=rnd()+t()/25
-- Get the direction the wall should go.
-- If we just used `u,v=cos(a)*4,sin(a)*4` then each wall would always be spinning.
-- We'll alter these coordinates to get the desired effect.
--
--`mid` returns the middle of three numbers, it's basically a clamp function.
-- By clamping circular coordinates, they can move in a square shape rather than a circular one.
-- See the GIF below!
u=mid(-4,4,cos(a)*120)
v=mid(-4,4,sin(a)*120)
-- Draw the wall as 4 lines stacked on top of each other.
for i=0,3 do
-- `i>2 and 7 or 2` makes the top white but the rest dark red.
line(x+u,y+v-i,x-u,y-v-i,i>2 and 7 or 2)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment