factor/extra/golden-section/golden-section.factor

65 lines
1.6 KiB
Factor
Raw Normal View History

2008-01-24 18:18:12 -05:00
USING: kernel namespaces math math.constants math.functions arrays sequences
opengl opengl.gl opengl.glu ui ui.render ui.gadgets ui.gadgets.theme
ui.gadgets.slate colors ;
2007-09-20 18:09:08 -04:00
IN: golden-section
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! To run:
2008-01-24 18:18:12 -05:00
! "golden-section" run
2007-09-20 18:09:08 -04:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: disk ( quadric radius center -- )
2008-01-24 18:18:12 -05:00
glPushMatrix
gl-translate
dup 0 glScalef
0 1 10 10 gluDisk
glPopMatrix ;
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
: x ( i -- x ) dup omega cos * 0.5 * ;
: y ( i -- y ) dup omega sin * 0.5 * ;
: center ( i -- point ) dup x swap y 2array ;
: radius ( i -- radius ) pi * 720 / sin 10 * ;
: color ( i -- color ) 360.0 / dup 0.25 1 4array ;
: rim ( quadric i -- )
2008-01-24 18:18:12 -05:00
black gl-color dup radius 1.5 * swap center disk ;
2007-09-20 18:09:08 -04:00
: inner ( quadric i -- )
2008-01-24 18:18:12 -05:00
dup color gl-color dup radius swap center disk ;
2007-09-20 18:09:08 -04:00
: dot ( quadric i -- ) 2dup rim inner ;
2008-01-09 17:36:30 -05:00
: golden-section ( quadric -- ) 720 [ dot ] with each ;
2007-09-20 18:09:08 -04:00
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
: with-quadric ( quot -- )
2008-01-24 18:18:12 -05:00
gluNewQuadric [ swap call ] keep gluDeleteQuadric ; inline
2007-09-20 18:09:08 -04:00
: display ( -- )
2008-01-24 18:18:12 -05:00
GL_PROJECTION glMatrixMode
glLoadIdentity
-400 400 -400 400 -1 1 glOrtho
GL_MODELVIEW glMatrixMode
glLoadIdentity
[ golden-section ] with-quadric ;
2007-09-20 18:09:08 -04:00
: golden-section-window ( -- )
2008-01-24 18:18:12 -05:00
[
[ display ] <slate>
{ 600 600 } over set-slate-dim
"Golden Section" open-window
] with-ui ;
2007-09-20 18:09:08 -04:00
2008-01-24 18:18:12 -05:00
MAIN: golden-section-window