RosettaCodeData/Task/Dutch-national-flag-problem/FutureBasic/dutch-national-flag-problem.basic

44 lines
1 KiB
Text
Raw Permalink Normal View History

2024-11-04 20:28:54 -08:00
void local fn DrawBalls( y as long, balls as CFArrayRef, sort as BOOL )
2025-02-27 18:35:13 -05:00
long col, prevCol = 0, x = 10
CFArrayRef cols = @[fn ColorWithSRGB(.78,.06,.18,1.0),fn ColorWhite,fn ColorWithSRGB(0,.24,.65,1.0)]
if ( sort ) then balls = fn ArraySortedArrayUsingSelector( balls, @"compare:" )
pen -1
for long i = 0 to len(balls) - 1
col = intval(balls[i])
if ( sort == YES )
if ( col != prevCol ) then y += 30 : x = 10
else
if ( i > 0 && i % 15 == 0 ) then y += 30 : x = 10
end if
oval fill (x,y,30,30), cols[col]
x += 30
prevCol = col
next
2024-11-04 20:28:54 -08:00
end fn
void local fn DutchNationalFlagProblem
2025-02-27 18:35:13 -05:00
window 1, @"Dutch national flag problem", (0,0,470,230)
WindowSetBackgroundColor( 1, fn ColorWithSRGB(1.0,.61,0,1.0) )
2024-11-04 20:28:54 -08:00
2025-02-27 18:35:13 -05:00
CFMutableArrayRef balls = fn MutableArrayNew
2024-11-04 20:28:54 -08:00
2025-02-27 18:35:13 -05:00
text @"Menlo-Bold",, fn ColorWhite
2024-11-04 20:28:54 -08:00
2025-02-27 18:35:13 -05:00
for long i = 0 to 29
balls[i] = @(rnd(3)-1)
next
2024-11-04 20:28:54 -08:00
2025-02-27 18:35:13 -05:00
print @"Unsorted:"
fn DrawBalls( 20, balls, NO )
2024-11-04 20:28:54 -08:00
2025-02-27 18:35:13 -05:00
print %(3,100)@"Sorted:"
fn DrawBalls( 120, balls, YES )
2024-11-04 20:28:54 -08:00
end fn
random
fn DutchNationalFlagProblem
HandleEvents