Created
April 22, 2015 20:12
-
-
Save Eiyeron/47d9314700a4b131cca7 to your computer and use it in GitHub Desktop.
Rotoscale
This file contains 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
-- rotoscale! | |
-- by eiyeron | |
-- 07/04/2015 | |
-- a good old demo effect! :3 | |
-- retroactive.me/retro-actif | |
-- thanks zep for everything!:) | |
-- for pico-8, the code and | |
-- voxatron! | |
-- iirc local vars are faster | |
local t, angle, scale = 0, 0, 1 | |
---- temp variables | |
-- x/yp = after rotation | |
local x, y, xp, yp | |
--trigonometry precalc vars | |
local ca, sa | |
local cal, sal = {}, {} | |
local function _draw() | |
-- for each row | |
for x=0,127,1 do | |
for y=0,127,1 do | |
-- here goes the rotation! | |
-- with real bits of scale! | |
xp = ( cal[x]+sal[y]) /scale | |
yp = (-sal[x]+cal[y]) /scale | |
-- we're getting the pixel's | |
-- color from the spritesheet. | |
pset(x,y,sget(xp%32,yp%24)) | |
end | |
end | |
end | |
local function _update() | |
-- just making things move. | |
t = t + 0.005 | |
scale = abs(cos(t*1.3)) * 3 + 1 | |
angle = angle + 0.01 | |
-- some quick precalculations | |
ca,sa = cos(angle), sin(angle) | |
-- prcalc distance rotations | |
-- to render way faster | |
for x=0,127,1 do | |
y = x-64 | |
cal[x] = ca * y | |
sal[x] = sa * y | |
end | |
end | |
-- you lost the game! :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment