Cantor set: Difference between revisions

(Add Rust implementation)
Line 2,234:
███ ███ ███ ███
█ █ █ █ █ █ █ █</pre>
 
=={{header|QB64}}==
{{trans|FreeBASIC}}
 
Note: Other languages will need to zero out the a() array. In QB64 all arrays are initialized to zero at program start.
 
<lang qb64>_Title "Cantor Set"
 
Dim Shared As Integer sw, sh, wide, high
sw = 800: sh = 200: wide = 729: high = 7
Dim Shared As Integer a(wide, high)
 
Screen _NewImage(sw, sh, 8)
Cls , 15: Color 0
 
Call calc(0, wide, 1)
Call CantorSet
 
Sleep
System
 
Sub calc (start As Integer, length As Integer, index As Integer)
Dim As Integer i, j, newLength
newLength = length \ 3
If newLength = 0 Then Exit Sub
For j = index To high - 1
For i = start + newLength To start + newLength * 2 - 1
a(i, j) = 1
Next
Next
Call calc(start, newLength, index + 1)
Call calc(start + newLength * 2, newLength, index + 1)
End Sub
 
Sub CantorSet
Dim As Integer i, j, x, y
For y = 0 To high - 1
j = y + 1
For x = 0 To wide - 1
i = x + 34
If a(x, y) = 0 Then Line (i, j * 24 - 5)-(i, j * 24 + 17)
Next
Next
End Sub</lang>
 
=={{header|Racket}}==
Anonymous user