USING: arrays math math.constants math.functions namespaces kernel opengl.gl locals ui.gadgets.canvas ui.gadgets ui.render accessors sequences math.order ui ; IN: dragon SYMBOL: angle SYMBOL: point : trn ( d -- ) pi * 180 / angle get + angle set ; : frw ( l -- ) [ cos ] [ sin ] bi 2array GL_LINE glBegin point get glVertex2d dup glVertex2d glEnd point set ; :: dragon' ( l s d -- ) s zero? [ l frw ] [ d 45 * trn l 2 sqrt / s 1 - 1 dragon' d neg 90 * trn l 2 sqrt / s 1 - -1 dragon' d 45 * trn ] if ; : dragon ( n -- ) drop 1 glLineWidth 1 glPointSize 1.0 1.0 1.0 1.0 glColor4d 0 angle set { 150 180 } point set 400 12 1 dragon ; ! --- there be dragons beyond this TUPLE: dragon-canvas < canvas ; M: dragon-canvas layout* delete-canvas-dlist ; M: dragon-canvas draw-gadget* [ dim>> first2 min 3 /i dragon ] draw-canvas ; M: dragon-canvas pref-dim* drop { 430 300 } ; MAIN-WINDOW: dragon-window { { title "Dragon Curve" } } dragon-canvas new-canvas >>gadgets ; MAIN: dragon-window