Posts: 2,701
Threads: 328
Joined: Apr 2022
Reputation:
217
10-14-2023, 01:45 AM
(This post was last modified: 09-15-2024, 08:16 AM by SMcNeill.)
Code: (Select All)
Option _Explicit
Screen _NewImage(640, 480, 32)
$Color:32
RoundRect 100, 100, 200, 200, 15, Red
RoundRectFill 200, 210, 300, 250, 5, Green
thickCircle 300, 325, 50, 4, Blue
Sub RoundRect (x As Single, y As Single, x1 As Single, y1 As Single, r As Single, c As _Unsigned Long)
Dim a As Single, b As Single, e As Single
'Draw the 4 straight lines first
Line (x, y + r)-(x, y1 - r), c
Line (x1, y + r)-(x1, y1 - r), c
Line (x + r, y)-(x1 - r, y), c
Line (x + r, y1)-(x1 - r, y1), c
a = r: b = 0: e = -a
'And then draw the rounded circle portions of the RoundRect
Do While a >= b
PSet (x + r - b, y + r - a), c: PSet (x1 - r + b, y + r - a), c
PSet (x + r - a, y + r - b), c: PSet (x1 - r + a, y + r - b), c
PSet (x + r - b, y1 - r + a), c: PSet (x1 - r + b, y1 - r + a), c
PSet (x + r - a, y1 - r + b), c: PSet (x1 - r + a, y1 - r + b), c
b = b + 1: e = e + b + b
If e > 0 Then a = a - 1: e = e - a - a
Loop
End Sub
Sub RoundRectFill (x As Single, y As Single, x1 As Single, y1 As Single, r As Single, c As _Unsigned Long)
Dim a As Single, b As Single, e As Single
Line (x, y + r+1)-(x1, y1 - r-1), c, BF
a = r: b = 0: e = -a
Do While a >= b
Line (x + r - b, y + r - a)-(x1 - r + b, y + r - a), c, BF
Line (x + r - a, y + r - b)-(x1 - r + a, y + r - b), c, BF
Line (x + r - b, y1 - r + a)-(x1 - r + b, y1 - r + a), c, BF
Line (x + r - a, y1 - r + b)-(x1 - r + a, y1 - r + b), c, BF
b = b + 1: e = e + b + b
If e > 0 Then a = a - 1: e = e - a - a
Loop
End Sub
Sub thickCircle (x As Single, y As Single, radius As Single, thickness As Single, colour As _Unsigned Long)
Dim rp As Single, rm As Single, rp2 As Single, rm2 As Single
Dim sm As Single, rpi2 As Single, rmi2 As Single, sp As Single
Dim i As Single
rp = radius + thickness / 2
rm = radius - thickness / 2
rp2 = rp ^ 2
rm2 = rm ^ 2
For i = -rp To -rm Step .2
rpi2 = rp2 - i ^ 2
sp = Sqr(rpi2)
Line (x + i, y)-(x + i, y + sp), colour, BF
Line (x + i, y)-(x + i, y - sp), colour, BF
Next
For i = -rm To 0 Step .2
rpi2 = rp2 - i ^ 2
rmi2 = rm2 - i ^ 2
sm = Sqr(rmi2)
sp = Sqr(rpi2)
Line (x + i, y + sm)-(x + i, y + sp), colour, BF
Line (x - i, y + sm)-(x - i, y + sp), colour, BF
Line (x + i, y - sm)-(x + i, y - sp), colour, BF
Line (x - i, y - sm)-(x - i, y - sp), colour, BF
Next
For i = rm To rp Step .2
rpi2 = rp2 - i ^ 2
sp = Sqr(rpi2)
Line (x + i, y)-(x + i, y + sp), colour, BF
Line (x + i, y)-(x + i, y - sp), colour, BF
Next
End Sub
So, while I was searching my hard drives for little routines and utilities to add to my new little Github Toolbox project, I came across these old routines -- RoundRectFill and thickCircle. I don't know who the original author of these were; I don't think I wrote them, but the drive they were on was probably 5 to 10 years old and dated all the way back to the days of Galleon's Forums (.net?), and back when we were all chatting and talking over on the freenode IRC chat channels. (MY original SBot which ran via freenode was in the same folders, which is what helps me date how old these things are! LOL!)
My best guess is STxATxIC or perhaps vince helped create these originally. If anyone knows for certain who the original author of RoundRectFill and thickCircle are, let me know and I'll be certain to add their names to the routines to give them credit for their work.
(If you notice, I didn't list RoundRect as being unknown. That's simple -- I wrote it this evening to go with the filled version. If there was ever an original RoundRect routine somewhere, I didn't save it, so the one here is one I derived myself. It's no mystery code! )
Anyways, I thought I'd share these here to see if anyone knows for certain who the original authors were, before just tossing them all slappy-happy into my toolbox. Kindly speak up if they were yours. Heck, they might've even been mine -- though it's been so long, I certainly don't remember them! LOL! Solve the mystery, if you have information on "Where the heck did those come from?"
Posts: 3,981
Threads: 177
Joined: Apr 2022
Reputation:
220
10-14-2023, 07:25 AM
(This post was last modified: 10-14-2023, 07:53 AM by bplus.)
(10-14-2023, 01:45 AM)SMcNeill Wrote: Code: (Select All)
Option _Explicit
Screen _NewImage(640, 480, 32)
$Color:32
RoundRect 100, 100, 200, 200, 15, Red
RoundRectFill 200, 210, 300, 250, 5, Green
thickCircle 300, 325, 50, 4, Blue
Sub RoundRect (x As Single, y As Single, x1 As Single, y1 As Single, r As Single, c As _Unsigned Long)
Dim a As Single, b As Single, e As Single
'Draw the 4 straight lines first
Line (x, y + r)-(x, y1 - r), c
Line (x1, y + r)-(x1, y1 - r), c
Line (x + r, y)-(x1 - r, y), c
Line (x + r, y1)-(x1 - r, y1), c
a = r: b = 0: e = -a
'And then draw the rounded circle portions of the RoundRect
Do While a >= b
PSet (x + r - b, y + r - a), c: PSet (x1 - r + b, y + r - a), c
PSet (x + r - a, y + r - b), c: PSet (x1 - r + a, y + r - b), c
PSet (x + r - b, y1 - r + a), c: PSet (x1 - r + b, y1 - r + a), c
PSet (x + r - a, y1 - r + b), c: PSet (x1 - r + a, y1 - r + b), c
b = b + 1: e = e + b + b
If e > 0 Then a = a - 1: e = e - a - a
Loop
End Sub
Sub RoundRectFill (x As Single, y As Single, x1 As Single, y1 As Single, r As Single, c As _Unsigned Long)
Dim a As Single, b As Single, e As Single
Line (x, y + r)-(x1, y1 - r), c, BF
a = r: b = 0: e = -a
Do While a >= b
Line (x + r - b, y + r - a)-(x1 - r + b, y + r - a), c, BF
Line (x + r - a, y + r - b)-(x1 - r + a, y + r - b), c, BF
Line (x + r - b, y1 - r + a)-(x1 - r + b, y1 - r + a), c, BF
Line (x + r - a, y1 - r + b)-(x1 - r + a, y1 - r + b), c, BF
b = b + 1: e = e + b + b
If e > 0 Then a = a - 1: e = e - a - a
Loop
End Sub
Sub thickCircle (x As Single, y As Single, radius As Single, thickness As Single, colour As _Unsigned Long)
Dim rp As Single, rm As Single, rp2 As Single, rm2 As Single
Dim sm As Single, rpi2 As Single, rmi2 As Single, sp As Single
Dim i As Single
rp = radius + thickness / 2
rm = radius - thickness / 2
rp2 = rp ^ 2
rm2 = rm ^ 2
For i = -rp To -rm Step .2
rpi2 = rp2 - i ^ 2
sp = Sqr(rpi2)
Line (x + i, y)-(x + i, y + sp), colour, BF
Line (x + i, y)-(x + i, y - sp), colour, BF
Next
For i = -rm To 0 Step .2
rpi2 = rp2 - i ^ 2
rmi2 = rm2 - i ^ 2
sm = Sqr(rmi2)
sp = Sqr(rpi2)
Line (x + i, y + sm)-(x + i, y + sp), colour, BF
Line (x - i, y + sm)-(x - i, y + sp), colour, BF
Line (x + i, y - sm)-(x + i, y - sp), colour, BF
Line (x - i, y - sm)-(x - i, y - sp), colour, BF
Next
For i = rm To rp Step .2
rpi2 = rp2 - i ^ 2
sp = Sqr(rpi2)
Line (x + i, y)-(x + i, y + sp), colour, BF
Line (x + i, y)-(x + i, y - sp), colour, BF
Next
End Sub
So, while I was searching my hard drives for little routines and utilities to add to my new little Github Toolbox project, I came across these old routines -- RoundRectFill and thickCircle. I don't know who the original author of these were; I don't think I wrote them, but the drive they were on was probably 5 to 10 years old and dated all the way back to the days of Galleon's Forums (.net?), and back when we were all chatting and talking over on the freenode IRC chat channels. (MY original SBot which ran via freenode was in the same folders, which is what helps me date how old these things are! LOL!)
My best guess is STxATxIC or perhaps vince helped create these originally. If anyone knows for certain who the original author of RoundRectFill and thickCircle are, let me know and I'll be certain to add their names to the routines to give them credit for their work.
(If you notice, I didn't list RoundRect as being unknown. That's simple -- I wrote it this evening to go with the filled version. If there was ever an original RoundRect routine somewhere, I didn't save it, so the one here is one I derived myself. It's no mystery code! )
Anyways, I thought I'd share these here to see if anyone knows for certain who the original authors were, before just tossing them all slappy-happy into my toolbox. Kindly speak up if they were yours. Heck, they might've even been mine -- though it's been so long, I certainly don't remember them! LOL! Solve the mystery, if you have information on "Where the heck did those come from?"
Well I worked on both these drawing problems and posted results in my own Toolbox Thread stuff at QB64.org and here in drawing tools or in Programs Board and probably at QB64.net where someone gave me a filled triangle from MapTriangle and you Steve improved upon over years. I started with rounded squares called Squircles (and that was a name I stole from Math YouTube video on slightly different idea doing corners with math functions) and called thick circles, rings, and thick arcs fat or thick arcs same with lines. But if code is from my stuff feel free to use it, I am not going to try and keep track of what people do with code I share. Great minds think alike so other people will likely see their work in other peoples posts. I know Fellippe did stuff with rounded corners and thick lines also .P5J some bunch of letters and a 5.
Here is squircle https://qb64phoenix.com/forum/showthread...18#pid1218
If you want to compare what you have with what I did. That thick circle looks new method to me.
b = b + ...
|