hive.saysi.org

 

HIVE PICO-8 Tutorial

HIVE Content

HIVElings! Check the usual Trello board(s) for the assignment associated with the tutorials!

HIVE Programming Glossary: for quick definitions of important words and jargon. If this is your very first time dipping into coding, have this page open!

HIVE PICO-8 Cheat Sheet: download the pdf referenced in the videos all the time.

Videos & Source Code:

Other important links

Music Tutorials

Resources

Games





Videos & Source Code

1: intro & what it means to be ready to code

supercoolgame.p8

cls(8)
print("jello mold")





2a: functions & the coordinate system

circlesinouterspace.p8

function _draw()
 cls(1)
 circfill(0,0,30,9)

 circ(64,64,10,8)
 circ(64,64,11,8)

 circfill(127,127,rnd(30)+30,11)
end





2b: a few more functions for your starter pack

circlesinouterspace.p8

cls(1)

function _draw()

 circfill(0,0,30,9)

 circ(64,64,10,8)
 circ(64,64,11,8)

 line(64,64,rnd(128),rnd(128),14)
 line(rnd(128),rnd(128),14)
 line(rnd(128),rnd(128),14)
 line(rnd(128),rnd(128),14)
 line(rnd(128),rnd(128),14)
 line(rnd(128),rnd(128),14)

 color(1)
 pset(rnd(128),rnd(128))
 pset(rnd(128),rnd(128))
 pset(rnd(128),rnd(128))
 pset(rnd(128),rnd(128))
 pset(rnd(128),rnd(128))
 pset(rnd(128),rnd(128))
 pset(rnd(128),rnd(128),7)

 circfill(127,127,rnd(10)+60,15)
 circ(127,127,rnd(10)+40,7)
 circfill(127,127,10+rnd(20),7)
end





3: stashing stuff with variables

16mm_windy.p8

numbur =0

function _draw()
 cls(0)
 wobble_x=rnd(4)
 wobble_y=rnd(4)

 numbur=numbur+1

 rectfill(64-30,40,64+30,80,13)
 rectfill(64-24+wobble_x,42+wobble_y,64+24+wobble_x,76+wobble_y,7)
 print(numbur, 70+wobble_x,70+wobble_y,13)
end





4a: loops & conditional statements

petrixels2.p8

cls(7)

-- seed the agar
for start=0,25,1 do
 pset(rnd(128),rnd(128),0)
end

-- speed
grabbing=2000

function _draw()
 for grab=0,grabbing,1 do
  local x=rnd(128)
  local y=rnd(128)
  local c=pget(x,y)

  if c~=7 then
   circfill(x,y,1,0)
  end
 end
end





4b: interactivity

petrixels3.p8

cls(7)

-- seed the agar
for start=0,25,1 do
 pset(rnd(128),rnd(128),rnd(16))
end

-- hit x to pour bleach!
function _update()
 if btn(❎) then
  for glog=0,10,1 do
   circfill(rnd(128),rnd(128),rnd(15),7)
  end
  for glog=0,30,1 do
   pset(rnd(128),rnd(128),7)
  end
 end
end

-- speed
grabbing=2000

function _draw()
 for grab=0,grabbing,1 do
  local x=rnd(128)
  local y=rnd(128)
  local c=pget(x,y)

  if c~=7 then
   circfill(x,y,1,c)
  end
 end
end





4c: sine & cosine for angle math in coordinate space

grab_neighboring_pixels_with_a_for.p8

x=105
y=96
dist=1

cls(7)

-- poke only ordinal directions
pset(x,y,12)
for arc=0,.75,.25 do
 pset(sin(arc)*dist+x,cos(arc)*dist+y, 9)
 print(sin(arc)..","..cos(arc))
end

-- poke all 8 pixels around,
-- including diagonally
x+=10
pset(x,y,11)
for arc=0,.875,.125 do
 pset(sin(arc)*dist+x+.5,cos(arc)*dist+y+.5,14)
 print(sin(arc)..","..cos(arc))
end

-- poke only diagonals
x-=5
y+=7
pset(x,y,8)
for arc=.125,.875,.25 do
 pset(sin(arc)*dist+x+.5,cos(arc)*dist+y+.5,13)
 print(sin(arc)..","..cos(arc))
end

petrixels4.p8

cls(7)

for start=0,25,1 do
 pset(rnd(128),rnd(128),rnd(16))
end

function _update()
 if btn(❎) then
  for glog=0,10,1 do
   circfill(rnd(128),rnd(128),rnd(15),7)
  end
  for glog=0,30,1 do
   pset(rnd(128),rnd(128),7)
  end
 end
end

grabbing=250

function _draw()
 for grab=0,grabbing,1 do
  local x=flr(rnd(128))
  local y=flr(rnd(128))
  local c=pget(x,y)

  if c~=7 then
   local neigh_c
   local neighs = 0
   for arc=0,.875,.125 do
    neigh_c = pget(sin(arc)+x+.5,cos(arc)+y+.5)
    if neigh_c == c then
     neighs+=1
    end
   end
   if neighs>6 then
   --[[

   q w e r t y u i o p
   …∧░➡️⧗▤⬆️☉🅾️◆
   a s d f g h j k l
   █★⬇️✽●♥웃⌂⬅️
   z x c v b n m
   ▥❎🐱ˇ▒♪😐

   ]]--
    print("░",x-3,y-flr(rnd(4)),c)
   else
    circfill(x,y,neighs/4+1,c)
   end
  end
 end
end