Paste: sine-gadget

Author: slava
Mode: factor
Date: Wed, 26 Nov 2008 23:41:26
Plain Text |
USING: accessors alien.c-types assocs colors kernel math
math.constants math.functions namespaces opengl opengl.gl
sequences ui.gadgets ui.render ;
IN: sine-gadget

TUPLE: sine-gadget < gadget points count ;

: compute-points ( -- seq )
    400 dup [ 400 / 2 * pi * sin 200 * 200 + ] map zip concat >c-float-array ;

: <sine-gadget> ( -- gadget )
    sine-gadget new-gadget
        400 >>count
        compute-points >>points ;

M: sine-gadget pref-dim* ( sine-gadget -- dim ) drop { 400 400 } ;

M: sine-gadget draw-gadget* ( sine-gadget -- )
    origin get [
        black gl-color
        [ points>> gl-vertex-pointer ]
        [ [ GL_LINE_STRIP 0 ] dip count>> glDrawArrays ] bi
    ] with-translation ;

New Annotation

Summary:
Author:
Mode:
Body: