ÎÌÌÌ̈ˆˆ¬ªªª¬ˆˆˆ¬ÌÌ̬ÌÀ̬ÌÀ̬ÌÀÌÌÌìÌÀÀî̬ÀÌÀ¬ÀÀÀ¬ÀÀÀ¬ÀÀÎÌÌÌ̈ˆˆ¬ªªª¬ˆˆˆ¬ÌÌ̬ÌÌ̬ÌÀ̬ÌÀÌÌÌìÌÀÀî̬ÀÌ̬ÀÀÀ¬ÀÀÀ¬ÀÀ¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒˆˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒˆˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî >½?  ÀÏÏÏ  033ÀÌ ÀÌ Ì 033À ÀÌÌ 033À ÀÌÀÌ033ÀÌ ÌÌ 033À ÀÌ Ì ;-- title: PicEdit -- author: catnip -- desc: a little picture editor designed for quick sketches -- script: lua --[[ PicEdit by catnip Each time you add a shape, it's added to the drawlist which gets printed to the console. You can then copy it out into your own code. The drawlist is split into groups, press G to start a new one. This lets you split a picture into layers which can be animated individually. ]]-- -- Initial drawlist with 1 empty group drawList={ { }, } abs=math.abs min=math.min max=math.max -- Stores the moue m={} -- Initial group to draw into group=#drawList t=0 -- time -- These values store the current shape origin={} size={x=20,y=20} -- Shape type, 0:rect 1:circ 2:elli -- 4:tri 5:line 6:pix type=0 colour=8 border=false -- Used to track UI state pickingColour=false outline=false help=false function updateMouse() local wasLClick=m.l local a,b,c,d,e=mouse() m={x=a,y=b,l=c,r=e} poke(0x3FFB,0) if m.l then -- click start or continue if wasLClick then -- continue, update size state=2 if type==4 then -- no abs for line size={x=m.x-origin.x,y=-(m.y-origin.y)} else size={x=abs(m.x-origin.x),y=abs(m.y-origin.y)} end else -- start, add start point state=1 origin={x=m.x,y=m.y} end elseif wasLClick then -- edit end, draw to bkg and add to list vbank(0) drawShape() addShape() size={x=0,y=0} end end function updateKB() local lastType=type pickingColour=false if keyp(18) then -- Rect type=0 elseif keyp(3) then -- Circ type=1 elseif keyp(5) then -- Elli type=2 elseif keyp(7) then -- Group group=group+1 drawList[group]={} elseif keyp(20) then -- Tri type=3 elseif keyp(12) then -- Line type=4 elseif keyp(16) then -- Pix type=5 elseif keyp(2) then -- Border border=not border elseif key(48) then -- space pickingColour=true elseif keyp(51) then -- del table.remove(drawList[group],#drawList[group]) vbank(0) cls() drawBkg() elseif keyp(49) then -- tab outline=not outline trace(outline) elseif keyp(8) then -- h help=not help end end function addShape() local idx=#drawList[group]+1 drawList[group][idx]={ t=type, b=(border and 1 or 0), x=origin.x,y=origin.y, w=size.x,h=size.y, c=colour } trace("New drawlist:") local str="drawList={\n" for i=1,#drawList do str=str.." {\n" for j=1,#drawList[i] do local s=drawList[i][j] str=str.." {t="..s.t..",b="..s.b..",x="..s.x..",y="..s.y..",w="..s.w..",h="..s.h..",c="..s.c.."},\n" end str=str.." },\n" end str=str.."}" trace(str) end function drawBkg() for i=1,#drawList do for j=1,#drawList[i] do local s=drawList[i][j] type=s.t border=s.b==1 and true or false origin={x=s.x,y=s.y} size={x=s.w,y=s.h} colour=s.c drawShape() end end end function drawMouse() pix(m.x-5,m.y,12)pix(m.x-4,m.y,15)pix(m.x-3,m.y,12)pix(m.x-2,m.y,15)pix(m.x+5,m.y,12)pix(m.x+4,m.y,15)pix(m.x+3,m.y,12)pix(m.x+2,m.y,15)pix(m.x,m.y+5,12)pix(m.x,m.y+4,15)pix(m.x,m.y+3,12)pix(m.x,m.y+2,15)pix(m.x,m.y-5,12)pix(m.x,m.y-4,15)pix(m.x,m.y-3,12)pix(m.x,m.y-2,15) end function getSize() local minx=240 miny=136 maxx=0 maxy=0 for j=1,#drawList do for i=1,#drawList[j] do local s=drawList[j][i] local tl,br if s.t==0 then -- rect tl={x=s.x,y=s.y} br={x=s.x+s.w,y=s.y+s.h} elseif s.t==1 then tl={x=s.x-s.w,y=s.y-s.w} br={x=s.x+s.w,y=s.y+s.w} elseif s.t==4 then -- line tl={x=min(s.x,s.x+s.w),y=min(s.y,s.y-s.h)} br={x=max(s.x,s.x+s.w),y=max(s.y,s.y-s.h)} elseif s.t==5 then -- pix tl={x=s.x,y=s.y} br=tl else -- standard tl={x=s.x-s.w,y=s.y-s.h} br={x=s.x+s.w,y=s.y+s.h} end minx=min(minx,tl.x) miny=min(miny,tl.y) maxx=max(maxx,br.x) maxy=max(maxy,br.y) end end return minx,miny,maxx-minx+1,maxy-miny+1 end function drawHUD() if outline then local x,y,w,h=getSize() rectb(x,y,w,h,12) end local typeStr={"RECT","CIRC","ELLI","TRI","LINE","PIX"} print(typeStr[type+1],240-23,131,12) if border then rectb(240-23-6,131,5,5,colour) else rect(240-23-6,131,5,5,colour) end if help then print("Shortcuts:\n\nE: ellipse\nC: circle\nR: rectangle\nT: triangle\nL: line\nP: pixel\nB: toggle bordered/filled\nG: start new group/layer\n\nHold space and move mouse to pick colour\n\nClick and drag to add shape\n\nPress backspace to delete last shape\n\nH: hide / show this screen", 0,1,15) print("Shortcuts:\n\nE: ellipse\nC: circle\nR: rectangle\nT: triangle\nL: line\nP: pixel\nB: toggle bordered/filled\nG: start new group/layer\n\nHold space and move mouse to pick colour\n\nClick and drag to add shape\n\nPress backspace to delete last shape\n\nH: hide / show this screen", 0,0,12) print("Shows current tool & colour ->",0,132,15) print("Shows current tool & colour ->",0,131,12) end if t<60 and help==false then print("Press H for help",75,64,15) print("Press H for help",75,63,12) end if pickingColour then for i=0,15 do rect(i*15,131,15,5,i) if m.x>i*15 and m.x<(i+1)*15 then rectb(i*15,131,15,5,12) colour=i end end end end function drawShape() if type==0 then if border then rectb(origin.x,origin.y,size.x,size.y,colour) else rect(origin.x,origin.y,size.x,size.y,colour) end elseif type==1 then if border then circb(origin.x,origin.y,size.x,colour) else circ(origin.x,origin.y,size.x,colour) end elseif type==2 then if border then ellib(origin.x,origin.y,size.x,size.y,colour) else elli(origin.x,origin.y,size.x,size.y,colour) end elseif type==3 then if border then trib( origin.x-size.x,origin.y+size.y, origin.x+size.x,origin.y+size.y, origin.x,origin.y-size.y, colour) else tri( origin.x-size.x,origin.y+size.y, origin.x+size.x,origin.y+size.y, origin.x,origin.y-size.y, colour) end elseif type==4 then line(origin.x,origin.y,origin.x+size.x,origin.y-size.y,colour) elseif type==5 then pix(origin.x,origin.y,colour) end end function TIC() if t==0 then -- clear and draw initial list at startup cls() drawBkg() end updateMouse() updateKB() vbank(1) cls(0) if m.l then drawShape() end drawHUD() drawMouse() t=t+1 end