diff --git a/include/tools.bm b/include/tools.bm index 7a7cc0a..9930375 100644 --- a/include/tools.bm +++ b/include/tools.bm @@ -222,3 +222,71 @@ sub floodfill (startx,starty,fillcolor~&) wend end sub +sub ditheredgradient (x1 as long,y1 as long,x2 as long,y2 as long,fcol as _unsigned long,bcol as _unsigned long) + ' 1. Get canvas boundaries from the active drawing layer + dim canvasw as integer:canvasw=_width(layers(1).ihandle) + dim canvash as integer:canvash=_height(layers(1).ihandle) + + ' 2. Calculate vector properties of the drawn line + dim dx as single:dx=x2-x1 + dim dy as single:dy=y2-y1 + dim linelensq as single:linelensq=(dx*dx)+(dy*dy) + + ' If the user didn't drag the mouse anywhere, just paint a solid pixel and exit + if linelensq=0 then + pset (x1,y1),fcol + exit sub + end if + + ' 3. Extract RGB components of Foreground and Background colors + dim fr as integer:fr=_red(fcol) + dim fg as integer:fg=_green(fcol) + dim fb as integer:fb=_blue(fcol) + + dim br as integer:br=_red(bcol) + dim bg as integer:bg=_green(bcol) + dim bb as integer:bb=_blue(bcol) + + ' 4. Define a standard 4x4 Bayer Dithering Matrix (scaled 0 to 15) + dim bayer(3,3) as integer + bayer(0,0)=0:bayer(0,2)=8:bayer(0,1)=2:bayer(0,3)=10 + bayer(2,0)=12:bayer(2,2)=4:bayer(2,1)=14:bayer(2,3)=6 + bayer(1,0)=3:bayer(1,2)=11:bayer(1,1)=1:bayer(1,3)=9 + bayer(3,0)=15:bayer(3,2)=7:bayer(3,1)=13:bayer(3,3)=5 + + ' 5. Loop through every single pixel on the canvas layer + dim x as long,y as long + dim t as single,threshold as single + dim targetr as integer,targetg as integer,targetb as integer + dim mixedcolor as _unsigned long + + for y=0 to canvash-1 + for x=0 to canvasw-1 + ' Project current pixel onto the line vector to get interpolation factor 't' + t=((x-x1)*dx+(y-y1)*dy)/linelensq + + ' Clamp t strictly between 0.0 and 1.0 + if t<0 then t=0 + if t>1 then t=1 + + ' Get the ordered dither adjustment ratio (-0.5 to +0.5 range influence) + threshold=(bayer(x mod 4,y mod 4)/16.0)-0.5 + + ' Apply blend factor altered by our dither threshold noise + dim blend as single:blend=t+threshold + if blend<0 then blend=0 + if blend>1 then blend=1 + + ' Linearly interpolate colors + targetr=fr+(br-fr)*blend + targetg=fg+(bg-fg)*blend + targetb=fb+(bb-fb)*blend + + ' Find the absolute closest matching color available in your specific palette + mixedcolor=closestcolor(_rgb32(targetr,targetg,targetb),pal()) + + ' Draw directly onto the destination image + pset (x,y),mixedcolor + next x + next y +end sub diff --git a/pixler.bas b/pixler.bas index d1ad632..885e2e0 100644 --- a/pixler.bas +++ b/pixler.bas @@ -734,7 +734,7 @@ function icon (index as long) static icons() as long if not init then redim icons(19) as long ' Room for 20 icons - dim c as _unsigned long:c=_rgb32(255,255,255) ' Main icon color + dim c as _unsigned long:c=highlightcolor ' Main icon color ' --- 1. Pencil Tool --- icons(0)=_newimage(32,32,32):_dest icons(0) @@ -758,8 +758,7 @@ function icon (index as long) ' --- 4. Filled Circle --- icons(3)=_newimage(32,32,32):_dest icons(3) - dim r as integer - for r=0 to 11:circle (16,16),r,c:next r + filledcircle 16,16,11,c _dest 0 ' --- 5. Hollow Box --- @@ -794,8 +793,7 @@ function icon (index as long) line (20,26)-(26,20),c line (26,20)-(14,8),c line (14,8)-(8,14),c - ' Fixed syntax: Using valid multiplier expressions for the arc - circle (14,11),6,c,_pi(1),_pi(1.5) + circle (14,11),6,c,_pi(1.5),_pi(1) pset (6,28),c ' Spilling drip point _dest 0