USING: arrays math math.constants math.functions namespaces kernel opengl.gl locals ui.gadgets.canvas ui.gadgets ui.render accessors sequences math.order ui prettyprint ; IN: dragon ! http://rosettacode.org/wiki/Dragon_curve#BASIC SYMBOLS: point angle ; : trn ( d -- ) pi * 180 / angle get + angle set ; : fwd ( l -- ) [ angle get cos * ] [ angle get sin * ] bi 2array GL_LINE_STRIP glBegin dup point get first2 [ 100 + ] bi@ glVertex2d first2 [ 100 + ] bi@ glVertex2d glEnd point set ; :: dragon' ( l s d -- ) s zero? [ l fwd ] [ 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 ! artifact from maze.factor i don't understand 1 glLineWidth 1.0 1.0 1.0 glColor3d 0 angle set { 150 180 } point set 400 12 1 dragon' ; ! --- there be dragons beyond this, no idea why i have to do all 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 { 640 480 } ; MAIN-WINDOW: dragon-window { { title "Dragon Curve" } } dragon-canvas new-canvas >>gadgets ; MAIN: dragon-window