28 lines
754 B
Plaintext
28 lines
754 B
Plaintext
_window = 1
|
|
_width = 600
|
|
_height = 500
|
|
|
|
local fn SierpinskyTriangle( level as NSUInteger, x as NSUInteger, y as NSUInteger, w as NSUInteger, h as NSUInteger )
|
|
NSUInteger w2 = w/2, w4 = w/4, h2 = h/2
|
|
|
|
if ( level == 1 )
|
|
pen -1.0
|
|
line to x, y
|
|
pen 1.0, fn ColorYellow
|
|
line to x+w2, y+h
|
|
line to x+w, y
|
|
line to x, y
|
|
else
|
|
fn SierpinskyTriangle( level-1, x, y, w2, h2 )
|
|
fn SierpinskyTriangle( level-1, x+w4, y+h2, w2, h2 )
|
|
fn SierpinskyTriangle( level-1, x+w2, y, w2, h2 )
|
|
end if
|
|
end fn
|
|
|
|
window _window, @"Sierpinsky Triangle", ( 0, 0, _width, _height )
|
|
WindowSetBackgroundColor( 1, fn ColorBlack )
|
|
|
|
fn SierpinskyTriangle( 9, _width * 0.05, _height * 0.05, _width * 0.9, _height * 0.9 )
|
|
|
|
HandleEvents
|