2 USING: kernel alien.c-types combinators namespaces make arrays
4 math math.functions math.vectors math.trig
5 opengl.gl opengl.glu opengl ui ui.gadgets.slate
6 vars colors self self.slots
7 random-weighted colors.hsv cfdg.gl accessors
8 ui.gadgets.handler ui.gestures assocs ui.gadgets macros
9 specialized-arrays.double ;
15 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
19 : clear-color ( color -- ) gl-clear-color GL_COLOR_BUFFER_BIT glClear ;
21 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
24 ! base + base * adjustment
27 ! base + (1 - base) * adjustment
29 : adjust ( val num -- val ) dup 0 > [ 1 pick - * + ] [ dupd * + ] if ;
31 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
33 : hue ( num -- ) hue-> + 360 mod ->hue ;
35 : saturation ( num -- ) saturation-> swap adjust ->saturation ;
36 : brightness ( num -- ) value-> swap adjust ->value ;
37 : alpha ( num -- ) alpha-> swap adjust ->alpha ;
39 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
42 : sat ( num -- ) saturation ;
43 : b ( num -- ) brightness ;
44 : a ( num -- ) alpha ;
46 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
50 : init-color-stack ( -- ) V{ } clone >color-stack ;
52 : push-color ( -- ) self> color-stack> push self> clone >self ;
54 : pop-color ( -- ) color-stack> pop dup >self gl-color ;
56 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
58 ! : double-nth* ( c-array indices -- seq ) swap [ double-nth ] curry map ;
60 : double-nth* ( c-array indices -- seq )
61 swap byte-array>double-array [ nth ] curry map ;
63 : check-size ( modelview -- num ) { 0 1 4 5 } double-nth* [ abs ] map supremum ;
67 : iterate? ( -- ? ) get-modelview-matrix check-size threshold> > ;
69 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
78 : gl-flip ( angle -- ) deg>rad dup dup dup
79 [ 2 * cos , 2 * sin , 0 , 0 ,
80 2 * sin , 2 * cos neg , 0 , 0 ,
83 double-array{ } make underlying>> glMultMatrixd ;
85 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
89 gluNewQuadric dup 0 0.5 20 10 gluDisk gluDeleteQuadric ;
96 -0.5 -0.289 glVertex2d
108 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
110 : size ( scale -- ) dup 1 glScaled ;
112 : size* ( scale-x scale-y -- ) 1 glScaled ;
114 : rotate ( angle -- ) 0 0 1 glRotated ;
116 : x ( x -- ) 0 0 glTranslated ;
118 : y ( y -- ) 0 swap 0 glTranslated ;
120 : flip ( angle -- ) gl-flip ;
122 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
124 : s ( scale -- ) size ;
125 : s* ( scale-x scale-y -- ) size* ;
126 : r ( angle -- ) rotate ;
127 : f ( angle -- ) flip ;
129 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
132 push-modelview-matrix
138 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
140 : recursive ( quot -- ) iterate? swap when ; inline
142 : multi ( seq -- ) random-weighted* call ;
144 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
146 : [rules] ( seq -- quot )
147 [ unclip swap [ [ do ] curry ] map concat 2array ] map
148 [ call-random-weighted ] swap prefix
150 [ iterate? ] swap append ;
152 MACRO: rules ( seq -- quot ) [rules] ;
154 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
156 : [rule] ( seq -- quot )
157 [ [ do ] swap prefix ] map concat
159 [ iterate? ] prepend ;
161 MACRO: rule ( seq -- quot ) [rule] ;
163 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
167 : set-initial-background ( -- ) T{ hsva f 0 0 1 1 } clone >self ;
169 : set-background ( -- )
170 set-initial-background
174 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
176 USING: rewrite-closures ;
178 VAR: viewport ! { left width bottom height }
182 : set-initial-color ( -- ) T{ hsva f 0 0 0 1 } clone >self ;
184 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
188 ! : build-model-dlist ( -- )
189 ! 1 glGenLists dlist set
190 ! dlist get GL_COMPILE_AND_EXECUTE glNewList
194 : build-model-dlist ( -- )
195 1 glGenLists dlist set
196 dlist get GL_COMPILE_AND_EXECUTE glNewList
208 GL_PROJECTION glMatrixMode
210 viewport> first dup viewport> second +
211 viewport> third dup viewport> fourth + gluOrtho2D
213 GL_MODELVIEW glMatrixMode
218 GL_COLOR_BUFFER_BIT glClear
220 init-modelview-matrix-stack
224 [ build-model-dlist ]
225 [ dlist get glCallList ]
228 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
230 : delete-dlist ( -- ) dlist get [ dlist get 1 glDeleteLists dlist off ] when ;
232 : cfdg-window* ( -- slate )
235 C[ delete-dlist ] >>ungraft
236 dup "CFDG" open-window ;
238 : cfdg-window ( -- slate ) [ cfdg-window* ] with-ui ;
240 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
244 : rebuild ( -- ) delete-dlist the-slate get relayout-1 ;
246 : <cfdg-gadget> ( -- slate )
250 C[ dlist get [ dlist get 1 glDeleteLists ] when ] >>ungraft
253 T{ key-down f f "ENTER" } C[ drop rebuild ] swap pick set-at
254 T{ button-down } C[ drop rebuild ] swap pick set-at
257 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
261 : cfdg-window. ( quot -- )
262 '[ [ @ <cfdg-gadget> "CFDG" open-window ] with-scope ] with-ui ;