-------------------- detach-parent ; builds and animates a random heirarchical structure, ; click on the objects to detach them from their parents (define (build-heir depth) (with-state (let ((p (with-state (translate (vector 2 0 0)) (scale 0.9) (build-cube)))) (when (> depth 0) (parent p) (for ((i (in-range 0 5))) (when (zero? (random 3)) (rotate (vector 0 0 (* 45 (crndf)))) (build-heir (- depth 1)))))))) (define (animate-heir children depth) (for-each (lambda (child) (with-primitive child (rotate (vector 0 0 (sin (+ depth (time))))) (animate-heir (get-children) (+ depth 1)))) children)) (define (animate) (animate-heir (get-children) 0) (when (mouse-button 1) (let ((s (select (mouse-x) (mouse-y) 2))) (when (not (zero? s)) (with-primitive s (detach-parent)))))) (clear) (build-heir 5) (every-frame (animate)) -------------------- with-state ; state hierachy, by nesting with-state: (with-state (hint-vertcols) (colour (vector 0 0 1)) (with-state (translate (vector 1 0 0)) (build-sphere 10 10)) (build-torus 1 2 30 30)) ; making primitives: (define my-torus (with-state (hint-vertcols) (colour (vector 0 0 1)) (build-torus 1 2 30 30))) -------------------- with-primitive (define my-torus (with-state (colour (vector 0 0 1)) (build-torus 1 2 30 30))) ; change the torus colour: (with-primitive my-torus (colour (vector 0 1 0))) -------------------- with-pixels-renderer -------------------- pdata-map! (clear) (define my-torus (build-torus 1 2 30 30)) (with-primitive my-torus (pdata-map! (lambda (position) (vadd position (vector (flxrnd) 0 0))) ; jitter the vertex in x "p")) ; read/write the position pdata array (with-primitive my-torus (pdata-map! (lambda (position normal) (vadd position normal)) ; add the normal to the position (expand the object) "p" "n")) ; read/write the position pdata array, read the normals array -------------------- pdata-index-map! (clear) (define my-torus (build-torus 1 2 30 30)) (with-primitive my-torus (pdata-index-map! (lambda (index position) (vadd position (vector (gh index) 0 0))) ; jitter the vertex in x "p")) ; read/write the position pdata array -------------------- pdata-fold (define my-torus (build-torus 1 2 30 30)) ; find the centre of the primitive by averaging ; the points position's together (let ((centre (with-primitive my-torus (vdiv (pdata-fold vadd (vector 0 0 0) "p") (pdata-size))))) (display centre)(newline)) -------------------- pdata-index-fold (define my-torus (build-torus 1 2 30 30)) ; can't think of a good example for this yet... (let ((something (with-primitive my-torus (vdiv (pdata-index-fold (lambda (index position ret) (vadd ret (vmul position index))) (vector 0 0 0) "p") (pdata-size))))) (display something)(newline)) -------------------- collada-import ;(collada-import "test.dae") -------------------- vmix ; mix red and blue together (colour (vmix (vector 1 0 0) (vector 0 0 1) 0.5)) -------------------- vclamp ; make a valid colour from any old vector (colour (vclamp (vector 2 400 -123))) -------------------- vsquash ; make a valid colour from any old vector (colour (vclamp (vector 2 400 -123))) -------------------- pixels-circle (with-primitive (build-pixels 100 100) (pixels-circle (vector 50 50 0) 30 (vector 1 0 0 1)) (pixels-upload)) -------------------- pixels-blend-circle (with-primitive (build-pixels 100 100) (pixels-blend-circle (vector 50 50 0) 30 (vector 1 0 0 1)) (pixels-upload)) -------------------- pixels-dodge (with-primitive (build-pixels 100 100) (pixels-dodge (vector 50 50 0) 30 (vector 1 0 0 1)) (pixels-upload)) -------------------- pixels-burn (with-primitive (build-pixels 100 100) (pixels-burn (vector 50 50 0) 30 (vector 1 0 0 1)) (pixels-upload)) -------------------- pixels-clear (with-primitive (build-pixels 100 100) (pixels-clear (vector 1 0 0)) (pixels-upload)) -------------------- poly-type (define p (build-polygons 3 'triangle-strip)) (with-primitive p (display (poly-type))(newline)) -------------------- pdata-for-each-face -------------------- pdata-for-each-triangle -------------------- pdata-for-each-tri-sample -------------------- build-extrusion (clear) (build-extrusion (build-circle-profile 20 0.3) (list (vector 0 0 0) (vector 0 1 2) (vector 0 -1 4) (vector 0 0 6)) (list 0 1 1 0) 1 (vector 0 1 0)) -------------------- build-partial-extrusion (clear) (define profile (build-circle-profile 10 0.3)) (define path (build-list 20 (lambda (i) (vector (crndf) (crndf) i)))) (define width (build-list 20 (lambda (_) 1))) (hint-wire) (define p (build-partial-extrusion profile path 1)) (every-frame (with-primitive p (partial-extrude (* (length path) 0.5 (+ (sin (time)) 1)) profile path width (vector 0 1 0) 0.1))) -------------------- partial-extrude (clear) (define profile (build-circle-profile 10 0.3)) (define path (build-list 20 (lambda (i) (vector (crndf) (crndf) i)))) (define width (build-list 20 (lambda (_) 1))) (hint-wire) (define p (build-partial-extrusion profile path 100)) (every-frame (with-primitive p (partial-extrude (* (length path) 0.5 (+ (sin (time)) 1)) profile path width (vector 0 1 0) 0.1))) -------------------- build-circle-profile (clear) (build-extrusion (build-circle-profile 20 0.3) (list (vector 0 0 0) (vector 0 1 2) (vector 0 -1 4) (vector 0 0 6)) (list 0 1 1 0) 1 (vector 0 1 0)) -------------------- rndf (display (rndf))(newline) -------------------- crndf (display (crndf))(newline) -------------------- rndvec (clear) (hint-none) (hint-points) (point-width 4) (define p (build-particles 1000)) (show-axis 1) (with-primitive p (pdata-map! (lambda (p) (vector 1 1 1)) "c") (pdata-map! (lambda (p) (rndvec)) "p")) -------------------- crndvec (clear) (hint-none) (hint-points) (point-width 4) (define p (build-particles 1000)) (show-axis 1) (with-primitive p (pdata-map! (lambda (p) (vector 1 1 1)) "c") (pdata-map! (lambda (p) (crndvec)) "p")) -------------------- srndvec (clear) (hint-none) (hint-points) (point-width 4) (define p (build-particles 1000)) (show-axis 1) (with-primitive p (pdata-map! (lambda (p) (vector 1 1 1)) "c") (pdata-map! (lambda (p) (srndvec)) "p")) -------------------- hsrndvec (clear) (hint-none) (hint-points) (point-width 4) (define p (build-particles 1000)) (show-axis 1) (with-primitive p (pdata-map! (lambda (p) (vector 1 1 1)) "c") (pdata-map! (lambda (p) (hsrndvec)) "p")) -------------------- grndf (display (grndf))(newline) -------------------- grndvec (clear) (hint-none) (hint-points) (point-width 4) (define p (build-particles 1000)) (show-axis 1) (with-primitive p (pdata-map! (lambda (p) (vector 1 1 1)) "c") (pdata-map! (lambda (p) (grndvec)) "p")) -------------------- rndbary (rndbary) -------------------- rndbary (clear) (hint-none) (hint-points) (point-width 4) (define p (build-particles 1000)) (show-axis 1) (with-primitive p (pdata-map! (lambda (p) (vector 1 1 1)) "c") (pdata-map! (lambda (p) (rndhemi (vector 0 1 0))) "p")) -------------------- hrndbary (clear) (hint-none) (hint-points) (point-width 4) (define p (build-particles 1000)) (show-axis 1) (with-primitive p (pdata-map! (lambda (p) (vector 1 1 1)) "c") (pdata-map! (lambda (p) (hrndhemi (vector 0 1 0))) "p")) -------------------- pdata-for-each-tri-sample -------------------- pdata-for-each-tri-sample -------------------- occlusion-texture-bake -------------------- oa-start (oa-start) (define mysample (oa-load-sample (fullpath "sample.wav"))) (oa-play mysample (vector 0 0 0) 1 0.2) -------------------- oa-load-sample (oa-start) (define mysample (oa-load-sample "sample.wav")) (oa-play mysample (vector 0 0 0) 1 0.2) -------------------- oa-update (oa-update) -------------------- oa-play (oa-start) (define mysample (oa-load-sample (fullpath "sample.wav"))) (oa-play mysample (vector 0 0 0) 1 0.2) -------------------- oa-set-head-pos (oa-start) (define mysample (oa-load-sample (fullpath "sample.wav"))) (oa-set-head-pos (vector -1 0 0) (vector 0 0 1)) (oa-play mysample (vector 0 0 0) 1 0.2) -------------------- oa-set-poly (oa-set-poly 256) -------------------- oa-set-cull-dist (oa-set-cull-dist 1000) -------------------- oa-set-acoustics (oa-set-acoustics 1 1 1 1) -------------------- time (define (animate) (rotate (vector (sin (time)) 0 0)) (draw-cube)) (every-frame (animate)) -------------------- delta (define (animate) (rotate (vector (* (delta) 10) 0 0)) (draw-cube)) (every-frame (animate)) -------------------- flxrnd (define (animate) (colour (vector (flxrnd) (flxrnd) (flxrnd))) (draw-cube)) (every-frame (animate)) -------------------- flxseed (define (animate) (colour (vector (flxrnd) (flxrnd) (flxrnd))) (draw-cube)) (flxseed 10) (every-frame (animate)) ; the same sequence of colours will be generated -------------------- set-searchpathss (set-searchpaths (append (get-searchpaths) (list "/path/to/my/textures/" "/path/to/my/other/textures/"))) -------------------- get-searchpaths (display (get-searchpaths))(newline) -------------------- fullpath (fullpath "myfile") -------------------- framedump (framedump "picture.jpg") -------------------- tiled-framedump (tiled-framedump "picture.jpg" 3000 2000) -------------------- build-cube (define mynewcube (build-cube)) -------------------- build-polygons (define mynewshape (build-polygons 100 'triangle-strip)) -------------------- build-sphere (define mynewshape (build-sphere 10 10)) -------------------- build-torus (define mynewshape (build-torus 0.5 1 12 12)) -------------------- build-plane (define mynewshape (build-plane)) -------------------- build-seg-plane (define mynewshape (build-plane)) -------------------- build-cylinder (define mynewshape (build-cylinder 10 10)) -------------------- build-ribbon (define mynewshape (build-ribbon 10)) -------------------- build-text (texture (load-texture "font.png")) (define mynewshape (build-text "hello")) -------------------- build-type (clear) (wire-colour (vector 0 0 1)) ; this font should be on the default fluxus path (as it's the editor font) (define t (build-type "Bitstream-Vera-Sans-Mono.ttf" "fluxus rocks!!")) ; make a poly primitive from the type (define p (with-state (translate (vector 0 4 0)) (type->poly t))) ; set some texture coords on the poly prim and load a texture onto it (with-primitive p (pdata-map! (lambda (t p) (vmul p 0.5)) "t" "p") (texture (load-texture "refmap.png"))) -------------------- build-extruded-type (clear) (wire-colour (vector 0 0 1)) ; this font should be on the default fluxus path (as it's the editor font) (define t (build-extruded-type "Bitstream-Vera-Sans-Mono.ttf" "fluxus rocks!!" 1)) ; make a poly primitive from the type (define p (with-state (translate (vector 0 4 0)) (type->poly t))) ; set some texture coords on the poly prim and load a texture onto it (with-primitive p (pdata-map! (lambda (t p) (vmul p 0.5)) "t" "p") (texture (load-texture "refmap.png"))) -------------------- type->poly (clear) (wire-colour (vector 0 0 1)) ; this font should be on the default fluxus path (as it's the editor font) (define t (build-extruded-type "Bitstream-Vera-Sans-Mono.ttf" "fluxus rocks!!" 1)) ; make a poly primitive from the type (define p (with-state (translate (vector 0 4 0)) (type->poly t))) ; set some texture coords on the poly prim and load a texture onto it (with-primitive p (pdata-map! (lambda (t p) (vmul p 0.5)) "t" "p") (texture (load-texture "refmap.png"))) -------------------- text-params ; don't use me! -------------------- build-nurbs-sphere (define mynewshape (build-nurbs-sphere 10 10)) -------------------- build-nurbs-plane (define mynewshape (build-nurbs-plane 10 10)) -------------------- build-particles (define mynewshape (build-particles 100)) -------------------- build-image (define img (build-image (load-texture "test.png") (vector 0 0) (get-screen-size))) -------------------- build-locator (define mynewshape (build-locator)) -------------------- locator-bounding-radius (define mylocator (build-locator)) (with-primitive mylocator (locator-bounding-radius 23.4)) -------------------- load-primitive (define mynewshape (load-primitive "octopus.obj")) -------------------- clear-geometry-cache (clear-geometry-cache) -------------------- save-primitive (with-primitive (build-sphere 10 10) (save-primitive "mymesh.obj")) -------------------- build-pixels (clear) (define p1 (build-pixels 16 16)) (with-primitive p1 (pdata-map! (lambda (c) (rndvec)) "c") (pixels-upload)) ; call pixels upload to see the results (translate (vector 1.5 0 0)) (define p2 (build-pixels 256 256 #t)) ; render target (with-pixels-renderer p2 ; render a cube into the pixels primitive (clear-colour (vector .37 .5 .59)) (scale 5) (rotate (vector -5 60 140)) (build-cube)) -------------------- pixels-upload (define mynewshape (build-pixels 100 100)) (with-primitive mynewshape (pdata-map! (lambda (c) (rndvec)) "c") (pixels-upload)) ; call pixels upload to see the results -------------------- pixels-download -------------------- pixels->texture (define mypixels (build-pixels 100 100)) (with-primitive mypixels (pdata-map! (lambda (c) (rndvec)) "c") (pixels-upload)) (with-state (texture (pixels->texture mypixels)) (build-torus 1 2 10 10)) -------------------- pixels-width (define mynewshape (build-pixels 100 100)) (with-primitive mynewshape (display (vector (pixels-width) (pixels-height)))(newline)) -------------------- pixels-height (define mynewshape (build-pixels 100 100)) (with-primitive mynewshape (display (vector (pixels-width) (pixels-height)))(newline)) -------------------- pixels-renderer-activate (clear) (define p (build-pixels 256 256)) (with-primitive p (pixels-renderer-activate #t)) (define cube (with-pixels-renderer p (clear-colour (vector .2 .4 .8)) (rotate #(30 50 80)) (scale 5) (build-cube))) -------------------- build-blobby (clear) (define b (build-blobby 5 (vector 30 30 30) (vector 1 1 1))) (with-primitive b (shinyness 100) (specular (vector 1 1 1)) (hint-vertcols) (pdata-set "p" 0 (vector 0.75 0.25 0.5)) (pdata-set "c" 0 (vector 0.01 0 0)) (pdata-set "s" 0 0.01) (pdata-set "p" 1 (vector 0.25 0.75 0.5)) (pdata-set "c" 1 (vector 0 0.01 0)) (pdata-set "s" 1 0.01) (pdata-set "p" 2 (vector 0.75 0.75 0.5)) (pdata-set "c" 2 (vector 0 0 0.01)) (pdata-set "s" 2 0.01) (pdata-set "p" 3 (vector 0.25 0.25 0.5)) (pdata-set "c" 3 (vector 0.01 0.01 0)) (pdata-set "s" 3 0.01) (pdata-set "p" 4 (vector 0.5 0.5 0.5)) (pdata-set "c" 4 (vector 0.01 0.01 0.01)) (pdata-set "s" 4 0.025)) -------------------- blobby->poly (clear) (define b (build-blobby 5 (vector 30 30 30) (vector 1 1 1))) (with-primitive b (shinyness 100) (specular (vector 1 1 1)) (hint-vertcols) (pdata-set "p" 0 (vector 0.75 0.25 0.5)) (pdata-set "c" 0 (vector 0.01 0 0)) (pdata-set "s" 0 0.01) (pdata-set "p" 1 (vector 0.25 0.75 0.5)) (pdata-set "c" 1 (vector 0 0.01 0)) (pdata-set "s" 1 0.01) (pdata-set "p" 2 (vector 0.75 0.75 0.5)) (pdata-set "c" 2 (vector 0 0 0.01)) (pdata-set "s" 2 0.01) (pdata-set "p" 3 (vector 0.25 0.25 0.5)) (pdata-set "c" 3 (vector 0.01 0.01 0)) (pdata-set "s" 3 0.01) (pdata-set "p" 4 (vector 0.5 0.5 0.5)) (pdata-set "c" 4 (vector 0.01 0.01 0.01)) (pdata-set "s" 4 0.025)) (define p (with-state (translate (vector 1 0 0)) (blobby->poly b))) -------------------- draw-instance (define mynewshape (build-cube)) (colour (vector 1 0 0)) (draw-instance mynewshape) ; draws a copy of mynewshape -------------------- draw-cube (define (render) (draw-cube)) (every-frame (render)) -------------------- draw-plane (define (render) (draw-plane)) (every-frame (render)) -------------------- draw-sphere (define (render) (draw-sphere)) (every-frame (render)) -------------------- draw-cylinder (define (render) (draw-cylinder)) (every-frame (render)) -------------------- draw-torus (define (render) (draw-torus)) (every-frame (render)) -------------------- destroy (define mynewshape (build-sphere 10 10)) (destroy mynewshape) -------------------- poly-indices (define p (build-cube)) (with-primitive p (poly-convert-to-indexed) (display (poly-indices))(newline)) -------------------- poly-type-enum (define (poly-type) (let ((t (poly-type-enum))) (cond ((eq? t 0) 'triangle-strip) ((eq? t 1) 'quad-list) ((eq? t 2) 'triangle-list) ((eq? t 3) 'triangle-fan) ((eq? t 4) 'polygon)))) -------------------- poly-indexed? (define p (build-polygons 3 'triangle-strip)) (with-primitive p (poly-convert-to-indexed) (display (poly-indexed?))(newline)) -------------------- poly-set-index (clear) ; lets build our own cube primitive... (define p (build-polygons 8 'quad-list)) (with-primitive p ; setup the vertex data (pdata-set "p" 0 (vector -1 -1 -1)) (pdata-set "p" 1 (vector 1 -1 -1)) (pdata-set "p" 2 (vector 1 -1 1)) (pdata-set "p" 3 (vector -1 -1 1)) (pdata-set "p" 4 (vector -1 1 -1)) (pdata-set "p" 5 (vector 1 1 -1)) (pdata-set "p" 6 (vector 1 1 1)) (pdata-set "p" 7 (vector -1 1 1)) (pdata-set "c" 0 (vector 0 0 0)) (pdata-set "c" 1 (vector 0 0 1)) (pdata-set "c" 2 (vector 0 1 0)) (pdata-set "c" 3 (vector 0 1 1)) (pdata-set "c" 4 (vector 1 0 0)) (pdata-set "c" 5 (vector 1 0 1)) (pdata-set "c" 6 (vector 1 1 0)) (pdata-set "c" 7 (vector 1 1 1)) (hint-wire) (hint-unlit) (hint-vertcols) ; connect the verts together into faces (poly-set-index (list 7 6 5 4 5 6 2 1 4 5 1 0 1 2 3 0 3 7 4 0 6 7 3 2))) -------------------- poly-convert-to-indexed (define mynewshape (build-sphere 10 10)) (grab mynewshape) (poly-convert-to-indexed) (ungrab) -------------------- build-copy (define mynewshape (build-sphere 10 10)) (define myothernewshape (build-copy mynewshape)) -------------------- make-pfunc (define mypfunc (make-pfunc 'arithmetic)) -------------------- pfunc-set! (define mypfunc (make-pfunc 'arithmetic)) (pfunc-set! mypfunc (list 'operator "add" 'src "p" 'const 0.4 'dst "p")) -------------------- pfunc-run (define mypfunc (make-pfunc 'arithmetic)) -------------------- geo/line-intersect (clear) (define s (with-state (build-torus 1 2 10 10))) (define l (with-state (hint-none) (hint-unlit) (hint-wire) (build-line 2))) (define (check a b) (with-primitive s (for-each (lambda (intersection) (with-state ; draw a sphere at the intersection point (translate (cdr (assoc "p" intersection))) (colour (vector 0 1 0)) (scale (vector 0.3 0.3 0.3)) (draw-sphere))) (geo/line-intersect a b)))) (every-frame (with-primitive l (pdata-set "p" 0 (vector 0 -5 0)) (pdata-set "p" 1 (vector (* 5 (sin (time))) 5 0)) (check (pdata-ref "p" 0) (pdata-ref "p" 1)))) -------------------- recalc-bb -------------------- bb/bb-intersect? (clear) (define a (with-state (build-sphere 10 10))) (define b (with-state (translate (vector 2 0 0)) (build-sphere 10 10))) (every-frame (begin (with-primitive b (translate (vector (* -0.1 (sin (time))) 0 0))) (with-primitive a (when (bb/bb-intersect? b 0) (colour (rndvec)))))) -------------------- bb/point-intersect? (clear) (define a (with-state (build-sphere 10 10))) (define b (with-state (translate (vector 2 0 0)) (build-sphere 10 10))) (every-frame (begin (with-primitive b (translate (vector (* -0.1 (sin (time))) 0 0)) (recalc-bb)) (with-primitive a ; check the centre point and give the radius, this sphere ; check is faster than a bb/bb one (when (bb/point-intersect? (vtransform (vector 0 0 0) (with-primitive b (get-transform))) 1) (colour (rndvec)))))) -------------------- get-children ; build a random heirachical structure (define (build-heir depth) (with-state (let ((p (with-state (translate (vector 2 0 0)) (scale 0.9) (build-cube)))) (when (> depth 0) (parent p) (for ((i (in-range 0 5))) (when (zero? (random 3)) (rotate (vector 0 0 (* 45 (crndf)))) (build-heir (- depth 1)))))))) ; navigate the scene graph and print it out (define (print-heir children) (for-each (lambda (child) (with-primitive child (printf "id: ~a parent: ~a children: ~a~n" child (get-parent) (get-children)) (print-heir (get-children)))) children)) (clear) (build-heir 5) (print-heir (get-children)) -------------------- get-parent ; build a random heirachical structure (define (build-heir depth) (with-state (let ((p (with-state (translate (vector 2 0 0)) (scale 0.9) (build-cube)))) (when (> depth 0) (parent p) (for ((i (in-range 0 5))) (when (zero? (random 3)) (rotate (vector 0 0 (* 45 (crndf)))) (build-heir (- depth 1)))))))) ; navigate the scene graph and print it out (define (print-heir children) (for-each (lambda (child) (with-primitive child (printf "id: ~a parent: ~a children: ~a~n" child (get-parent) (get-children)) (print-heir (get-children)))) children)) (clear) (build-heir 5) (print-heir (get-children)) -------------------- pdata-ref (pdata-ref "p" 1) -------------------- pdata-set! (pdata-set! "p" 1 (vector 0 100 0)) -------------------- pdata-add (pdata-add "mydata" "v") (pdata-set "mydata" 0 (vector 1 2 3)) -------------------- pdata-op (clear) (define t (build-torus 1 4 10 10)) (with-primitive t (pdata-op "+" "p" (vector 1 0 0)) ; add a vector to all the pdata vectors (pdata-op "+" "p" "n") ; add two pdata vectors element for element (pdata-op "*" "n" (vector -1 -1 -1)) ; multiply a vector to all the pdata vectors (pdata-op "*" "n" "p") ; multiply two pdata vectors element for element (let ((pos (pdata-op "closest" "p" (vector 100 0 0)))) ; returns position of the closest vertex to this point (with-state ; draw a sphere there (translate pos) (scale (vector 0.1 0.1 0.1)) (build-sphere 5 5))) ; can't think of a good example for these... ;(pdata-op "sin" "mydata" "myotherdata") ; sine of one float pdata to another ;(pdata-op "cos" "mydata" "myotherdata") ; cosine of one float pdata to another ) ; most common example of pdata op is for particles (define p (with-state (hint-points) (point-width 10) (build-particles 100))) (with-primitive p (pdata-add "vel" "v") ; add a velocity vector (pdata-map! (lambda (vel) (srndvec)) ; set random velocities "vel") (pdata-map! (lambda (c) (rndvec)) ; set random colours "c")) (every-frame (with-primitive p (pdata-op "+" "p" "vel"))) -------------------- pdata-copy (pdata-copy "p" "mydata") ; copy the vertex positions to a user array -------------------- pdata-size (define (mashup n) (pdata-set "p" n (vector (flxrnd) (flxrnd) (flxrnd))) ; randomise the vertex position (if (zero? n) 0 (mashup (- n 1)))) ; loops till n is 0 (define shape (build-sphere 10 10)) (grab shape) (mashup (pdata-size)) ; randomise verts on currently grabbed primitive (ungrab) -------------------- recalc-normals (define shape (build-sphere 10 10)) ; build a sphere (which is smooth by default) (grab shape) (recalc-normals 0) ; make the sphere faceted (ungrab) -------------------- push (colour (vector 1 0 0)) ; set current colour to red (push) ; copy and push drawing state (colour (vector 0 1 0)) ; set current colour to green (draw-cube) ; draws a green cube (pop) ; forget old drawing state ; current colour is now red again -------------------- pop (colour (vector 1 0 0)) ; set current colour to red (push) ; copy and push drawing state (colour (vector 0 1 0)) ; set current colour to green (draw-cube) ; draws a green cube (pop) ; forget old drawing state ; current colour is now red again -------------------- grab (colour (vector 1 0 0)) ; set the current colour to red (define mycube (build-cube)) ; makes a red cube (grab mycube) (colour (vector 0 1 0)) ; sets the cubes colour to green (ungrab) ; return to normal state -------------------- ungrab (colour (vector 1 0 0)) ; set the current colour to red (define mycube (build-cube)) ; makes a red cube (grab mycube) (colour (vector 0 1 0)) ; sets the cubes colour to green (ungrab) ; return to normal state -------------------- apply-transform (rotate (vector 45 0 0)) (define mycube (build-cube)) ; makes a cube with a rotation (with-primitive mycube (apply-transform)) ; applies the rotation to the points of the cube -------------------- opacity (opacity 0.5) (define mycube (build-cube)) ; makes a half transparent cube -------------------- wire-opacity (hint-none) (hint-wire) (backfacecull 0) (line-width 5) (wire-colour (vector 1 1 1)) (wire-opacity 0.5) (build-cube) ; makes a half transparent wireframe cube -------------------- shinyness (shinyness 100) (specular (vector 1 1 1)) ; sets the specular colour (define mysphere (build-sphere 10 10)) ; makes a shiny cube -------------------- colour (colour (vector 1 0.5 0.1)) ; mmm orange... (define mycube (build-cube)) ; makes an orange cube -------------------- colour-mode (clear) (colour-mode 'hsv) (for ((x (in-range 0 10))) (translate (vector 1 0 0)) (colour (vector (/ x 10) 1 1)) (build-cube)) -------------------- rgb->hsv (rgb->hsv (vector 1 0.5 0.1)) -------------------- hsv->rgb (clear) (for* ((x (in-range 0 10)) ; builds a 10x10 HSV colour pattern (y (in-range 0 10))) (identity) (translate (vector x y 0)) (colour (hsv->rgb (vector (/ x 10) (/ y 10) 1))) (build-cube)) -------------------- wire-colour (wire-colour (vector 1 1 0)) ; set yellow as current wire colour (hint-wire) (define mycube (build-cube)) ; makes a cube with yellow wireframe -------------------- specular (specular (vector 0 0 1)) ; set blue as specular colour (define mysphere (build-sphere 10 10)) ; makes a shiny blue sphere -------------------- ambient (ambient (vector 0 0 1)) ; set blue as ambient colour (define mysphere (build-sphere 10 10)) ; makes a boringly blue sphere -------------------- opacity (emissive (vector 0 0 1)) ; set blue as emissive colour (define mysphere (build-sphere 10 10)) ; makes an bright blue sphere -------------------- identity (define mycube (with-state (scale (vector 2 2 2)) ; set the current scale to double in each dimension (build-cube))) ; make a scaled cube (with-primitive mycube (identity)) ; erases the transform and puts the cube back to its original state -------------------- concat (define mymatrix (mrotate (vector 0 45 0))) ; make a matrix (concat mymatrix) ; concat it into the current state (build-cube) ; make a cube with this rotation -------------------- translate (translate (vector 0 1.4 0)) ; translates the current transform up a bit (build-cube) ; build a cube with this transform -------------------- rotate (rotate (vector 0 45 0)) ; turns 45 degrees in the Y axis (build-cube) ; build a cube with this transform -------------------- scale (scale (vector 0.5 0.5 0.5)) ; scales the current transform to half the size (build-cube) ; build a cube with this transform -------------------- get-transform (clear) ; build a hierarchy (define a (with-state (colour (vector 1 0.5 0.5)) (build-cube))) (define b (with-state (colour (vector 0.5 1 0.5)) (parent a) (translate (vector 2 0 0)) (build-cube))) (define c (with-state (colour (vector 0.5 0.5 1)) (parent b) (translate (vector 2 0 0)) (build-cube))) (define (animate) ; animate the heirarchy (with-primitive a (rotate (vector 0 0 (sin (time))))) (with-primitive b (rotate (vector 0 0 (sin (time))))) (with-primitive c (rotate (vector 0 0 (sin (time))))) ; position a yellow sphere with c's local transform (with-state (concat (with-primitive c (get-transform))) (opacity 0.5) (colour (vector 1 1 0)) (draw-sphere)) ; position a purple sphere with c's global transform (with-state (concat (with-primitive c (get-global-transform))) (opacity 0.5) (colour (vector 1 0 1)) (draw-sphere))) (every-frame (animate)) -------------------- get-global-transform (clear) ; build a hierarchy (define a (with-state (colour (vector 1 0.5 0.5)) (build-cube))) (define b (with-state (colour (vector 0.5 1 0.5)) (parent a) (translate (vector 2 0 0)) (build-cube))) (define c (with-state (colour (vector 0.5 0.5 1)) (parent b) (translate (vector 2 0 0)) (build-cube))) (define (animate) ; animate the heirarchy (with-primitive a (rotate (vector 0 0 (sin (time))))) (with-primitive b (rotate (vector 0 0 (sin (time))))) (with-primitive c (rotate (vector 0 0 (sin (time))))) ; position a yellow sphere with c's local transform (with-state (concat (with-primitive c (get-transform))) (opacity 0.5) (colour (vector 1 1 0)) (draw-sphere)) ; position a purple sphere with c's global transform (with-state (concat (with-primitive c (get-global-transform))) (opacity 0.5) (colour (vector 1 0 1)) (draw-sphere))) (every-frame (animate)) -------------------- parent (define parent-prim (build-cube)) ; make a parent cube (translate (vector 2 0 0)) ; move a bit in x (parent parent-prim) ; set parent-prim as the current parent (define child-prim (build-cube)) ; make a child cube (grab parent-prim) (rotate (vector 0 45 0)) ; the child will now be moved by this transform in addition to its own (ungrab) -------------------- line-width (line-width 5) (hint-wire) (build-sphere 10 10) ; make a sphere with thick wireframe -------------------- point-width (point-width 5) (hint-points) (build-sphere 10 10) ; make a sphere with thick points -------------------- blend-mode ; list out all the possible blendmodes (define src-blend (vector 'zero 'one 'dst-color 'one-minus-dst-color 'src-alpha 'one-minus-src-alpha 'dst-alpha 'one-minus-dst-alpha 'src-alpha-saturate)) (define dst-blend (vector 'zero 'one 'dst-color 'one-minus-dst-color 'src-alpha 'one-minus-src-alpha 'dst-alpha 'one-minus-dst-alpha)) ; picks a random element (define (pick-rnd-item l) (vector-ref l (random (vector-length l)))) ; make lots of random spheres (define (rnd-sphere n) (push) (hint-depth-sort) (opacity 0.5) (colour (vector (flxrnd) (flxrnd) (flxrnd))) ; set a random blendmode (blend-mode (pick-rnd-item src-blend) (pick-rnd-item dst-blend)) (translate (vector (flxrnd) (flxrnd) (flxrnd))) (scale (vector 0.1 0.1 0.1)) (build-sphere 10 10) (pop) (if (zero? n) 0 (rnd-sphere (- n 1)))) (clear) (clear-colour (vector 0.5 0.5 0.5)) (rnd-sphere 100) -------------------- hint-solid (hint-solid) ; this is the default render style so this isn't too exciting (build-cube) ; make a solid rendered cube -------------------- hint-wire (hint-wire) (build-cube) ; make a wirefame rendered cube -------------------- hint-wire-stippled (hint-none) (hint-wire-stippled) (build-cube) ; make a stippled wirefame cube -------------------- hint-frustum-cull (hint-frustum-cull) -------------------- hint-normalize (clear) (hint-normalize) (build-cube) ; non uniform scaling (with-primitive (build-cube) (translate #(.5 0 0)) (scale #(3 1 1)) (translate #(.5 0 0))) ; uniform scaling (with-primitive (build-cube) (translate #(0 0 2)) (scale 2)) -------------------- line-pattern (hint-none) (hint-wire-stippled) (line-pattern 4 #x0aaaa) (build-cube) ; make a stippled wirefame cube -------------------- hint-normal (hint-normal) (build-cube) ; display the normals on this cube -------------------- hint-points (hint-points) (build-cube) ; display the vertex points on this cube -------------------- hint-anti-alias (hint-anti-alias) (build-cube) ; display a smoothed cube -------------------- hint-unlit (hint-unlit) (build-cube) ; display an unlit cube -------------------- hint-vertcols (clear) (hint-vertcols) (define mycube (build-cube)) ; make a cube with vertcols enabled (with-primitive mycube (pdata-map! (lambda (c) (rndvec)) ; randomise the vertcols "c")) -------------------- hint-box (hint-box) (build-sphere 10 10) ; make a sphere with bounding box displayed -------------------- hint-none (hint-none) (hint-wire) (build-cube) ; make a cube only visible with wireframe -------------------- hint-origin (hint-origin) (build-sphere 10 10) ; make a sphere with the origin displayed -------------------- hint-cast-shadow (hint-origin) (build-sphere 10 10) ; make a sphere with the origin displayed -------------------- hint-depth-sort (hint-depth-sort) (build-sphere 10 10) -------------------- hint-ignore-depth (clear) (with-state (hint-ignore-depth) (opacity 0.6) (with-state (colour (vector 1 0 0)) (build-cube)) (with-state (colour (vector 0 1 0)) (translate (vector 1 0 0)) (build-cube))) -------------------- hint-lazy-parent (hint-lazy-parent) (build-sphere 10 10) ; make a sphere with the origin displayed -------------------- hint-cull-ccw (hint-cull-ccw) (build-sphere 10 10) ; make an inside out -------------------- hint-sphere-map (clear) (hint-sphere-map) (texture (load-texture "test.png")) (define p (build-torus 1 2 20 20)) (every-frame (with-primitive p (rotate #(.543 .59 .87)))) -------------------- texture (texture (load-texture "mytexture.png")) (build-sphere 10 10) ; make a sphere textured with mytexture.png -------------------- multitexture (clear) (define p (build-torus 1 2 20 20)) (with-primitive p (multitexture 0 (load-texture "refmap.png")) (multitexture 1 (load-texture "transp.png"))) -------------------- print-scene-graph (print-scene-graph) ; exciting... -------------------- hide (define obj (build-cube)) (grab obj) (hide 1) ; hide this cube (ungrab) -------------------- camera-hide (define obj (build-cube)) (with-primitive obj (camera-hide 1)) ; hide this cube -------------------- selectable (define obj (build-cube)) (grab obj) (selectable 0) ; now it won't be "seen" by calling select (ungrab) -------------------- backfacecull (backfacecull 0) -------------------- shader ; you need to have built fluxus with GLSL=1 (clear) (fluxus-init) ; this is important to add when using shaders ; at the moment, it will be moved somewhere ; to run automatically... (define s (with-state ; assign the shaders to the surface (shader "simple.vert.glsl" "simple.frag.glsl") (build-sphere 20 20))) (with-primitive s ; add and set the pdata - this is then picked up in the vertex shader ; as an input attribute called "testcol" (pdata-add "testcol" "v") ; set the testcol pdata with a random colour for every vertex (pdata-map! (lambda (c) (rndvec)) "testcol")) (define (animate) (with-primitive s ; animate the deformamount uniform input parameter (shader-set! (list "deformamount" (cos (time)))))) (every-frame (animate)) -------------------- shader-source ; you need to have built fluxus with GLSL=1 -------------------- clear-shader-cache (clear-shader-cache) -------------------- shader-set! ; you need to have built fluxus with GLSL=1 (clear) (fluxus-init) ; this is important to add when using shaders ; at the moment, it will be moved somewhere ; to run automatically... (define s (with-state ; assign the shaders to the surface (shader "simple.vert.glsl" "simple.frag.glsl") (build-sphere 20 20))) (with-primitive s ; add and set the pdata - this is then picked up in the vertex shader ; as an input attribute called "testcol" (pdata-add "testcol" "v") ; set the testcol pdata with a random colour for every vertex (pdata-map! (lambda (c) (rndvec)) "testcol")) (define (animate) (with-primitive s ; animate the deformamount uniform input parameter (shader-set! (list "deformamount" (cos (time)))))) (every-frame (animate)) -------------------- texture-params ; parameters are the following: ; tex-env : [modulate decal blend replace] ; min : [nearest linear nearest-mipmap-nearest linear-mipmap-nearest linear-mipmap-linear] ; mag : [nearest linear] ; wrap-s : [clamp repeat] ; wrap-t : [clamp repeat] ; wrap-r : [clamp repeat] (for cube maps) ; border-colour : (vector of length 4) ; priority : real number 0 -> 1 ; env-colour : (vector of length 4) ; min-lod : real number (for mipmap blending - default -1000) ; max-lod : real number (for mipmap blending - default 1000) (texture-params 0 '(min nearest mag nearest)) -------------------- clear-engine (clear-engine) ; woo hoo! -------------------- blur (blur 0.1) ; for nice trails -------------------- fog (clear-colour (vector 0 0 1)) ; looks nice if the background matches (fog (vector 0 0 1) 0.01 1 100) ; blue fog -------------------- show-axis (show-axis 1) -------------------- show-fps (show-fps 1) -------------------- lock-camera (clear) (define obj (build-cube)) ; make a cube for the camera to lock to (with-state ; make a background cube so we can tell what's happening (hint-wire) (hint-unlit) (texture (load-texture "test.png")) (colour (vector 0.5 0.5 0.5)) (scale (vector -20 -10 -10)) (build-cube)) (lock-camera obj) ; lock the camera to our first cube (camera-lag 0.1) ; set the lag amount, this will smooth out the cube jittery movement (define (animate) (with-primitive obj (identity) (translate (vector (fmod (time) 5) 0 0)))) ; make a jittery movement (every-frame (animate)) -------------------- camera-lag (clear) (define obj (build-cube)) ; make a cube for the camera to lock to (with-state ; make a background cube so we can tell what's happening (hint-wire) (hint-unlit) (texture (load-texture "test.png")) (colour (vector 0.5 0.5 0.5)) (scale (vector -20 -10 -10)) (build-cube)) (lock-camera obj) ; lock the camera to our first cube (camera-lag 0.1) ; set the lag amount, this will smooth out the cube jittery movement (define (animate) (with-primitive obj (identity) (translate (vector (fmod (time) 5) 0 0)))) ; make a jittery movement (every-frame (animate)) -------------------- load-texture ; simple usage: (texture (load-texture "mytexture.png")) (build-cube) ; the cube will be texture mapped with the image ; complex usages: ; the options list can contain the following keys and values: ; id: texture-id-number (for adding images to existing textures - for mipmapping and cubemapping) ; type: [texture-2d cube-map-positive-x cube-map-negative-x cube-map-positive-y ; cube-map-negative-y cube-map-positive-z cube-map-negative-z] ; generate-mipmaps : exact integer, 0 or 1 ; mip-level : exact integer ; border : exact integer ; setup an environment cube map (define t (load-texture "cube-left.png" (list 'type 'cube-map-positive-x))) (load-texture "cube-right.png" (list 'id t 'type 'cube-map-negative-x)) (load-texture "cube-top.png" (list 'id t 'type 'cube-map-positive-y)) (load-texture "cube-bottom.png" (list 'id t 'type 'cube-map-negative-y)) (load-texture "cube-front.png" (list 'id t 'type 'cube-map-positive-z)) (load-texture "cube-back.png" (list 'id t 'type 'cube-map-negative-z)) (texture t) ; setup a mipmapped texture with our own images ; you need as many levels as it takes you to get to 1X1 pixels from your ; level 0 texture size (define t2 (load-texture "m0.png" (list 'generate-mipmaps 0 'mip-level 0))) (load-texture "m1.png" (list 'id t2 'generate-mipmaps 0 'mip-level 1)) (load-texture "m2.png" (list 'id t2 'generate-mipmaps 0 'mip-level 2)) (load-texture "m3.png" (list 'id t2 'generate-mipmaps 0 'mip-level 3)) (texture (load-texture "mytexture.png" (list 'generate-mipmaps 0 ; turn mipmapping off 'border 2))) ; add a border to the texture (build-cube) ; the cube will be texture mapped with the image -------------------- clear-texture-cache (clear-texture-cache) -------------------- frustum (frustum -1 1 -0.75 0.75) ; default settings -------------------- clip (clip 1 10000) ; default settings -------------------- ortho (ortho) -------------------- persp (persp) -------------------- set-ortho-zoom (set-ortho-zoom 2) -------------------- clear-colour (clear-colour (vector 1 0 0)) ; RED!!! -------------------- clear-frame (clear-frame 0) (clear-frame 1) -------------------- clear-zbuffer (clear-zbuffer 0) (clear-zbuffer 1) -------------------- clear-accum (clear-accum 1) -------------------- build-camera (clear) (viewport 0 0.5 0.5 0.5) (define cam2 (build-camera)) (current-camera cam2) (viewport 0.5 0 0.5 1) (define cam3 (build-camera)) (current-camera cam3) (set-camera (mmul (mtranslate (vector 0 0 -5)) (mrotate (vector 0 45 0)))) (viewport 0 0 0.5 0.5) ; render a primitive in one view only (define t (with-state (translate (vector 3 0 0)) (scale 0.3) (colour (vector 1 0 0)) (build-torus 1 2 10 10))) (with-primitive t (hide 1) ; hide in all (camera-hide 0)) ; unhide in current camera (current-camera 0) (define c (with-state (hint-cull-ccw) (hint-unlit) (hint-wire) (line-width 2) (colour (vector 0.4 0.3 0.2)) (wire-colour (vector 0 0 0)) (scale 10) (build-cube))) (define p (with-state (scale 3) (load-primitive "widget.obj"))) (every-frame (with-primitive p (rotate (vector 0 1 0)))) -------------------- current-camera (clear) (viewport 0 0.5 0.5 0.5) (define cam2 (build-camera)) (current-camera cam2) (viewport 0.5 0 0.5 1) (define cam3 (build-camera)) (current-camera cam3) (set-camera (mmul (mtranslate (vector 0 0 -5)) (mrotate (vector 0 45 0)))) (viewport 0 0 0.5 0.5) ; render a primitive in one view only (define t (with-state (translate (vector 3 0 0)) (scale 0.3) (colour (vector 1 0 0)) (build-torus 1 2 10 10))) (with-primitive t (hide 1) ; hide in all (camera-hide 0)) ; unhide in current camera (current-camera 0) (define c (with-state (hint-cull-ccw) (hint-unlit) (hint-wire) (line-width 2) (colour (vector 0.4 0.3 0.2)) (wire-colour (vector 0 0 0)) (scale 10) (build-cube))) (define p (with-state (scale 3) (load-primitive "widget.obj"))) (every-frame (with-primitive p (rotate (vector 0 1 0)))) -------------------- viewport (clear) (viewport 0 0.5 0.5 0.5) (define cam2 (build-camera)) (current-camera cam2) (viewport 0.5 0 0.5 1) (define cam3 (build-camera)) (current-camera cam3) (set-camera (mmul (mtranslate (vector 0 0 -5)) (mrotate (vector 0 45 0)))) (viewport 0 0 0.5 0.5) ; render a primitive in one view only (define t (with-state (translate (vector 3 0 0)) (scale 0.3) (colour (vector 1 0 0)) (build-torus 1 2 10 10))) (with-primitive t (hide 1) ; hide in all (camera-hide 0)) ; unhide in current camera (current-camera 0) (define c (with-state (hint-cull-ccw) (hint-unlit) (hint-wire) (line-width 2) (colour (vector 0.4 0.3 0.2)) (wire-colour (vector 0 0 0)) (scale 10) (build-cube))) (define p (with-state (scale 3) (load-primitive "widget.obj"))) (every-frame (with-primitive p (rotate (vector 0 1 0)))) -------------------- get-camera (get-camera) -------------------- get-locked-matrix (get-locked-matrix) -------------------- set-camera (set-camera (mtranslate (vector 0 0 -10))) -------------------- get-projection-transform (get-projection-transform) -------------------- set-projection-transform (set-projection-transform (vector 1 0 0 0 0 4/3 0 0 0 0 -1 -1 0 0 -2 -0)) -------------------- get-screen-size (get-screen-size) -------------------- set-screen-size (set-screen-size (vector 10 10)) ; small window time :) (set-screen-size (vector 720 576)) ; and back again! -------------------- select (display (select 10 10 2))(newline) -------------------- select-all (display (select-all 10 10 2))(newline) -------------------- desiredfps (desiredfps 100000) ; makes fluxus render as fast as it can, and take 100% cpu. -------------------- draw-buffer (draw-buffer 'back) -------------------- read-buffer (read-buffer 'back) -------------------- set-stereo-mode (set-stereo-mode 'crystal-eyes) -------------------- set-colour-mask (set-colour-mask #(#t #f #f #t)) -------------------- shadow-light (shadow-light 1) -------------------- shadow-length (shadow-length 10) -------------------- shadow-debug (shadow-debug 1) -------------------- accum (accum 'add 1) -------------------- print-info (print-info) -------------------- set-cursor (set-cursor 'crosshair) -------------------- start-audio (start-audio "alsa_pcm:capture_1" 1024 44100) -------------------- gh (define (animate) (colour (vector (gh 1) (gh 2) (gh 3))) ; make a colour from the harmonics, and set it to be the current colour (draw-cube)) ; draw a cube with this colour (every-frame (animate)) -------------------- gain (gain 100) ; too quiet?! -------------------- process (process "somemusic.wav") ; read a precorded audio file -------------------- smoothing-bias (smoothing-bias 0) ; no smoothing -------------------- update-audio (update-audio) -------------------- make-light ; turn off the main light (light-diffuse 0 (vector 0 0 0)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'point 'free)) (light-position mylight (vector 5 2 0)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20)) -------------------- light-ambient ; turn off the main light (light-diffuse 0 (vector 0 0 0)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'point 'free)) (light-position mylight (vector 5 2 0)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20)) -------------------- light-diffuse ; turn off the main light (light-diffuse 0 (vector 0 0 0)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'point 'free)) (light-position mylight (vector 5 2 0)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20)) -------------------- light-specular ; turn off the main light (light-diffuse 0 (vector 0 0 0)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'point 'free)) (light-position mylight (vector 5 2 0)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20)) -------------------- light-position ; turn off the main light (light-diffuse 0 (vector 0 0 0)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'point 'free)) (light-position mylight (vector 5 2 0)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20)) -------------------- light-spot-angle ; turn down the main light (light-diffuse 0 (vector 0.1 0.1 0.1)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'spot 'free)) (light-position mylight (vector (+ 4 (crndf)) (crndf) 2)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (light-spot-angle mylight (+ 5 (random 40))) (light-spot-exponent mylight 500) (light-attenuation mylight 'constant 1) (light-direction mylight (vector -1 0 -1)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20) (scale (vector 10 10 10)) (translate (vector -0.5 -0.5 0)) (build-seg-plane 20 20)) -------------------- light-spot-exponent ; turn down the main light (light-diffuse 0 (vector 0.1 0.1 0.1)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'spot 'free)) (light-position mylight (vector (+ 4 (crndf)) (crndf) 2)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (light-spot-angle mylight (+ 5 (random 40))) (light-spot-exponent mylight 500) (light-attenuation mylight 'constant 1) (light-direction mylight (vector -1 0 -1)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20) (scale (vector 10 10 10)) (translate (vector -0.5 -0.5 0)) (build-seg-plane 20 20)) -------------------- light-attenuation ; turn down the main light (light-diffuse 0 (vector 0.1 0.1 0.1)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'spot 'free)) (light-position mylight (vector (+ 4 (crndf)) (crndf) 2)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (light-spot-angle mylight (+ 5 (random 40))) (light-spot-exponent mylight 500) (light-attenuation mylight 'constant 1) (light-direction mylight (vector -1 0 -1)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20) (scale (vector 10 10 10)) (translate (vector -0.5 -0.5 0)) (build-seg-plane 20 20)) -------------------- light-direction ; turn down the main light (light-diffuse 0 (vector 0.1 0.1 0.1)) (light-specular 0 (vector 0 0 0)) (light-ambient 0 (vector 0 0 0)) (define mylight (make-light 'spot 'free)) (light-position mylight (vector (+ 4 (crndf)) (crndf) 2)) (light-diffuse mylight (rndvec)) (light-ambient mylight (vmul (rndvec) 0.1)) (light-specular mylight (vmul (rndvec) 10)) (light-spot-angle mylight (+ 5 (random 40))) (light-spot-exponent mylight 500) (light-attenuation mylight 'constant 1) (light-direction mylight (vector -1 0 -1)) (with-state (ambient (vector 1 1 1)) (colour (vector 1 1 1)) (specular (vector 0.5 0.5 0.5)) (shinyness 20) (build-torus 1 2 20 20) (scale (vector 10 10 10)) (translate (vector -0.5 -0.5 0)) (build-seg-plane 20 20)) -------------------- vmul (vmul (vector 1 2 3) 2) -------------------- vadd (vadd (vector 1 2 3) (vector 1 2 3)) -------------------- vsub (vsub (vector 1 2 3) (vector 1 2 3)) -------------------- vdiv (vdiv (vector 1 2 3) 2) -------------------- vtransform (vtransform (vector 0 1 0) (mrotate (vector 90 0 0))) -------------------- vtransform-rot (vtransform-rot (vector 0 1 0) (mrotate (vector 90 0 0))) -------------------- vnormalise (vtransform-rot (vector 0 1 0) (mrotate (vector 90 0 0))) -------------------- vdot (vdot (vector 0 1 0) (vector 1 0 0)) -------------------- vmag (vmag (vector 0 1 1)) -------------------- vreflect (vreflect (vector 0 1 1) (vector 1 0 1)) -------------------- vdist (vdist (vector 100 100 0) (vector 0 0 100)) -------------------- vdist-sq (vdist-sq (vector 100 100 0) (vector 0 0 100)) -------------------- vcross (vcross (vector 100 100 0) (vector 0 0 100)) -------------------- mmul (mmul (mtranslate (vector 1 0 0)) (mrotate (vector 0 90 0))) -------------------- madd (madd (mtranslate (vector 1 0 0)) (mrotate (vector 0 90 0))) -------------------- msub (msub (mtranslate (vector 1 0 0)) (mrotate (vector 0 90 0))) -------------------- mdiv (mdiv (mtranslate (vector 1 0 0)) (mrotate (vector 0 90 0))) -------------------- mident (mident) -------------------- mtranslate (mtranslate (vector 100 0 0)) -------------------- mrotate (mrotate (vector 0 45 0)) -------------------- mscale (mscale (vector 0.5 2 0.5)) -------------------- mtranspose (mtranspose (mident)) -------------------- minverse (minverse (mscale (vector 0.5 2 0.5))) -------------------- maim (maim (vector 0 0 1) (vector 0 1 0)) -------------------- matrix->euler (matrix->euler (mrotate (vector 15 0 0))) -------------------- qaxisangle (qaxisangle (vector 0 1 0) 45) -------------------- qmul (qmul (qaxisangle (vector 0 1 0) 45) (qaxisangle (vector 0 0 1) 180)) -------------------- qnormalise (qnormalise (qaxisangle (vector 0 19 0) 45)) -------------------- qtomatrix (qtomatrix (qaxisangle (vector 0 1 0) 45)) -------------------- qconjugate (qconjugate (qaxisangle (vector 0 1 0) 45)) -------------------- fmod (fmod 14.4 10) -------------------- snoise (snoise 1.0 2.0) ; 2D noise (snoise 6.1 2.4 .5 1.3) ; 4D noise ; example on a pixel prim (clear) (with-primitive (build-pixels 100 100) (pdata-index-map! (lambda (i c) (snoise (* 0.1 (modulo i (pixels-width))) (* 0.1 (quotient i (pixels-height))))) "c") (pixels-upload)) -------------------- noise (noise 1.0 2.0) ; 2D noise (noise 6.1 2.4 .5) ; 3D noise ; example on a pixel prim (clear) (with-primitive (build-pixels 100 100) (pdata-index-map! (lambda (i c) (noise (* 0.1 (modulo i (pixels-width))) (* 0.1 (quotient i (pixels-height))))) "c") (pixels-upload)) -------------------- noise-seed (noise-seed 1) -------------------- noise-detail (noise-detail 4) ; noise with 4 octaves (noise-detail 4 .5) ; noise with 4 octaves and .5 falloff -------------------- collisions (collisions 1) -------------------- ground-plane (ground-plane (vector 0 1 0) 0) -------------------- active-box (define mycube (build-cube)) (active-box mycube) -------------------- active-cylinder (define mycube (build-cube)) (active-cylinder mycube) -------------------- active-sphere (define mycube (build-cube)) (active-sphere mycube) -------------------- passive-box (define mycube (build-cube)) (passive-box mycube) -------------------- passive-cylinder (define mycube (build-cube)) (passive-cylinder mycube) -------------------- passive-sphere (define mycube (build-cube)) (passive-sphere mycube) -------------------- physics-remove (define mycube (build-cube)) (active-box mycube) (physics-remove mycube) -------------------- surface-params (surface-params 0.1 0.1 0.1 0.1) -------------------- build-balljoint (clear) (ground-plane (vector 0 1 0) -1) (collisions 1) (define shape1 (with-state (translate (vector -1 0 0)) (build-cube))) (active-box shape1) (define shape2 (with-state (translate (vector 1 0 0)) (build-cube))) (active-box shape2) (build-balljoint shape1 shape2 (vector 0 0 0)) (kick shape1 (vector 0 2 0)) (set-physics-debug #t) -------------------- build-fixedjoint (clear) (define shape1 (with-state (translate (vector 0 1 0)) (build-cube))) (active-box shape1) (build-fixedjoint shape1) ; not very exciting... -------------------- build-hingejoint (clear) (ground-plane (vector 0 1 0) -1) (collisions 1) (define shape1 (with-state (translate (vector -1 0 0)) (build-cube))) (active-box shape1) (define shape2 (with-state (translate (vector 1 0 0)) (build-cube))) (active-box shape2) (build-hingejoint shape1 shape2 (vector 0 0 0) (vector 0 0 1)) (kick shape1 (vector 0 2 0)) (set-physics-debug #t) -------------------- build-sliderjoint (clear) (ground-plane (vector 0 1 0) -1) (collisions 1) (define shape1 (with-state (translate (vector -1 0 0)) (build-cube))) (active-box shape1) (define shape2 (with-state (translate (vector 1 0 0)) (build-cube))) (active-box shape2) (build-sliderjoint shape1 shape2 (vector 1 0 0)) (kick shape1 (vector 0 2 0)) (set-physics-debug #t) -------------------- build-hinge2joint (clear) (ground-plane (vector 0 1 0) -1) (collisions 1) (define shape1 (with-state (translate (vector -1 0 0)) (build-cube))) (active-box shape1) (define shape2 (with-state (translate (vector 1 0 0)) (build-cube))) (active-box shape2) (build-hinge2joint shape1 shape2 (vector 0 0 0) (vector 1 0 0) (vector 0 1 0)) (kick shape1 (vector 0 2 0)) (set-physics-debug #t) -------------------- build-amotorjoint (clear) (ground-plane (vector 0 1 0) -1) (collisions 1) (define shape1 (with-state (translate (vector -1 0 0)) (build-cube))) (active-box shape1) (define shape2 (with-state (translate (vector 1 0 0)) (build-cube))) (active-box shape2) (build-amotorjoint shape1 shape2 (vector 1 0 0)) (kick shape1 (vector 0 2 0)) (set-physics-debug #t) -------------------- joint-param (clear) (ground-plane (vector 0 1 0) -1) (collisions 1) (define shape1 (with-state (translate (vector -1 0 0)) (build-cube))) (active-box shape1) (define shape2 (with-state (translate (vector 1 0 0)) (build-cube))) (active-box shape2) (define j (build-hinge2joint shape1 shape2 (vector 0 0 0) (vector 1 0 0) (vector 0 1 0))) (joint-param j "Vel2" 0.1) (joint-param j "FMax2" 0.2) (joint-param j "LoStop" -0.75) (joint-param j "HiStop" 0.75) (set-physics-debug #t) -------------------- joint-angle (clear) (ground-plane (vector 0 1 0) -1) (collisions 1) (define shape1 (with-state (translate (vector -1 0 0)) (build-cube))) (active-box shape1) (define shape2 (with-state (translate (vector 1 0 0)) (build-cube))) (active-box shape2) (define j (build-hingejoint shape1 shape2 (vector 0 0 0) (vector 0 1 0))) (joint-param j "FMax" 20) (joint-param j "LoStop" -1) (joint-param j "HiStop" 1) (set-physics-debug #t) (define (animate) (joint-angle j 0.1 (* 5 (sin (time))))) -------------------- joint-slide (clear) (ground-plane (vector 0 1 0) -1) (collisions 1) (define shape1 (with-state (translate (vector -1 0 0)) (build-cube))) (active-box shape1) (define shape2 (with-state (translate (vector 1 0 0)) (build-cube))) (active-box shape2) (define j (build-sliderjoint shape1 shape2 (vector 1 0 0))) (joint-param j "FMax" 20) (joint-param j "LoStop" -1) (joint-param j "HiStop" 1) (set-physics-debug #t) (define (animate) (joint-slide j (* 5 (sin (time))))) -------------------- set-max-physical (clear) (set-max-physical 200) (every-frame (with-state (translate (vector 0 5 0)) (scale (srndvec)) (colour (rndvec)) (let ((ob (build-cube))) (active-box ob) (kick ob (vmul (srndvec) 3)) (twist ob (vmul (srndvec) 2))))) -------------------- set-mass (clear) (ground-plane (vector 0 1 0) 0) (collisions 1) (set-max-physical 20) ; not a great example, but these boxes will have ; different mass, so behave a bit differently. (every-frame (when (> (rndf) 0.92) (with-state (translate (vector 0 5 0)) (scale (vmul (rndvec) 5)) (colour (rndvec)) (let ((ob (build-cube))) (active-box ob) (set-mass ob (* (rndf) 10)) (kick ob (vmul (srndvec) 3)) (twist ob (vmul (srndvec) 2)))))) -------------------- gravity (clear) (ground-plane (vector 0 1 0) 0) (collisions 1) (set-max-physical 20) (every-frame (begin (gravity (vector 0 (sin (time)) 0)) ; change gravity! :) (when (> (rndf) 0.92) (with-state (translate (vector 0 5 0)) (scale (rndvec)) (colour (rndvec)) (let ((ob (build-cube))) (active-box ob) (kick ob (vmul (srndvec) 3)) (twist ob (vmul (srndvec) 2))))))) -------------------- kick (clear) (collisions 1) (set-max-physical 20) (gravity (vector 0 0 0)) (every-frame (when (> (rndf) 0.92) (with-state (scale (rndvec)) (colour (rndvec)) (let ((ob (build-cube))) (active-box ob) (kick ob (vmul (srndvec) 3)) (twist ob (vmul (srndvec) 2)))))) -------------------- twist (clear) (collisions 1) (set-max-physical 20) (gravity (vector 0 0 0)) (every-frame (when (> (rndf) 0.92) (with-state (scale (rndvec)) (colour (rndvec)) (let ((ob (build-cube))) (active-box ob) (kick ob (vmul (srndvec) 3)) (twist ob (vmul (srndvec) 2)))))) -------------------- has-collided (clear) (ground-plane (vector 0 1 0) 0) (collisions 1) (set-max-physical 20) (define ob (with-state (translate (vector 0 5 0)) (build-cube))) (active-box ob) (every-frame (when (has-collided ob) (with-primitive ob (colour (rndvec))))) -------------------- turtle-prim (turtle-prim 0) -------------------- turtle-vert (turtle-vert) -------------------- turtle-build (define mynewshape (turtle-build)) -------------------- turtle-move (turtle-move 1) -------------------- turtle-push (turtle-push) -------------------- turtle-pop (turtle-pop) -------------------- turtle-turn (turtle-turn (vector 45 0 0)) -------------------- turtle-reset (turtle-reset) -------------------- turtle-attach (define myshape (build-sphere 10 10)) (turtle-attach myshape) -------------------- turtle-skip (turtle-skip -1) -------------------- turtle-position (display (turtle-position))(newline) -------------------- turtle-seek (turtle-seek 0) -------------------- midi-info (midi-info) -------------------- midi-init (midi-init 1) -------------------- midi-cc (midi-cc 0 1) -------------------- midi-ccn (midi-ccn 0 1) -------------------- midi-note (midi-note) -------------------- midi-peek (display (midi-peek))(newline) -------------------- osc-source (osc-source "4444") ; listen to port 4444 for osc messages -------------------- osc-msg (cond ((osc-msg "/hello") ; if a the /hello message is recieved (display (osc 1))(newline))) ; print out the first argument -------------------- osc (cond ((osc-msg "/hello") ; if a the /hello message is recieved (display (osc 1))(newline))) ; print out the first argument -------------------- osc-destination (osc-destination "osc.udp:localhost:4444") (osc-send "/hello" "s" (list "boo!")) ; send a message to this destination -------------------- osc-peek (display (osc-peek))(newline) -------------------- osc-send (osc-destination "osc.udp:localhost:4444") (osc-send "/hello" "sif" (list "boo!" 3 42.3)) ; send a message to this destination -------------------- reset-camera ; ruin the camera transform (set-camera-transform (vector 123 41832 28 0.2 128 0.001 123 41832 28 0.2 128 0.001 0.2 100 13 1931)) ; set it back to the starting position/orientation (reset-camera) -------------------- set-camera-transform (set-camera-transform (mtranslate (vector 0 0 -10))) -------------------- get-camera-transform (define tx (get-camera-transform)) -------------------- set-help-locale! (set-help-locale! "pt") ; switch to portuguese (set-help-locale! "en") ; and back to english -------------------- help (help "pop") -------------------- key-pressed (when (key-pressed "q") (display "q pressed!")) -------------------- keys-down (display (keys-down))(newline) -------------------- key-special-pressed (when (key-special-pressed 100) (display "left cursor pressed")) (when (key-special-pressed 102) (display "right cursor pressed")) (when (key-special-pressed 101) (display "up cursor pressed")) (when (key-special-pressed 103) (display "down cursor pressed")) -------------------- keys-special-down (display (keys-special-down)) -------------------- key-pressed-this-frame (when (key-pressed-this-frame "q") (display "q pressed!")) -------------------- key-special-pressed-this-frame (when (key-special-pressed-this-frame "q") (display "q pressed!")) -------------------- mouse-x (display (mouse-x)) -------------------- mouse-y (display (mouse-y)) -------------------- mouse-button (display (mouse-button 1)) -------------------- mouse-wheel (display (mouse-wheel)) -------------------- mouse-over (grab (mouse-over)) (colour (vector 1 0 0)) ; paints objects the mouse is over red (ungrab) -------------------- every-frame (define (myfunc) (colour (rndvec)) (draw-torus)) (every-frame (myfunc)) -------------------- clear (clear) ; without this we would accumulate a new cube every time F5 was pressed (build-cube) -------------------- start-framedump (start-framedump "frame" "jpg") -------------------- end-framedump (end-framedump) -------------------- set-physics-debug (set-physics-debug #t) -------------------- override-frame-callback (override-frame-callback myfunc) (override-frame-callback default-fluxus-frame-callback) ; set it back again... -------------------- set-auto-indent-tab (set-auto-indent-tab 2) -------------------- set-camera-update (set-camera-update #f) (set-camera-update #t) -------------------- spawn-task (spawn-task (lambda () (draw-torus)) 'torus-task) (rm-task 'torus-task) -------------------- rm-task (spawn-task (lambda () (draw-torus)) 'torus-task) ; add a task (rm-task 'torus-task) ; remove it again -------------------- rm-all-tasks (rm-all-tasks) -------------------- ls-tasks (spawn-task (lambda () (draw-torus)) 'torus-task) ; add a task (ls-tasks) (rm-task 'torus-task) -------------------- spawn-timed-task (spawn-timed-task (+ (time-now) 10) ; schedule a task 10 seconds from now (lambda () (display "hello future!") (newline)))