Commit 8d16f805 authored by Dave Griffiths's avatar Dave Griffiths
Browse files

rpi optimisations

parent 3eb151a6
......@@ -6,8 +6,8 @@
(define _touches '())
(define _fling (vector 0 0))
;(define-macro (every-frame . args)
; `(begin (set! frame-thunk (lambda () ,@args))))
(define-macro (every-frame . args)
`(begin (set! frame-thunk (lambda () ,@args))))
(define (frame-hook)
(set! flx_time (+ flx_time 1))
......
......@@ -9,51 +9,143 @@
(set! addr (+ addr 1)))
code))
(define jellyfish '())
(define jellyfish
(list
(build-jellyfish 512)
(build-jellyfish 512)
(build-jellyfish 512)))
;; run 3 at once
(define max-jellyfish 3)
(define (add-jellyfish j l)
(cond
((>= (length l) max-jellyfish)
(destroy (car l))
(append (cdr l) (list j)))
(else
(append l (list j)))))
(define current 0)
(define (make-jelly speed prim-type code)
(let ((p (build-jellyfish 512)))
(let ((p (list-ref jellyfish current)))
(msg p)
(with-primitive
p
(let ((c (compile-program speed prim-type 1 code)))
;; (disassemble c)
(jelly-compiled c))
(set! jellyfish (add-jellyfish p jellyfish))
(set! current (modulo (+ current 1) (length jellyfish)))
p)))
(with-primitive
(make-jelly
10000 prim-tristrip
10000 prim-triangles
'(let ((vertex positions-start)
(t 0)
(v 0)
(np 0))
(flingdamp (vector 50 -20 0))
(world (vector 0 0 0))
(t 0))
(define recycle
(lambda (dir)
;; shift along x and y coordinates:
;; set z to zero for each vertex
(write! vertex
(+ (*v (read vertex)
(vector 1 1 0)) dir)
(+ (*v (read (+ vertex 1))
(vector 1 1 0)) dir)
(+ (*v (read (+ vertex 2))
(vector 1 1 0)) dir))
;; get the perlin noise values for each vertex
(let ((a (noise (* (- (read vertex) world) 0.2)))
(b (noise (* (- (read (+ vertex 1))
world) 0.2)))
(c (noise (* (- (read (+ vertex 2))
world) 0.2))))
;; set the z coordinate for height
(write-add!
vertex
(+ (*v a (vector 0 0 8))
(vector 0 0 -4))
(+ (*v b (vector 0 0 8))
(vector 0 0 -4))
(+ (*v c (vector 0 0 8))
(vector 0 0 -4)))
;; recalculate normals
(define n (normalise
(cross (- (read vertex)
(read (+ vertex 1)))
(- (read vertex)
(read (+ vertex 2))))))
;; write to normal data
(write! (+ vertex 512) n n n)
;; write the z height as texture coordinates
(write! (+ vertex 1536)
(*v (swizzle zzz a) (vector 0 4 0))
(*v (swizzle zzz b) (vector 0 4 0))
(*v (swizzle zzz c) (vector 0 4 0))))))
;; forever
(forever
(set! vertex (+ positions-start 1))
(loop (< vertex positions-end)
(set! v (+ (* (normalise (read vertex)) 0.05)
(* (- (read vertex)
(read (- vertex 1))) -0.5)))
(write-add! vertex (+ v (* (rndvec) 0.1)))
(set! vertex (+ vertex 1)))
(set! t (+ t 0.01))
)))
(hint-unlit)
(pdata-copy "p" "t")
(pdata-map! (lambda (p) (vmul (srndvec) 1)) "p")
(pdata-map! (lambda (c) (rndvec)) "c")
(pdata-map! (lambda (n) (vector 0 0 0)) "n"))
(define vel (* flingdamp 0.002))
;; update the world coordinates
(set! world (+ world vel))
(set! t (+ t 0.1))
;; for each vertex
(loop (< vertex (- positions-end 3))
;; update the vertex position
(write-add! vertex vel vel vel)
;; check for out of area polygons to recycle
(cond
((> (read vertex) 5.0)
(recycle (vector -10 0 0)))
((< (read vertex) -5.0)
(recycle (vector 10 0 0))))
(cond
((> (swizzle yzz (read vertex)) 4.0)
(recycle (vector 0 -8 0)))
((< (swizzle yzz (read vertex)) -4.0)
(recycle (vector 0 8 0))))
(set! vertex (+ vertex 3)))
(set! vertex positions-start))))
(pdata-map! (lambda (n) (vmul (vector (crndf) (crndf) 0) 0.001)) "n")
(pdata-map! (lambda (c) (vector 1 1 1)) "c")
(texture (load-texture "stripes.png"))
(translate (vector -1 2 0))
(rotate (vector -45 0 0))
; (rotate (vector 0 0 100))
(scale (vector 1.5 1.5 1.5))
(let ((tsize 1)
(twidth 8))
(pdata-index-map!
(lambda (i p)
(let* ((tpos (modulo i 3))
(tri (quotient i 3))
(flip (modulo tri 2))
(quad (quotient tri 2))
(col (modulo quad twidth))
(row (quotient quad twidth)))
(vadd
(vector (+ (* row tsize) 10) (* col tsize) 0)
(vmul
(if (zero? flip)
(cond
((eqv? tpos 0) (vector 0 0 0))
((eqv? tpos 1) (vector tsize 0 0))
((eqv? tpos 2) (vector tsize tsize 0)))
(cond
((eqv? tpos 0) (vector 0 0 0))
((eqv? tpos 1) (vector tsize tsize 0))
((eqv? tpos 2) (vector 0 tsize 0))))
1))))
"p"))
(pdata-map! (lambda (t) (vector 0 0 0)) "t")
)
assets/stripes.png

7.09 KB | W: | H:

assets/stripes.png

7.73 KB | W: | H:

assets/stripes.png
assets/stripes.png
assets/stripes.png
assets/stripes.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -274,8 +274,8 @@ void primitive::render(u32 hints)
if (hints&HINT_WIRE)
{
glDisableClientState(GL_COLOR_ARRAY);
glColor3f(0,0,0);
// glDisableClientState(GL_COLOR_ARRAY);
// glColor3f(0,0,0);
glDrawArrays(GL_LINE_STRIP, 0, m_size);
}
......
......@@ -10,7 +10,6 @@ code = ["""
(v 0)
(np 0))
(forever
(set! vertex (+ positions-start 1))
(loop (< vertex positions-end)
(set! v (+ (* (normalise (read vertex)) 0.05)
......@@ -22,7 +21,7 @@ code = ["""
(set! t (+ t 0.01))
)))
(hint-unlit)
(pdata-copy "p" "t")
(texture 0)
(pdata-map! (lambda (p) (vmul (srndvec) 1)) "p")
(pdata-map! (lambda (c) (rndvec)) "c")
(pdata-map! (lambda (n) (vector 0 0 0)) "n"))
......@@ -32,12 +31,14 @@ code = ["""
(with-primitive
(make-jelly 1000 prim-tristrip
'(let ((vertex positions-start))
(write! reg-graphics (vector 512 1 2))
(forever
(set! vertex positions-start)
(loop (< vertex positions-end)
(write! vertex (+ (read vertex) (rndvec)))
(++! vertex))
)))
(texture 0)
(pdata-map! (lambda (p) (srndvec)) "p")
(pdata-map! (lambda (c) (rndvec)) "c"))
""",
......@@ -85,6 +86,6 @@ code = ["""
while 1:
print("sending")
osc.Message("/eval",[choice(code)]).sendto("192.168.1.192",8000)
#osc.Message("/eval",[choice(code)]).sendlocal(8000)
time.sleep(60)
#osc.Message("/eval",[choice(code)]).sendto("192.168.1.192",8000)
osc.Message("/eval",[choice(code)]).sendlocal(8000)
time.sleep(6)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment