PicoPicoGameEngine

Quick Links

Source Code

g=ppgraph
sin=math.sin
cos=math.cos
pi=math.pi
c=pppoint(160,200)
z=ppscreen:size()

function polygon(o,r,c)
  local s
  local d=360/o
  s=ppsprite.new()
  s.col=c
  s.r=r
  s.draw=function(s)
    local p={}
    local b=-90*180/pi
    b=b+s:rotate()
    for q=0,360-d,d do
      local x=s.x+s.r
      local y=s.y+s.r
      local u=q*pi/180+b
      p[#p+1] = {
        cos(u)*r+x,
        sin(u)*r+y,
      }
    end
    g:triangleFan(p,s.col)
  end
  s:pivot(r,r)
  s:tileSize(r*2,r*2)
  return s
end

poly={}
p=polygon(3,80,g.red)
p:move(0,60)
table.insert(poly,p)

p=polygon(4,80,g.green)
p:move(160,60)
table.insert(poly,p)

p=polygon(5,80,g.yellow)
p:move(0,260)
table.insert(poly,p)

p=polygon(6,80,g.cyan)
p:move(160,260)
table.insert(poly,p)

function start()
  for i,p in ipairs(poly)
  do
    p:rotate(
      p:rotate()+0.02)
    p:drag(pptouch(),z)
    p:draw()
  end
end