Author: Ouims
Added: 4y
Updated: 4y
mIRC: Unknown
Hits: 863
Downloads: 6
Review: westor
Size: 1.11KB
2 0
Login to vote.
Drawing gradient colored line between 2 RGB colors
v1.0
This snippet draw a line in a picture window, just like /drawline is, except that you can pass two RGB colors and it draws a gradient between the two points.
In bonus, you get the $interpol alias, which can be used to get the color you need based on a percentage, $interpol(rgb1,rgb2,p) where p is 1 for 100%, and 0 for 0%
So if rgb1 is 255 and rgb2 is 64512 (green), $interpol(255,64512,0) is 255 $interpol(255,64512,1) is 64512 and $interpol(255,64512,0.5) is the color right in between both.
;/drawgradientline x1 y1 x2 y2 rgb1 rgb2 size @win
x1 y1 = first point, same as /drawline
x2 y2 = second point, same as /drawline
rgb1 = first color
rgb2 = second color
size = the size of the line, same as /drawline
@win = the picture window
For example, execute:
//window -pdfoC +Lt @dgl -1 -1 600 600 | drawgradientline 50 50 500 500 255 64512 8 @dgl
;/drawgradientline x1 y1 x2 y2 rgb1 rgb2 size @win alias drawgradientline { drawdot -r $8 $5 $7 $1 $2 drawdot -r $8 $6 $7 $3 $4 if ($1 < $3) var %x1 $1,%y1 $2,%x2 $3,%y2 $4,%c1 $5,%c2 $6 elseif ($1 > $3) var %x1 $3,%y1 $4,%x2 $1,%y2 $2,%c1 $6,%c2 $5 else { if ($2 < $4) var %r 1,%x1 $2,%y1 $1,%x2 $4,%y2 $3,%c1 $5,%c2 $6 elseif ($2 > $4) var %r 1,%x1 $4,%y1 $3,%x2 $2,%y2 $1,%c1 $6,%c2 $5 else { echo -s * /drawgradientline you're passing the same point! | return } } var %ox %x1,%oy %y1,%n 0,%oldx %x1,%oldy %y1 while (%x1 <= %x2) { var %x1 $calc(%ox + %n * (%x2 - %ox)),%y1 $calc(%oy + %n * (%y2 - %oy)) if (%r) drawline -r $8 $interpol(%c1,%c2,$calc((%x1 - %ox) / (%x2 - %ox))) $7 %oldy %oldx %y1 %x1 else drawline -r $8 $interpol(%c1,%c2,$calc((%x1 - %ox) / (%x2 - %ox))) $7 %oldx %oldy %x1 %y1 inc %n 0.001 %oldx = %x1 %oldy = %y1 } } alias interpol var %f $3 | tokenize 44 $rgb($1) $+ , $+ $rgb($2) | return $rgb($calc(($4 - $1) * %f + $1),$calc(($5 - $2) * %f + $2),$calc(($6 - $3) * %f + $3))
0
Moderator
Moderator
It does make things faster but would change the effect, I'll leave it like that, people can edit the snippet to use -n is they need to.