Commit 98d641bb authored by Dave Griffiths's avatar Dave Griffiths
Browse files

network livecoding bugfixes

parent 8d16f805
......@@ -571,6 +571,8 @@
(else s)))
(define (compile-program cycles prim hints x)
(set! variables '())
(set! function-code '())
(let* ((code (emit-expr (pre-process x)))
(data (variables->data))
(function-start (+ reg-code-start (length data)))
......
......@@ -15,14 +15,14 @@ code = ["""
(set! v (+ (* (normalise (read vertex)) 0.05)
(* (- (read vertex)
(read (- vertex 1))) -0.5)))
(write-add! vertex (+ v (* (rndvec) 0.1)))
(write-add! vertex (+ v (* (sincos (* (read vertex) 0.01)) 0.1)))
(set! vertex (+ vertex 1)))
(set! t (+ t 0.01))
)))
(hint-unlit)
(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"))
""",
......@@ -80,12 +80,134 @@ code = ["""
(pdata-map! (lambda (t) (vmul t -1)) "t")
(pdata-map! (lambda (c) (vector 1 1 1)) "c")
(pdata-map! (lambda (n) (vector 0 0 0)) "n"))
"""]
""",
"""
(with-primitive
(make-jelly
10000 prim-triangles
'(let ((vertex positions-start)
(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
(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")
)
"""
]
while 1:
print("sending")
#osc.Message("/eval",[choice(code)]).sendto("192.168.1.192",8000)
osc.Message("/eval",[choice(code)]).sendlocal(8000)
time.sleep(6)
osc.Message("/eval",[choice(code)]).sendto("192.168.1.192",8000)
#osc.Message("/eval",[choice(code)]).sendlocal(8000)
time.sleep(30)
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