Post by bplus on Oct 17, 2022 0:12:39 GMT
The _MapTriangle subst code works here but QBJS still needs Xor:
_Title "Xor 2 fans" 'b+ 2022-09-10 just saw at JB
' hmm... how to do this in QB64?
Screen _NewImage(800, 600, 32)
Dim As Long f1, f2
f1 = _NewImage(800, 600, 32)
f2 = _NewImage(800, 600, 32)
Color , &HFF990000
Do
Cls
ao1 = ao1 + .012: ao2 = ao2 - .012
_Dest f1
Line (0, 0)-(799, 599), _RGB32(0, 0, 0), BF
drawFan 300, 300, 295, 32, &HFFFFFFFF, ao1
_Dest f2
Line (0, 0)-(799, 599), _RGB32(0, 0, 0), BF
drawFan 500, 300, 295, 32, &HFFFFFFFF, ao2
_Dest 0
For y = 0 To 599
For x = 0 To 799
_Source f1
If Point(x, y) = _RGB32(0, 0, 0) Then p1 = 0 Else p1 = -1
_Source f2
If Point(x, y) = _RGB32(0, 0, 0) Then p2 = 0 Else p2 = -1
If p1 Xor p2 Then PSet (x, y), &HFFAAAAAA ' tone it down a bit
Next
Next
_Display
_Limit 60 'Draw as fast as you can!
Loop
Sub drawFan (x, y, r, nBlades, colr As _Unsigned Long, ao)
angle = _Pi(1 / nBlades)
For i = 0 To 2 * nBlades - 1 Step 2
x1 = x + r * Cos(i * angle + ao)
y1 = y + r * Sin(i * angle + ao)
x2 = x + r * Cos((i + 1) * angle + ao)
y2 = y + r * Sin((i + 1) * angle + ao)
filltri x, y, x1, y1, x2, y2, colr
Next
End Sub
'Sub ftri (x1, y1, x2, y2, x3, y3, K As _Unsigned Long)
' Dim D As Long
' Static a&
' D = _Dest
' If a& = 0 Then a& = _NewImage(1, 1, 32)
' _Dest a&
' _DontBlend a& ' '<<<< new 2019-12-16 fix
' PSet (0, 0), K
' _Blend a& '<<<< new 2019-12-16 fix
' _Dest D
' _MapTriangle _Seamless(0, 0)-(0, 0)-(0, 0), a& To(x1, y1)-(x2, y2)-(x3, y3)
'End Sub
'Andy Amaya's triangle fill modified for QB64, use if color already set
Sub filltri (xx1, yy1, xx2, yy2, xx3, yy3, K As _Unsigned Long)
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