PicoPicoGameEngine

Quick Links

Source Code

g=ppgraph
floor=math.floor
B=ppscreen:size()

function col(i)
  local r,g,b
  r=i%2
  b=floor(i/2)%2
  g=floor(i/4)%2
  return {
    r*255,g*255,b*255}
end

o=ppoffscreen.new()
o:create(8,8)
o:scale(32,32)
o:move(32,32)

o.char=function(s)
local c
local t
local rs,rg,rb
ra=""
rg=""
rb=""
t="0123456789ABCDEF"
for y=0,7 do
  local r,g,b
  r=0
  g=0
  b=0
  for x=0,7 do
    c=s:pixel(x,y)
    r=r*2+(c.r/255)
    g=g*2+(c.g/255)
    b=b*2+(c.b/255)
  end
  local u,v
  u=floor(r/16)+1
  v=(r%16)+1
  ra=ra..t:sub(u,u)
  ra=ra..t:sub(v,v)
  u=floor(g/16)+1
  v=(g%16)+1
  rg=rg..t:sub(u,u)
  rg=rg..t:sub(v,v)
  u=floor(b/16)+1
  v=(b%16)+1
  rb=rb..t:sub(u,u)
  rb=rb..t:sub(v,v)
end
return ra,rg,rb
end

o.defchar
=function(o,i,r,g,b)
local t
local floor
floor=math.floor
local dx=(i-1)*8
t="0123456789ABCDEF"
local
function f(o,dx,s,k)
  local c
  for y=0,7 do
    local r,n
    for i=0,1 do
    n=y*2+1+i
    r=s:sub(n,n)
    r=t:find(r)-1
    for x=0,3 do
      local p,z
      p=(r%2)*255
      r=floor(r/2)
      z=3-x+i*4
      c=o:pixel(z+dx,y)
      c[k]=p
      c.a=255
      o:pixel(z+dx,y,c)
    end
    end
  end
end
f(o,dx,r,"r")
f(o,dx,g,"g")
f(o,dx,b,"b")
end

o:defchar(1,
"000080DAFF878700",
"001880DAFF1D8766",
"5A7EFE80877D7F66")

p=ppoffscreen.new()
p:create(8,1)
p:scale(32,32)
p:pos(o:pos())
p:move(0,o.height+16)

for i=0,7 do
  p:pixel(i,0,col(i))
end

bt=ppbutton("PRINT")
bt.y=-48
t=g:layout(
  bt,true,false,B)
bt:pos(t)

c=0

function start()
t=pptouch()
if o:hitCheck(t)
then
end
if o.touch then
t=pptouch()
t=(t[1]-o:pos())/32
o:pixel(t,col(c))
o:bind()
end
if p:hitCheck(t)
then
end
if p.touch then
t=pptouch()
t=(t[1]-p:pos())/32
c=floor(t.x)
end
o:draw()
g:box(o:aabb())
p:draw()
local b
b=pprect(0,0,32,32)
b:pos(p:pos())
b:move(c*32,0)
b:inset(4,4)
g:box(b)
b:inset(1,1)
g:box(b,g.black)
g:box(p:aabb())
g:pos(p:pos())
ra,rg,rb=o:char()
g:move(-16,48)
g:print("R:"..ra)
g:move(0,16)
g:print("G:"..rg)
g:move(0,16)
g:print("B:"..rb)
if bt:idle(pptouch())
then
 print("\""..ra.."\",")
 print("\""..rg.."\",")
 print("\""..rb.."\"")
end
bt:draw()
end