Log In  18  Hi all,

I'm writing a short graphical text adventure for the PICO-8, and a few weeks ago I determined that I needed a vector graphics editor capable of outputting PICO-8 code. I've created a web app called GMagic that lets you make vector drawings on a canvas, then export Lua functions for drawing them. I also provide the functions for drawing polygons and polylines:

ptstr() (needed for the functions):

 ```function ptstr(s) local data={} local wip='' for i=1,#s do r=sub(s,i,i) if(r==',') then add(data,wip+0) wip='' else wip=wip..r end end add(data,wip+0) return data end```

Polygon:

 ```function poly(r,c,p) local t=ptstr(r) --based off alienryderflex.com/polygon_fill --t=table x1,y1,x2,y2... --c=colors (hex) --p=pattern local pc=#t/2 local px={} local py={} local my=127--miny local xy=0 --maxy --split out xy lookups for i=1,#t-1,2 do add(px,t[i]) add(py,t[i+1]) if(t[i+1]xy) xy=t[i+1] if(i<#t-2) then if(p) fillp(p) line(t[i],t[i+1],t[i+2],t[i+3],c) fillp() --yield() end end --scan down the screen for y=my,xy do local nx={} --build a list of nodes local n=0 local j=pc for i=1,pc do if((py[i]=y) or(py[j]=y)) then add(nx,(px[i]+(y-py[i])/(py[j]-py[i])*(px[j]-px[i]))) end j=i end --bubblesort nodes local k=1 while(k<#nx) do if(nx[k]>nx[k+1]) then nx[k],nx[k+1]=nx[k+1],nx[k] if(k>1) then k-=1 end else k+=1 end end --fill the pixels for l=1,#nx-1,2 do local d=nx[l] local e=nx[l+1] if(d>=127) break if(e>0) then if(d<0) d=0 if(e>127) e=127 if(p) fillp(p) line(d,y,e,y,c) fillp() end end end --yield() end```

Polyline:

 ```function pline(r,c,p) local t=ptstr(r) for i=1,#t-2,2 do if(p) fillp(p) line( t[i], t[i+1], t[i+2], t[i+3], c ) fillp() end --yield() end```

If you want to read more about GMagic or check out some sample screenshots, you can view the Github repository here. If you end up using GMagic for a cart, I'd love to hear about it!

EDIT 6/24: I can't believe I forgot to include ptstr()! I've added it above, and to the Lua sample in the repo.

P#61467 2019-02-02 18:26 ( Edited 2019-06-24 21:48)  This looks way cool! I'm interested in using this because I'm annoyed with trying to do it all with the built in line() function, but when I ran it in Pico 8 the ptstr() function throws an error: I'm not sure where it's expecting that to come from.

P#65351 2019-06-23 01:45  Very cool.

Was about to say this would be useful for an adventure game engine, then I see you're doing just that! 😁

P#65387 2019-06-24 20:26 ( Edited 2019-06-24 20:26)  YES! this is awesome.

P#65389 2019-06-24 21:15  Hey all, sorry I forgot about ptstr()! I've updated the main post, it's just a function that divvies up a comma-separated string of points. That way your shapes can count as one token each.

P#65390 2019-06-24 21:49  Wow this looks like the drawing style of early graphic adventure games! Cool idea!

P#65394 2019-06-25 04:31  I LOVE THIS tool. Ago you think you could add RECT and CIRC to the web app? I could obviously see this tool ballooning out of control, but at least circles would add an art layer that's pretty important.

P#65424 2019-06-27 16:53
:: dw817  Did you ever make this tool specifically to run in Pico-8 ?

P#70194 2019-11-24 17:08 ( Edited 2019-11-24 17:10)