gradient
This commit is contained in:
parent
3c35f4cc8a
commit
41b28e4fd2
2 changed files with 71 additions and 5 deletions
|
|
@ -222,3 +222,71 @@ sub floodfill (startx,starty,fillcolor~&)
|
||||||
wend
|
wend
|
||||||
end sub
|
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
|
||||||
|
|
|
||||||
|
|
@ -734,7 +734,7 @@ function icon (index as long)
|
||||||
static icons() as long
|
static icons() as long
|
||||||
if not init then
|
if not init then
|
||||||
redim icons(19) as long ' Room for 20 icons
|
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 ---
|
' --- 1. Pencil Tool ---
|
||||||
icons(0)=_newimage(32,32,32):_dest icons(0)
|
icons(0)=_newimage(32,32,32):_dest icons(0)
|
||||||
|
|
@ -758,8 +758,7 @@ function icon (index as long)
|
||||||
|
|
||||||
' --- 4. Filled Circle ---
|
' --- 4. Filled Circle ---
|
||||||
icons(3)=_newimage(32,32,32):_dest icons(3)
|
icons(3)=_newimage(32,32,32):_dest icons(3)
|
||||||
dim r as integer
|
filledcircle 16,16,11,c
|
||||||
for r=0 to 11:circle (16,16),r,c:next r
|
|
||||||
_dest 0
|
_dest 0
|
||||||
|
|
||||||
' --- 5. Hollow Box ---
|
' --- 5. Hollow Box ---
|
||||||
|
|
@ -794,8 +793,7 @@ function icon (index as long)
|
||||||
line (20,26)-(26,20),c
|
line (20,26)-(26,20),c
|
||||||
line (26,20)-(14,8),c
|
line (26,20)-(14,8),c
|
||||||
line (14,8)-(8,14),c
|
line (14,8)-(8,14),c
|
||||||
' Fixed syntax: Using valid multiplier expressions for the arc
|
circle (14,11),6,c,_pi(1.5),_pi(1)
|
||||||
circle (14,11),6,c,_pi(1),_pi(1.5)
|
|
||||||
pset (6,28),c ' Spilling drip point
|
pset (6,28),c ' Spilling drip point
|
||||||
_dest 0
|
_dest 0
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue