USING: arrays math math.constants math.functions namespaces kernel colors colors.hsv opengl.gl locals ui.gadgets.canvas ui.gadgets ui.render accessors sequences math.order ui prettyprint math.vectors random ; IN: dragon ! http://rosettacode.org/wiki/Dragon_curve#BASIC SYMBOLS: point angle color ; : trn ( d -- ) pi * 180 / angle get + angle set ; : new-color ( -- ) color get dup 1.0 1.0 1.0 >rgba-components glColor4d dup 360 = [ drop 0 color set ] [ 0.1 + color set ] if ; : draw-fwd ( p -- ) new-color dup point get GL_LINES glBegin [ first2 glVertex2d ] bi@ glEnd point set ; : fwd ( l -- ) [ angle get cos * ] [ angle get sin * ] bi 2array point get v+ 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, see draw-gadget* 0 angle set { 150 180 } point set 0 color set 400 12 1 dragon' ; TUPLE: dragon-canvas < canvas ; ! this quote is silly and i have no idea what and why i do this 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