_window = 1 _wndWidth = 680 void local fn BuildWindow window _window, @"Fractal Tree", ( 0, 0, _wndWidth, 600 ) WindowSetBackgroundColor( _window, fn ColorBlack ) WindowSubclassContentView( _window ) end fn local fn PlotFractalTree( x1 as double, y1 as double, size as long, angle as double, spread as long, depth as long, scale as double ) double x2, y2 pen 1.0, fn ColorGreen, NSLineCapStyleSquare // Convert angle to radians x2 = x1 + size * cos(angle * pi / 180) y2 = y1 + size * sin(angle * pi / 180) line x1, y1, x2, y2 if ( depth > 0 ) fn PlotFractalTree( x2, y2, size * scale, angle - spread, spread, depth - 1, scale ) fn PlotFractalTree( x2, y2, size * scale, angle + spread, spread, depth - 1, scale ) end if end fn void local fn DoDialog( ev as long, tag as long ) select ( tag ) case _windowContentViewTag double spread = ( 80.0 / (_wndWidth / 2 ) ) * 90 fn PlotFractalTree( _wndWidth / 2, 550, 140, -90, spread, 10, 0.75 ) end select select ( ev ) case _windowWillClose : end end select end fn on dialog fn DoDialog fn BuildWindow HandleEvents