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 math.vectors ; IN: dragon ! http://rosettacode.org/wiki/Dragon_curve#BASIC SYMBOLS: point angle ; : trn ( d -- ) pi * 180 / angle get + angle set ; : draw-fwd ( p -- ) ! this is still kinda ugly, TODO fancy colors dup point get swap point get v+ GL_LINES glBegin [ first2 glVertex2d ] bi@ glEnd point get v+ point set ; : fwd ( l -- ) [ angle get cos * ] [ angle get sin * ] bi 2array draw-fwd ; :: 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 but breaks 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 some of this TUPLE: dragon-canvas < canvas ; 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