Skip to content

Instantly share code, notes, and snippets.

@Chovin
Last active April 11, 2017 03:28
Show Gist options
  • Save Chovin/ac26979c5b43a413341474b29ac4ac2d to your computer and use it in GitHub Desktop.
Save Chovin/ac26979c5b43a413341474b29ac4ac2d to your computer and use it in GitHub Desktop.
-- this is a pico8(lua) comment. it is ignored by the program
::a:: -- this is a label. it allows us to goto it later (good for looping)
cls() -- 1st, clear the screen
-- then set our starting values
y=rnd(9) -- we'll use a random number between 0 and 9, not including 9
x=y -- x, y, and w all start with this random number. x,y will be our coordinates.
w=y -- w will be our salt. we won't change it after this.
-- now we're ready to start drawing!
while 1 do -- repeatedly execute the following code (until we tell it go elsewhere)
---+==|| we want to increase the pixel we're on by 1 color value ||==+---
c=1+pget(x,y) -- we're going to get the color of the current pixel and add 1 to it.
pset(x,y,c) -- then set the current pixel to the new color
---+==|| then we want to find out which pixel we want to look at next ||==+---
x,y=y,(x*cos(w)-y/w*sin(w))%127 -- this line is where the magic happens. It's the same as doing the following:
----------------------------------
-- we're going to do some math, and then shuffle x and y around.
temp = y -- store the old y value. we want our next x to be this. if we don't store the old y value,
-- we'll just get a straight line because x is always y next time around.
y = (x*cos(w)-y/w*sin(w))%127 -- magical math I tweaked with but didn't bother understanding :3
-- the % is the modulus operator. It gives the remainder of a division.
-- anything modulus 127 will keep that value less than 127, keeping x and y within the screen bounds.
-- ex. 25%127 is 25. 127%127 is 0. 130%127 is 3.
x = temp -- now that we've done our math with the old x and y, we can replace x with the old y
----------------------------------
---+==|| we need to define when to stop drawing and start a new picture ||==+---
if(c>15)goto a -- there are only 16 colors (0-15)
-- so if the current pixel has gone through all the colors, restart a new drawing at the ::a:: label
-- otherwise, continue drawing the next pixel
end --#tweetjam #april3030 #pico8 --that's it!
--The code can be further minified by replacing the while loop with another label:
::a::cls()y=rnd(9)x=y
w=y::b::c=1+pget(x,y)pset(x,y,c)x,y=y,(x*cos(w)-y/w*sin(w))%127
if(c>15)goto a
goto b--#tweetjam #april3030 #pico8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment