Skip to content

Instantly share code, notes, and snippets.

@wesleywerner
Last active September 16, 2022 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesleywerner/39ba36fb48b7c8b132faa09cba1980fb to your computer and use it in GitHub Desktop.
Save wesleywerner/39ba36fb48b7c8b132faa09cba1980fb to your computer and use it in GitHub Desktop.
txt="greets to everyone at the pico 1k jam 2022 🐱 its a blast playing all your entries 🐱 some are real gems! 🐱 enjoy squeezing every byte into your code 🐱 i know i have 🐱 good luck to all 🐱 i hope you enjoyed this scroller 🐱 i am out of bytes 🐱 now go make something cool! 🐱 have fun! ★ ★ ★"
_l,_t,_s=1,-10,{} -- INIT globals:
-- _l: loop counter, increments each time demo restarts.
-- _t: the clock, determines the position of text,
-- start negative to give a short pause before
-- first text appears.
-- _s: table of particles, used for various
-- background effects.
function _draw() -- [DRAW LOOP]
camera() -- Reset draw position.
for x=0,15do for y=0,15do -- Fills the display with sprite #1.
h=x%2==0 -- For every odd X position, flip horizontally.
v=y%2==0 -- For every odd Y posiition, flip vertivally.
spr(1,x*8,y*8,1,1,h,v) -- This creates a symmetry in both planes.
end end -- Symmetry is (computationally) cheap and creates
-- a very pleasing effect. Even random shapes
-- look good when drawn symmetrical.
-- Sprite 1 is generated during update().
camera(0,38*sin(t()*.1)+6) -- Translate remaining drawing ops as a sine
-- function of the clock.
-- This makes the text and particles move
-- up-and-down in a repeated wave-like motion.
rectfill(0,47,127,88,_l) -- Draw a box of color _l.
for s in all(_s)do -- Draw particle effects, determined by _l:
if _l==1 then -- Effect #1 (flowing particles)
pset(s.x, --
s.y+4*sin(s.a), -- Modified y as sine of its angle.
2+s.a*3)
elseif _l==2 then -- Effect #2 (rotating lines)
line(s.x, -- We use the formula for calculating a point
s.y, -- on a circle to give this effect:
s.x+4*cos(s.a), -- x = cx + r * cos(a)
s.y+4*sin(s.a), -- y = cy + r * sin(a)
s.y%3) -- where radius is 4 and cx,cy is the center.
elseif _l==3 then -- Effect #3 (flowers)
pset(s.x, -- One pixel for the center, yellow.
s.y+4*sin(s.a),
9)
circ(s.x, -- The petals as a circle with
s.y+4*sin(s.a), -- radius 1.8-angle, as angle increase
1.8-s.a, -- so will radius decrease.
7)
elseif _l==4 then -- Effect #4 (triangulates)
line(64,47, -- Line from top-center of box to particle.
s.x,
s.y+4*sin(s.a),
1)
line(64,87, -- Line from bottom-center of box to particle.
s.x,
s.y+4*sin(s.a), -- Modified y as a sine function.
1)
end
end
f=1 -- f: index of current text effect.
_c=0 -- _c: index of current color, note only some
-- effects use this value.
for i=1,#txt,1 do -- For each letter:
_x=128-_t*32+i*8 -- Set and decrease _x pos over _t.
_y=64 -- Center _y pos.
l=sub(txt,i,i) -- Store letter in l.
if(l=="🐱")f=1+f%#_f -- At each cat, cycle to next effect.
if(l==" ")_c+=1 -- At each space, cycle to next color.
print("\^t\^w"..l,_f[f](i)) -- Print letter double height/width (\t\w)
end -- at position and color determined by the
-- effect in _f[f].
if _x<-64 then -- _x will contain the position of the last
_t=0 -- letter from above loop. If last _x
_l=1+_l%4 -- is off-screen (-64) we restart the clock
end -- and increment the loop counter _l.
end
function _update() -- [UPDATE LOOP]
_t+=.03 -- Move clock forward 1/30 fps.
if(btn()>0)_t+=.1 -- Fast-forward clock on button press.
for s in all(_s)do -- Update all particles.
s.a+=.015 -- Increase angle.
s.x+=1+s.a*2 -- Move x position, accelerates with angle.
if(s.x>128)del(_s,s) -- Remove particle when out of bounds.
end
for n=0,63do -- Generate sprite #1.
sset( 8+n%8, -- Use linear addressing so we only need one loop,
n/8, -- i.e. x as 8+modulo 8 steps, y every 8 steps.
5+(n%8+n/8+_t*12)%12) -- Color is in range 5-16, as a function of
end -- x + y, which creates a sloped rainbow line.
-- Because the sprite is mirrored on-screen
-- the slope creates a diamond shape.
-- Color is offset by clock _t to give the
-- animated effect.
add(_s,{x=0, -- Add a new particle each tick,
y=53+rnd(33),
a=rnd(.5)}) -- Randomize angle, giving particles
-- parallax-like movement.
end
-- [TEXT EFFECTS]
-- Below functions define the different movements
-- and color for the text. Each receives parameter
-- i (letter index), and returns x, y, color.
-- Additional local variable (t) is defined as a
-- parameter to save on local declares.
function crl(i,t) -- The Crawler.
t=_t-.1*i -- Makes a letter crawl across the screen.
_x+=sin(t)*4 --
return _x, -- Returns x, y and color.
_y+sin(t*0.5)*4, --
13+i%3 -- Color range 13-15, based on letter index.
end
function wav(i,t) -- The Wave.
t=_t-.1*i -- Moves a letter in a sine wave motion.
_x+=sin(t*.5)*4 -- X component is adjusted so letters appear
_y+=sin(t*.7)*16 -- to contract & compress near the peaks and valleys.
return _x,_y, --
12+(_y*.1)%4 -- Color range 12-15, based on y position.
end
function acc(i,t) -- The Accordion.
t=_t-.1*i -- Move letters along constant y plane,
_x+=cos(i+t)*4 -- contract & expand on the x plane.
return _x,_y, --
7+_c%9 -- Color range 7-15, based on _c,
end -- i.e. at word boundaries.
function hop(i) -- The Hopper.
_x+=cos(_t-.1*i)*4 -- Makes letters hop along the ground.
_y+=sin(_t-.1*i)*8 --
return _x,_y, --
8+(_x/32)%4 -- Color range 8-11, based on x position.
end
function crc(i) -- The Circle.
_x+=cos(_t+_c*.5)*8 -- Moves each word boundary in circular motion.
_y+=sin(_t+_c*.5)*8 --
return _x,_y,7+_c%9 -- Color range 7-15, based on word boundary.
end
_f={wav,acc,crl,crc,hop} -- List all text effects in global _f.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment