46 lines
1.1 KiB
Plaintext
46 lines
1.1 KiB
Plaintext
_window = 1
|
|
|
|
void local fn BuildWindow
|
|
CGRect r = fn CGRectMake( 0, 0, 705, 500 )
|
|
window _window, @"Pythagoras Tree In FutureBasic", r, NSWindowStyleMaskTitled
|
|
WindowSetBackgroundColor( _window, fn ColorBlack )
|
|
end fn
|
|
|
|
local fn PythagorasTree( x1 as double, y1 as double, x2 as double, y2 as double, depth as NSUInteger )
|
|
if depth > 10 then exit fn
|
|
|
|
double dx = x2 - x1, dy = y1 - y2
|
|
double x3 = x2 - dy, y3 = y2 - dx
|
|
double x4 = x1 - dy, y4 = y1 - dx
|
|
double x5 = x4 + (dx - dy) / 2
|
|
double y5 = y4 - (dx + dy) / 2
|
|
|
|
select ( rnd(5) )
|
|
case 1 : pen 2, fn ColorBrown
|
|
case 2 : pen 2, fn ColorRed
|
|
case 3 : pen 2, fn ColorOrange
|
|
case 4 : pen 2, fn ColorYellow
|
|
case 5 : pen 2, fn ColorGreen
|
|
end select
|
|
|
|
line x1, y1, x2, y2 : Line x2, y2, x3, y3
|
|
line x3, y3, x4, y4 : Line x4, y4, x1, y1
|
|
|
|
fn PythagorasTree( x4, y4, x5, y5, depth +1 )
|
|
fn PythagorasTree( x5, y5, x3, y3, depth +1 )
|
|
end fn
|
|
|
|
local fn DrawTree
|
|
NSUInteger w = 700, h = w * 11 \ 16
|
|
NSUInteger w2 = w \ 2, diff = w \ 12
|
|
|
|
fn PythagorasTree( w2 - diff, h -10 , w2 + diff , h -10 , 0 )
|
|
end fn
|
|
|
|
random
|
|
|
|
fn BuildWindow
|
|
fn DrawTree
|
|
|
|
HandleEvents
|