Last active
July 16, 2020 20:40
-
-
Save lucatronica/5d1b2bdceced5d5f1315b8e2f252146e 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 code uses the following RGB trick | |
--https://gist.github.com/lucatronica/6dc7fae058440ab208d99584fe314e5c | |
--Setting up the RGB colors. | |
--Unlike the above example, we're using all 16 colors now! | |
--That's because we're now using the 4th bit of the color index. | |
--We use this bit (color 8) for the background text color. | |
pal({ | |
8,11,10,140,14,12,7, | |
129,8,11,10,140,14,12,7, | |
},1) | |
--frame count | |
n=0 | |
function _draw() | |
cls() | |
--Draw the background text. | |
--Seeding random makes the random pattern consistent across frames. | |
srand() | |
--Iterate the lines from top to bottom. | |
for y=0,127,7 do | |
--'d' is the direction the text should move: -1 or +1. | |
local d=sgn(y%14-7) | |
--Only the third line should be in English. | |
if y==14 then | |
--Iterate the characters. | |
--We wrap X in a 150 range to prevent "teleporting" at the edges of the screen. | |
--(150 was chosen since it's a multiple of 6 and 5) | |
for x=0,149,6 do | |
--The character index. | |
local i=1+(x/6)%5 | |
--Draw one character. | |
?sub("pico8 ",i,i),(x+n*d)%150-11,y,8 | |
end | |
else | |
for x=0,143,8 do | |
--2 new features here! | |
-- chr() - convert a byte to a character | |
-- Native kana (indexes between 154 and 253). | |
-- | |
--'2.5*max(sin(rnd()+t()/3)))' is used vary each character over time: | |
--max() is called with a single argument as the second arg defaults to 0. | |
--This creates the following pattern | |
--https://commons.wikimedia.org/wiki/File:Simple_half-wave_rectified_sine.svg | |
--Note how it stays still for half the time! | |
?chr(154+rnd(99)+2.5*max(sin(rnd()+t()/3))),(x+n*d)%144-8,y,8 | |
end | |
end | |
end | |
--Powers of 2. | |
local p={[0]=1,2,4} | |
--Pre-calculate hologram rotation parameters. | |
--'q' is the rotation amount. | |
local q=t()/12 | |
local c=cos(q) | |
local s=sin(q) | |
--Iterate over pixels in the text we just draw (just the top left corner). | |
for y=0,31.5,.5 do | |
for x=0,31.5,.5 do | |
--New operator '&' (binary AND)! | |
--We're checking if the 4th bit is set (that it's a text pixel). | |
if pget(x,y)&8==8 then | |
--'u' and 'v' X and Y coordinates. | |
--Rotation and perspective are relative to (0,0), so we need to shift | |
--'x' and 'y' by 16 pixels to center them around (0,0). | |
local x2=x-16 | |
--Iterate the 3 RGB layers. | |
for i=0,2 do | |
--The z position. We now have a 3D coordinate ('x','y','z')! | |
local z2=(i-1)*1.65 | |
--Rotate the coordinate around the Y axis. | |
--i.e. rotate (X,Z)=('u','z') around (0,0). | |
local x3=x2*c-z2*s | |
local z3=x2*s+z2*c | |
--Apply perspective. | |
local k=.54-z3/72 | |
local u=64+x3/k | |
local v=64+(y-16)/k | |
--New operator '|' (binary OR)! | |
--p[i] is the color of the current layer. | |
pset(u,v,pget(u,v)|p[i]) | |
end | |
end | |
end | |
end | |
n+=1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment