RosettaCodeData/Task/Sierpinski-carpet/FutureBasic/sierpinski-carpet.basic

26 lines
605 B
Plaintext

local fn IsInCarpet( x as NSUInteger, y as NSUInteger ) as BOOL
while ( x != 0 && y != 0 )
if ( x % 3 == 1 && y % 3 == 1 ) then return NO
y /= 3 : x /= 3
wend
end fn = YES
void local fn SierpinskiCarpet( n as NSUInteger )
NSUInteger i, j, k = fn pow(3,n) - 1
pen -1
for i = 0 to k
for j = 0 to k
ColorRef col = fn ColorOrange
if ( fn IsInCarpet(i,j) )
col = fn ColorRed
end if
rect fill (i * 10, j * 10, 10, 10 ), col
next
next
end fn
window 1, @"Sierpinski Carpet", (0,0,270,270), NSWindowStyleMaskTitled
fn SierpinskiCarpet(3)
HandleEvents