factor/unmaintained/golden-section/golden-section.factor

55 lines
1.5 KiB
Factor
Raw Normal View History

2008-07-18 18:14:23 -04:00
2008-07-28 01:49:34 -04:00
USING: kernel namespaces math math.constants math.functions math.order
arrays sequences
2008-07-18 18:14:23 -04:00
opengl opengl.gl opengl.glu ui ui.render ui.gadgets ui.gadgets.theme
2008-07-29 22:16:34 -04:00
ui.gadgets.cartesian colors accessors combinators.cleave
2008-07-28 01:49:34 -04:00
processing.shapes ;
2008-07-18 18:14:23 -04:00
2007-09-20 18:09:08 -04:00
IN: golden-section
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2008-07-18 18:14:23 -04:00
! omega(i) = 2*pi*i*(phi-1)
! x(i) = 0.5*i*cos(omega(i))
! y(i) = 0.5*i*sin(omega(i))
! radius(i) = 10*sin((pi*i)/720)
2007-09-20 18:09:08 -04:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2008-01-24 18:18:12 -05:00
: omega ( i -- omega ) phi 1- * 2 * pi * ;
2007-09-20 18:09:08 -04:00
2008-07-18 18:14:23 -04:00
: x ( i -- x ) [ omega cos ] [ 0.5 * ] bi * ;
: y ( i -- y ) [ omega sin ] [ 0.5 * ] bi * ;
2007-09-20 18:09:08 -04:00
2008-07-18 18:14:23 -04:00
: center ( i -- point ) { x y } 1arr ;
2007-09-20 18:09:08 -04:00
: radius ( i -- radius ) pi * 720 / sin 10 * ;
2008-07-28 15:59:29 -04:00
: color ( i -- i ) dup 360.0 / dup 0.25 1 rgba boa >fill-color ;
2008-07-28 01:49:34 -04:00
: line-width ( i -- i ) dup radius 0.5 * 1 max glLineWidth ;
2007-09-20 18:09:08 -04:00
2008-07-28 01:49:34 -04:00
: draw ( i -- ) [ center ] [ radius 1.5 * 2 * ] bi circle ;
2007-09-20 18:09:08 -04:00
2008-07-28 01:49:34 -04:00
: dot ( i -- ) color line-width draw ;
2007-09-20 18:09:08 -04:00
2008-07-18 18:14:23 -04:00
: golden-section ( -- ) 720 [ dot ] each ;
2007-09-20 18:09:08 -04:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2008-08-01 15:24:00 -04:00
: <golden-section> ( -- gadget )
<cartesian>
{ 600 600 } >>pdim
{ -400 400 } x-range
{ -400 400 } y-range
[ golden-section ] >>action ;
2007-09-20 18:09:08 -04:00
: golden-section-window ( -- )
2008-08-01 15:24:00 -04:00
[ <golden-section> "Golden Section" open-window ] with-ui ;
2007-09-20 18:09:08 -04:00
2008-07-29 22:16:34 -04:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2008-01-24 18:18:12 -05:00
MAIN: golden-section-window