Last active
April 11, 2017 03:18
-
-
Save Chovin/7344e5dc563106d175d7dbedc84aa52d to your computer and use it in GitHub Desktop.
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
-- this is a pico8(lua) comment. it is ignored by the program | |
-- first we set up some variables | |
z=0 -- this will be our index so we know what pixel we're on. | |
p={} -- we need to store all the pixels on the screen so we have a base set of pixels to manipulate | |
f=133 -- this will control how many pixels we try to read per line | |
-- notice, I chose a little more than 128 pixels. This is to adjust for sideways movement | |
-- as well as various timing things that use this as part of their calculation. | |
t=0 -- tick counter | |
-- now we start drawing | |
::a:: -- label to go back to in order to repeat the following lines | |
---+==|| get the x and y value ||==+--- | |
x=z%f -- % is modulo. it gives the remainder of a division | |
-- ex. 5%133 is 5. 133%133 is 0. 134%133 is 1. | |
-- notice, this keeps x between 0 and 133(exclusive). This will be our x value. | |
y=z/f -- x is going between 0 and 133, but we need y to increase as well. | |
-- we need it to increase by 1 every time x is finished doing a sweep. | |
-- dividing by f does this for us. It will give us a decimal(float) value, but that's fine. | |
---+==|| store the pixel on 1st pass ||==+--- | |
if(t<f) then -- if this is the 1st pass (explained how this checks for that later), | |
p[z]=pget(x,y) -- store the pixel color before drawing over it | |
end | |
c=p[z] -- grab the color of the current pixel | |
---+==|| decide when to draw it ||==+--- | |
if(y>f-t/f-sin(t)*7) then -- defines the rising wave. | |
-- if we are below the wave, draw it. (y is larger as we go down) | |
-- sin(t)*7 gives us the wave shape. it is 15 pixels tall (-7 to 7) | |
-- f-t/f makes the wave rise. as time increases, we subtract more and more | |
-- ^ we start where y is around f (the bottom of the screen) | |
x+=sin(y/60+t)-3 -- adjust the x coordinate to draw our pixel | |
-- we're moving it left 3 and wiggling it between -1,1 depending on time and the y value | |
c+=1 -- now shift the color by one to give the bg a blue color | |
-- as well as to make the objects look distorted | |
end | |
pset(x,y,c) -- draw a new pixel which may have updated x/c values | |
---+==|| go to the next pixel ||==+--- | |
z=(z+1)%(f*f) -- increase z by one, keeping it within the "bounds" of the screen. | |
-- 128*128 pixels, but in our case, 133*133. the extras won't give *too* much lag. | |
t+=1/f -- increase the timer by 1/133. | |
-- Increasing it by a fraction lets do a meaningful sin operation on it without | |
-- needing to divide t by something within the sin. | |
-- using specifically 1/f, lets us easily know when the 1st pass is over, | |
-- so we can stop storing new pixel information. | |
-- recall that our 1st pass check is if(t<f). if we increment 1/f each iteration, | |
-- that means it'll take f*f iterations for t to be greater than f. | |
-- and remember, f*f is our board size. That's all the pixels! perfect fit. | |
goto a -- now go do the next pixel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment