Log In  
15

Cart [#34620#] | Copy | Code | 2016-12-31 | Link
15

EDIT: changed the rendering style and improved performance. Happy New Year from a surly talking head!

Spend a long night with an uncooperative subject.

(Just a quick sketch—thanks to electricgryphon for the RGB dither-plotter. Head by Videroboy.)

old version:


Cart [#34576#] | Copy | Code | 2016-12-31 | Link
15

P#34577 2016-12-31 03:35

15

Cart [#34502#] | Copy | Code | 2016-12-30 | Link
15

EDIT3: round 2 -- with updated algorithms, methodology, and results
EDIT2: added Catatafish's method -- we have a new champion!!
EDIT: added solar's method.

EatMoreCheese's thread about triangle rasterizers got me thinking about the different "trifill" methods that have been posted to the BBS—and so, in the spirit of the holiday season, I wrote a small profiler to pit them against each other in a brutal, winner-takes-all competition.

Methodology: I measure the time it takes for each routine to draw the same table of 300 randomly-generated triangles ten times over. Vertex extents are in the range [-50, 178].

CAVEATS: This is not an "apples-to-apples" comparison, or even apples-to-genetically-modified-oranges. For example, scgrn's method draws n-gons (not just triangles) and creamdog's method draws particularly chunky triangles. For personal edification only—no code-shaming intended!

Results:


Round 2: electricgryphon retakes the crown with a blistering ~5600 tris/sec, followed by Catatafish in a close second, and leaving musurca and NuSan tied for third (on average).

Round 1: Catatafish's method takes first place with an absolutely insane ~0.4 secs, followed by the method from the Gryphon 3D engine in second place at a very stable ~0.8 secs.

A lot of interesting discoveries—among them that rectfill() beats rect(), line(), AND memset().

Let me know if you'd like me to change your entry, or add others!

See round 1 here:


Cart [#34326#] | Copy | Code | 2016-12-27 | Link
15

P#34266 2016-12-26 21:36

23

Cart [#34530#] | Copy | Code | 2016-12-30 | Link
23

**UPDATE v0.21: click n' drag support, analog keyboard control, smaller template, and LOTS of bugfixes

A vector graphics authoring tool for your Pico8 demos, fonts, adventure games, etc. Draw an image, then save it as a highly compressed string which can be shared with other PiCAD users, or else displayed in your own cartridges without using any space in the spritesheet by including the PiCAD API.

To use your PiCAD images in your own cartridges, start with this template API (click Show to see):

Cart [#34531#] | Copy | Code | 2016-12-30 | Link
23

Features:
-save/load images as compressed strings (saved to picad_string.p8l)
-save to a spritesheet (saved to picad_export.p8)
-paint with a variety of brushes, including pattern/gradient fill, bezier curves, and copy/clone screen rectangles
-unlimited undo
-autosave
-mouse & keyboard support

Controls:
ENTER: open save/load menu
x: show/hide UI
tab: undo
q: show/hide guides
s/f: scroll color
e/d: scroll brush

To load strings into PiCAD, hit ENTER, select "Load..." and paste (Ctrl-V/Apple-V) the string into the Pico8 window. This must be done in the actual Pico8 console as the web player does not support reading from the clipboard.

Tech info: Rather than raw pixel data, PiCAD images are composed of a series of encoded draw operations—like an assembly language for images—which allows them to be stored as highly compressed strings. The format is inspired by the Sierra AGI "PICTURE" specification. Thanks to @dw817 for fast floodfill code.

(PiCAD is a lot more useful when used inside the actual Pico8 console rather than on the web player, which does not support save/load.)

GUIDE TO SETTINGS:
Export CLS Cmds: PiCAD strings generally begin with a "clear screen" opcode. That opcode is omitted from string exports when this setting is OFF. ON by default.
Continue Lines: When ON, lines and bezier curves can be continued relative to the previous operation, which will produce more efficient strings. OFF by default.
Autosave: When ON, saves your work to a string in picad_autosave.p8l after every new brush. OFF by default.
Click n' Drag: Turn ON if you're more comfortable with clicking and dragging to place brushes (rather than clicking and releasing for each operation). OFF by default.
Analog Keyboard: Simulates an analog joypad when using the keyboard instead of the mouse, which should make using PiCAD more pleasant on the PocketCHIP. ON by default.

P#33832 2016-12-21 05:00

1

Pico-8 implementation of Scale2x and Scale3x. Original algorithms by Andrea Mazzoleni

Scale2x:

--[[
sind : sprite index 
sz_x : x size
sz_y : y size
sx    : screen pos x
sy    : screen pos y
alpha: color to make transparent
]]--

function scale2x(sind,sz_x,sz_y,sx,sy,alpha)
 alpha=alpha or 0
 local offx=sind%16
 local offy=flr(sind/16)
 local soffx=offx*8
 local soffy=offy*8
 local sizex=sz_x-1
 local sizey=sz_y-1
 local a,b,c,d,e,f,g,h,i,
        e0,e1,e2,e3,x0,y0

 for y=0,sizey do
  for x=0,sizex do
   e=sget(soffx+x,soffy+y)
   a=e
   b=e
   c=e
   d=e
   f=e
   g=e
   h=e
   i=e

   if y>0 then
    b=sget(soffx+x,soffy+y-1)
   end

   if y<sizey then
    h=sget(soffx+x,soffy+y+1)
   end

   if x>0 then
    d=sget(soffx+x-1,soffy+y)
    if y>0 then
     a=sget(soffx+x-1,soffy+y-1)
    end
    if y<sizey then
     g=sget(soffx+x-1,soffy+y+1)
    end
   end

   if x<sizex then
    f=sget(soffx+x+1,soffy+y)

    if y>0 then
     c=sget(soffx+x+1,soffy+y-1)
    end
    if y<sizey then
     i=sget(soffx+x+1,soffy+y+1)
    end
   end

   e0=e
   e1=e
   e2=e
   e3=e

   if b!=h and d!=f then
    if(d==b) e0=d
    if(b==f) e1=f
    if(d==h) e2=d
    if(h==f) e3=f
   end

   --draw
   x0=sx+x*2
   y0=sy+y*2
   if(e0!=alpha) pset(x0,  y0,  e0)
   if(e1!=alpha) pset(x0+1,y0,  e1)
   if(e2!=alpha) pset(x0,  y0+1,e2)
   if(e3!=alpha) pset(x0+1,y0+1,e3)
  end
 end
end

Scale3x:

--[[
sind : sprite index 
sz_x : x size
sz_y : y size
sx    : screen pos x
sy    : screen pos y
alpha: color to make transparent
]]--

function scale3x(sind,sz_x,sz_y,sx,sy,alpha)
 alpha=alpha or 0
 local offx=sind%16
 local offy=flr(sind/16)
 local soffx=offx*8
 local soffy=offy*8
 local sizex=sz_x-1
 local sizey=sz_y-1
 local a,b,c,d,e,f,g,h,i,
       e0,e1,e2,e3,e4,e5,e6,e7,e8,
       x0,y0

 for y=0,sizey do
  for x=0,sizex do
   e=sget(soffx+x,soffy+y)
   a=e
   b=e
   c=e
   d=e
   f=e
   h=e
   i=e
   g=e

   if y>0 then
    b=sget(soffx+x,soffy+y-1)
   end

   if y<sizey then
    h=sget(soffx+x,soffy+y+1)
   end

   if x>0 then
    d=sget(soffx+x-1,soffy+y)
    if y>0 then
     a=sget(soffx+x-1,soffy+y-1)
    end
    if y<sizey then
     g=sget(soffx+x-1,soffy+y+1)
    end
   end

   if x<sizex then
    f=sget(soffx+x+1,soffy+y)

    if y>0 then
     c=sget(soffx+x+1,soffy+y-1)
    end
    if y<sizey then
     i=sget(soffx+x+1,soffy+y+1)
    end
   end

   e0=e
   e1=e
   e2=e
   e3=e
   e4=e
   e5=e
   e6=e
   e7=e
   e8=e

   if b!=h and d!=f then
    if(d==b) e0=d
    if((d==b and e!=c) or (b==f and e!=a)) e1=b
    if(b==f) e2=f
    if((d==b and e!=g) or (d==h and e!=a)) e3=d
    if((b==f and e!=i) or (h==f and e!=c)) e5=f
    if(d==h) e6=d
    if((d==h and e!=i) or (h==f and e!=g)) e7=h
    if(h==f) e8=f
   end

   --draw
   x0=sx+x*3
   y0=sy+y*3
   if(e0!=alpha) pset(x0,  y0,  e0)
   if(e1!=alpha) pset(x0+1,y0,  e1)
   if(e2!=alpha) pset(x0+2,y0,  e2)
   if(e3!=alpha) pset(x0,  y0+1,e3)
   if(e4!=alpha) pset(x0+1,y0+1,e4)
   if(e5!=alpha) pset(x0+2,y0+1,e5)
   if(e6!=alpha) pset(x0,  y0+2,e6)
   if(e7!=alpha) pset(x0+1,y0+2,e7)
   if(e8!=alpha) pset(x0+2,y0+2,e8)
  end
 end
end
P#23217 2016-06-19 13:56

9

Cart [#22146#] | Copy | Code | 2016-06-02 | Link
9

Wanted to throw something together for p8jam2, so did a spin on the forest-fire cellular automata.

Controls
Up/down: adjust probability of new fires
Left/right: adjust probability of tree growth
Button 1: reset probabilities
Button 1+2: reset map

(Warning: you could probably give yourself a seizure by cranking up the probabilities to the max.)

If you're not familiar with forest-fire, the rules are as follows:
1) A burning cell will become an empty cell
2) A tree will start to burn if at least one neighbor is burning
3) A tree ignites with probability f even if no neighbor is burning
4) An empty space fills with a tree with probability p
(from Wikipedia)

p8jam2
P#21388 2016-05-26 08:11


:: More
X
About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2017-10-24 00:14 | 0.307s | 1835k | Q:73