BasicScience wrote:Actually, the use of a unique color is not to avoid the case where paint will be "blocked"... it avoids the case where paint will "leak". For example if a line that is not in the border_color crosses the bounded region, then the paint will leak out. (you probably know this... I may have misinterpreted your text).
Hi BasicScience
This thickline topic came up about one and a half years ago, member Roger Hunter was asking if there was a built in way of doing it.
Richard, himself and myself were at it for a day or two, I'll post the thickline sub and a simple example below.
It was Richard's idea to prime before paint, and I have since always used a primer, in thickline, thickcircle and my 2d and 3d rotators.
I suppose it makes sense, prime then paint, not only in Freebasic, but also in home improvement projects.
Here's the thickline sub, I've painted 15 random lines to an image, press spacebar for next image, esc to quit:
Code: Select all
'THICKLINE
Sub thickline(x1 As Double,_
y1 As Double,_
x2 As Double,_
y2 As Double,_
thickness As Double,_
colour As Uinteger,_
im as any pointer=0)
dim p as uinteger
p=Rgb(255, 255, 255)
If thickness<2 Then
Line(x1,y1)-(x2,y2),colour
Else
Dim As Double s,h,c
h=Sqr((x2-x1)^2+(y2-y1)^2) 'hypotenuse
s=(y1-y2)/h 'sine
c=(x2-x1)/h 'cosine
Line im,(x1+s*thickness/2,y1+c*thickness/2)-(x2+s*thickness/2,y2+c*thickness/2),p
Line im,(x1-s*thickness/2,y1-c*thickness/2)-(x2-s*thickness/2,y2-c*thickness/2),p
Line im,(x1+s*thickness/2,y1+c*thickness/2)-(x1-s*thickness/2,y1-c*thickness/2),p
Line im,(x2+s*thickness/2,y2+c*thickness/2)-(x2-s*thickness/2,y2-c*thickness/2),p
Paint im,((x1+x2)/2, (y1+y2)/2), p, p
Line im,(x1+s*thickness/2,y1+c*thickness/2)-(x2+s*thickness/2,y2+c*thickness/2),colour
Line im,(x1-s*thickness/2,y1-c*thickness/2)-(x2-s*thickness/2,y2-c*thickness/2),colour
Line im,(x1+s*thickness/2,y1+c*thickness/2)-(x1-s*thickness/2,y1-c*thickness/2),colour
Line im,(x2+s*thickness/2,y2+c*thickness/2)-(x2-s*thickness/2,y2-c*thickness/2),colour
Paint im,((x1+x2)/2, (y1+y2)/2), colour, colour
End If
End Sub
' ********************************************************
Dim As Integer desktop_width, desktop_height
Screeninfo desktop_width, desktop_height
Screenres desktop_width, desktop_height,32
dim as any pointer image
dim count as integer
do
randomize
count=0
image=imagecreate(desktop_width, desktop_height,rgb(0,0,0))
Do
count=count+1
'screenlock
thickline(_
Int(Rnd * desktop_width), Int(Rnd * desktop_height),_
Int(Rnd * desktop_width), Int(Rnd * desktop_height),_
Int(4 + Rnd * desktop_height / 8),_ ' avoids lines narrower than 4
Rgb(Int(Rnd * 255), Int(Rnd * 256), Int(Rnd * 256)),image) ' avoids prime colour
'screenunlock
'Sleep 1,1
Loop Until count=15 'number of lines
put (0,0),image,pset
sleep
imagedestroy image
loop until inkey=chr(27)