Skip to content

Instantly share code, notes, and snippets.

@2DArray
Last active October 14, 2019 22:22
Show Gist options
  • Save 2DArray/dfe53cbf9c0d2ee10140149b29774d9e to your computer and use it in GitHub Desktop.
Save 2DArray/dfe53cbf9c0d2ee10140149b29774d9e to your computer and use it in GitHub Desktop.
-- clear the screen
cls()
-- make a shorter alias far pico8's
-- "get random number" function.
-- usage: r(10) means "random number in [0,10)"
r=rnd
-- print "grow" to the screen,
-- a weird shorthand for print("grow")
?"grow"
-- draw a green underline
-- (x1,y1, x2,y2, colorIndex)
line(0, 5, 15,5, 11)
-- (pico8 just gives you 16 colors,
-- and you have to pick from those)
-- copy the text from the screen
-- buffer to the spritesheet
memcpy(0,24576,384)
-- (0 is the memory address of the
-- spritesheet, 24576 is the address
-- of the screen buffer, 384 is a length)
-- clear the screen again
cls()
-- draw a zoomed-in version
-- of our original drawing
-- (now in the spritesheet)
-- back onto the screen
-- (https:--pico-8.fandom.com/wiki/Sspr)
sspr(0,0,15,6,11,70,105,35)
-- define a goto-label
::_::
-- pick random x/y position
x=r(128)
y=r(64)+64
-- pick nearby potential
-- grow-to position
u=x+r(2)-1
v=y-1
-- set neighbor-count to 0
c=0
-- iterate through a 3x3 block
-- of pixels around our new spot
for a=u-1,u+1 do
for b=v-1,v+1 do
-- check current screen-pixel,
-- color 0 and color 6 are
-- the background and grey
-- (plant-pixels are 3 or 11)
if pget(a,b)%6>0 then
-- found a green neighbor
c+=1
end
end
end
-- now we check if our grow-to
-- target is valid...
-- is our start pixel a color-index that
-- isn't 0 or 6?
-- 0 is black, 6 is grey - must start
-- growing from a green pixel!
if pget(x,y)%6>0 then
-- is the new pixel grey (text)?
-- if not, can we get lucky with a
-- 1/10 dice-roll?
-- ("plants mostly grow on text")
if pget(u,v)==6 or r()<.1 then
-- do we have fewer than 6
-- green-neighbors in our
-- 3x3 neighborhood?
if c<6 then
-- we're good to grow!
-- draw a green pixel at our
-- grow-target position.
-- (color 3 or color 11)
pset(u,v,3+c%2*8)
end
end
end
-- jump back to the goto-label
goto _
-- normally, goto is a bad idea,
-- but it's fewer chars than
-- "while" or "for" in lua,
-- lololol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment