jellyfish.scm 1.89 KB
Newer Older
Dave Griffiths's avatar
Dave Griffiths committed
1
2
3
4
5
6
7
8
9
10
11
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; jellyfish livecoding stuff

(define (jelly-compiled code)
  (define addr 0)
  (for-each
   (lambda (v)
     (pdata-set! "x" addr v)
     (set! addr (+ addr 1)))
   code))

Dave Griffiths's avatar
Dave Griffiths committed
12
13
14
15
16
(define jellyfish
  (list
   (build-jellyfish 512)
   (build-jellyfish 512)
   (build-jellyfish 512)))
Dave Griffiths's avatar
Dave Griffiths committed
17

Dave Griffiths's avatar
Dave Griffiths committed
18
(define current 0)
Dave Griffiths's avatar
Dave Griffiths committed
19
20

(define (make-jelly speed prim-type code)
Dave Griffiths's avatar
Dave Griffiths committed
21
22
  (let ((p (list-ref jellyfish current)))
    (msg p)
Dave Griffiths's avatar
Dave Griffiths committed
23
24
25
26
27
    (with-primitive
     p
     (let ((c (compile-program speed prim-type 1 code)))
       ;; (disassemble c)
       (jelly-compiled c))
Dave Griffiths's avatar
Dave Griffiths committed
28
     (set! current (modulo (+ current 1) (length jellyfish)))
Dave Griffiths's avatar
Dave Griffiths committed
29
30
31
32
     p)))


(with-primitive
Dave Griffiths's avatar
Dave Griffiths committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  (make-jelly
   10000 prim-triangles
   '(let ((vertex positions-start)
           (t 0)
           (v 0)
           (np 0))
       (forever
        (set! vertex positions-start)
        (loop (< vertex positions-end)
              (set! np (+ (* (+ (read vertex) vertex) 0.1)
                          (swizzle yyx t)))
              (set! v (+ (*v (noise np) (vector 1 0 0))
                        (*v (noise (+ np 101.1)) (vector 0 1 0))))
             (set! v (*v (- v (vector 0.47 0.47 0.47)) (vector 0.1 0.1 0)))
              (write-add! vertex v v v v v v)
              (set! vertex (+ vertex 6)))
        (set! t (+ t 0.01))
        )))
   (hint-unlit)
Dave Griffiths's avatar
Dave Griffiths committed
52
53
   (pdata-index-map!
    (lambda (i p)
Dave Griffiths's avatar
Dave Griffiths committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
      (let ((z (* i 0.01)))
        (if (odd? i)
            (list-ref
             (list (vector 0 0 z) (vector 1 0 z) (vector 1 1 z))
             (modulo i 3))
            (list-ref
             (list (vector 1 1 z) (vector 0 1 z) (vector 0 0 z))
             (modulo i 3))))) "p")
   (texture (load-texture "raspberrypi.png"))
   (translate (vector -0.5 -0.5 0))
   (pdata-copy "p" "t")
   (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"))