Post by plus on Feb 18, 2023 21:05:33 GMT
This is a recursive update to 8 year old code so that it may do different divisors of the screen and go deeper into levels than hard coded loops.
Ymax is setup to just fit my screen go ahead and make it bigger or smaller for yours, just match Xmax to it.
global Xmax, Ymax, Divisor, DivisorMinusOne
Xmax = 740
Ymax = 740
WindowWidth = Xmax + 8
WindowHeight = Ymax + 32
UpperLeftX = (DisplayWidth - Xmax) / 2 'or delete if Xmax is 1200 or above
UpperLeftY = 0 'or delete if Ymax is 700 or above
nomainwin
open "Checkered Checkers Recursive" for graphics_nsb_nf as #gr '<======================= title
#gr "trapclose quit"
#gr "fill black"
#gr "down"
#gr "color white"
#gr "backcolor white"
While 1
scan
Divisor = Int(Rnd(0) * 9) + 2
DivisorMinusOne = Divisor - 1
ReDim arr(DivisorMinusOne, DivisorMinusOne) ' holds pattern
For j = 0 To DivisorMinusOne
For i = 0 To DivisorMinusOne
If Rnd(0) < .5 Then arr(i, j) = 1
Next
Next
call CheckRecur 0, 0, 739 / Divisor
call pause 5000
#gr "fill black"
Wend
wait
sub quit H$
close #gr '<=== this needs Global H$ = "gr"
end 'Thanks Facundo, close graphic wo error
end sub
sub pause mil 'tsh version has scan built-in
t0 = time$("ms")
while time$("ms") < t0 + mil : scan : wend
end sub
Sub CheckRecur FirstX, FirstY, Side
If Side <= 4 Then Exit Sub ' done
For y = 0 To DivisorMinusOne
For x = 0 To DivisorMinusOne
scan
'Line (FirstX + x * Side, FirstY + y * Side)-Step(Side, Side), , B
#gr "place ";FirstX + x * Side;" ";FirstY + y * Side
#gr "box ";FirstX + x * Side + Side;" ";FirstY + y * Side + Side
If Side / Divisor <= 4 Then
If arr(x, y) Then
#gr "color white"
#gr "backcolor white"
Else
#gr "color black"
#gr "backcolor black"
End If
#gr "place ";FirstX + x * Side + 1;" ";FirstY + y * Side + 1
#gr "boxfilled ";FirstX + x * Side + Side - 2;" ";FirstY + y * Side + Side - 2
#gr "color white"
#gr "backcolor white"
Else
If arr(x, y) Then
call CheckRecur FirstX + x * Side, FirstY + y * Side, Side / Divisor
End If
End If
Next
Next
End Sub
Ymax is setup to just fit my screen go ahead and make it bigger or smaller for yours, just match Xmax to it.