USING: accessors arrays colors colors.hsv kernel locals math math.constants math.functions math.vectors namespaces opengl.gl sequences ui ui.gadgets ui.gadgets.canvas ui.render ; IN: dragon ! http://rosettacode.org/wiki/Dragon_curve#BASIC SYMBOLS: point angle color ; CONSTANT: depth 18 ! 6 12 18 neat depths : next-color ( -- ) color get dup 1.0 1.0 1.0 >rgba-components glColor4d ! increment should be constant derived from depth 360 2 depth ^ / + color set ; : draw-fwd ( p -- ) ! draw a line btw point get and p point get GL_LINES glBegin [ first2 glVertex2d ] bi@ glEnd ; : fwd ( l -- ) [ angle get cos * ] [ angle get sin * ] bi 2array point get v+ dup draw-fwd point set ; : trn ( d -- ) pi * 180 / angle get + angle set ; :: dragon' ( l s d -- ) s zero? [ next-color 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 ( -- ) 0 0 angle set color set { 150 180 } point set 400 depth 1 dragon' ; TUPLE: dragon-canvas < canvas ; M: dragon-canvas draw-gadget* [ drop 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