Posts: 597
Threads: 110
Joined: Apr 2022
Reputation:
34
Okay, this floats my boat something silly. Macro-programming to generate standard BASIC code for polygon generation.
Although the BAM source code is useless for QB64PE, the exported program is post-processing: so the end result is a BASIC program that will work A-1 with QB64PE.
Well, EXCEPTION: I've got an instance of IFF in the generated code.
Regardless, I think anybody will find in there what they need to create proper QB64PE code.
Details: Testing: POLYGON macro and support library
Well, proof will be in the pudding. I've got to test everything for various polygons to see if the code breaks.
Posts: 597
Threads: 110
Joined: Apr 2022
Reputation:
34
This test program is kind of fun:
Posts: 660
Threads: 142
Joined: Apr 2022
Reputation:
58
Posts: 597
Threads: 110
Joined: Apr 2022
Reputation:
34
09-01-2023, 08:01 PM
(This post was last modified: 09-01-2023, 08:26 PM by CharlieJV.)
(09-01-2023, 07:40 PM)James D Jarvis Wrote: could this be of any help? polyFT - draw filled polygons (qb64phoenix.com)
That's really good, but I don't have a _MapTriangle statement in BAM.
I've got a working prototype for an eventual POLYGON subroutine-as-include-library:
Posts: 3,994
Threads: 179
Joined: Apr 2022
Reputation:
222
(09-01-2023, 08:01 PM)CharlieJV Wrote: (09-01-2023, 07:40 PM)James D Jarvis Wrote: could this be of any help? polyFT - draw filled polygons (qb64phoenix.com)
That's really good, but I don't have a _MapTriangle statement in BAM.
I've got a working prototype for an eventual POLYGON subroutine-as-include-library:
You do have a triangle fill routine from me (from Andy). It won't be as fast as _MapTriangle but it will do.
b = b + ...
Posts: 597
Threads: 110
Joined: Apr 2022
Reputation:
34
(09-01-2023, 08:56 PM)bplus Wrote: (09-01-2023, 08:01 PM)CharlieJV Wrote: (09-01-2023, 07:40 PM)James D Jarvis Wrote: could this be of any help? polyFT - draw filled polygons (qb64phoenix.com)
That's really good, but I don't have a _MapTriangle statement in BAM.
I've got a working prototype for an eventual POLYGON subroutine-as-include-library:
You do have a triangle fill routine from me (from Andy). It won't be as fast as _MapTriangle but it will do.
Yeah, I wound up not using it because I didn't want to specify the fill points. I wanted the POLYGON statement to figure it out.
Posts: 597
Threads: 110
Joined: Apr 2022
Reputation:
34
I decided to keep it simple and just use PAINT, and focused efforts on the task of identifying a point to be used for PAINT.
The process of drawing the polygon identifies the leftmost coordinate (let's call that "a"), and the immediate neighbouring coordinates of "a".
Of the neighbouring coordinates, identify the topmost coordinate. Let's call that "b".
Find the midpoint coordinate between a and b. From there, go down one pixel, and go right one pixel. PAINT at that spot.
Something like that. I've put that code aside to review it again later after finishing up a "Rgba" set of library subroutines. I figure when I look at the POLYGON code again later with fresh eyes and faint memory, I'll be in a better place to go "what the hell were you thinking?"
Posts: 3,994
Threads: 179
Joined: Apr 2022
Reputation:
222
09-01-2023, 10:28 PM
(This post was last modified: 09-01-2023, 10:34 PM by bplus.)
Don't have to figure fill point with triangle fills:
Code: (Select All) _Title "Polygonal Fills without Paint or MapTriangle"
Screen _NewImage(800, 600, 32)
_ScreenMove 250, 50
Dim x(1 To 200), y(1 To 200)
Color &HFFFFFF00
Do
While _MouseInput: Wend
If _MouseButton(1) Then
mx = _MouseX: my = _MouseY
p = p + 1
x(p) = mx: y(p) = my
If p >= 3 Then
filltri x(p - 2), y(p - 2), x(p - 1), y(p - 1), x(p), y(p)
End If
_Delay .25
End If
K$ = InKey$
If K$ = "c" Then
Cls
p = 0
Erase x, y
End If
Loop Until _KeyDown(27)
'Andy Amaya's triangle fill modified for QB64, use if color already set
Sub filltri (xx1, yy1, xx2, yy2, xx3, yy3)
Dim x1 As Single, y1 As Single, x2 As Single, y2 As Single, x3 As Single, y3 As Single
Dim slope1 As Single, slope2 As Single, length As Single, x As Single, lastx%, y As Single
Dim slope3 As Single
'make copies before swapping
x1 = xx1: y1 = yy1: x2 = xx2: y2 = yy2: x3 = xx3: y3 = yy3
'triangle coordinates must be ordered: where x1 < x2 < x3
If x2 < x1 Then Swap x1, x2: Swap y1, y2
If x3 < x1 Then Swap x1, x3: Swap y1, y3
If x3 < x2 Then Swap x2, x3: Swap y2, y3
If x1 <> x3 Then slope1 = (y3 - y1) / (x3 - x1)
'draw the first half of the triangle
length = x2 - x1
If length <> 0 Then
slope2 = (y2 - y1) / length
For x = 0 To length
Line (Int(x + x1), Int(x * slope1 + y1))-(Int(x + x1), Int(x * slope2 + y1))
lastx% = Int(x + x1)
Next
End If
'draw the second half of the triangle
y = length * slope1 + y1: length = x3 - x2
If length <> 0 Then
slope3 = (y3 - y2) / length
For x = 0 To length
If Int(x + x2) <> lastx% Then
Line (Int(x + x2), Int(x * slope1 + y))-(Int(x + x2), Int(x * slope3 + y2))
End If
Next
End If
End Sub
There may be an art to keeping last 2 points going in the direction you want the poly to go.
b = b + ...
Posts: 597
Threads: 110
Joined: Apr 2022
Reputation:
34
09-01-2023, 10:47 PM
(This post was last modified: 09-01-2023, 10:59 PM by CharlieJV.)
(09-01-2023, 10:28 PM)bplus Wrote: Don't have to figure fill point with triangle fills:
Code: (Select All) _Title "Polygonal Fills without Paint or MapTriangle"
Screen _NewImage(800, 600, 32)
_ScreenMove 250, 50
Dim x(1 To 200), y(1 To 200)
Color &HFFFFFF00
Do
While _MouseInput: Wend
If _MouseButton(1) Then
mx = _MouseX: my = _MouseY
p = p + 1
x(p) = mx: y(p) = my
If p >= 3 Then
filltri x(p - 2), y(p - 2), x(p - 1), y(p - 1), x(p), y(p)
End If
_Delay .25
End If
K$ = InKey$
If K$ = "c" Then
Cls
p = 0
Erase x, y
End If
Loop Until _KeyDown(27)
'Andy Amaya's triangle fill modified for QB64, use if color already set
Sub filltri (xx1, yy1, xx2, yy2, xx3, yy3)
Dim x1 As Single, y1 As Single, x2 As Single, y2 As Single, x3 As Single, y3 As Single
Dim slope1 As Single, slope2 As Single, length As Single, x As Single, lastx%, y As Single
Dim slope3 As Single
'make copies before swapping
x1 = xx1: y1 = yy1: x2 = xx2: y2 = yy2: x3 = xx3: y3 = yy3
'triangle coordinates must be ordered: where x1 < x2 < x3
If x2 < x1 Then Swap x1, x2: Swap y1, y2
If x3 < x1 Then Swap x1, x3: Swap y1, y3
If x3 < x2 Then Swap x2, x3: Swap y2, y3
If x1 <> x3 Then slope1 = (y3 - y1) / (x3 - x1)
'draw the first half of the triangle
length = x2 - x1
If length <> 0 Then
slope2 = (y2 - y1) / length
For x = 0 To length
Line (Int(x + x1), Int(x * slope1 + y1))-(Int(x + x1), Int(x * slope2 + y1))
lastx% = Int(x + x1)
Next
End If
'draw the second half of the triangle
y = length * slope1 + y1: length = x3 - x2
If length <> 0 Then
slope3 = (y3 - y2) / length
For x = 0 To length
If Int(x + x2) <> lastx% Then
Line (Int(x + x2), Int(x * slope1 + y))-(Int(x + x2), Int(x * slope3 + y2))
End If
Next
End If
End Sub
There may be an art to keeping last 2 points going in the direction you want the poly to go.
I thought you were referencing your first no,second (good grief...) first post in this thread.
Later when I revisit my POLYGON fill method, I'll compare with James' approach and figure out which way I want to go.
Posts: 597
Threads: 110
Joined: Apr 2022
Reputation:
34
I should not have looked at that tonight, but I could not help myself. The POLYGON and fill setup I was lining myself up with seems much more compact overall.
I'm tossing it all aside for the next week or so to look at again later.
|