/examples/empathy/source.scm
Scheme | 126 lines | 58 code | 56 blank | 12 comment | 0 complexity | fba14c042ebb47d4fea8177e9d005c62 MD5 | raw file
Possible License(s): BSD-3-Clause
1 2 3;; Original version by Kyle McDonald: 4;; 5;; http://www.openprocessing.org/visuals/?visualID=1182 6;; 7;; Ported to Abstracting by Ed Cavazos 8 9;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 10 11(for-each require-lib '("list" "math" "tendrils/nodebox")) 12 13;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 14 15(define *number-of-cells* 5000) 16 17(define *base-line-length* 37) 18 19(define *rotation-speed-step* 0.004) 20 21(define *slow-down-rate* 0.97) 22 23(set! *y-increases-up* #f) 24 25;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 26 27(define (det x1 y1 x2 y2 x3 y3) 28 (- (* (- x2 x1) 29 (- y3 y1)) 30 31 (* (- x3 x1) 32 (- y2 y1)))) 33 34(define (cell x y) 35 36 (let ((spin-velocity 0) 37 (current-angle 0)) 38 39 (let ((sense 40 (lambda () 41 42 (if (or (not (= *p-mouse-x* 0)) 43 (not (= *p-mouse-y* 0))) 44 45 (set! spin-velocity 46 47 (+ spin-velocity 48 49 (/ (* *rotation-speed-step* 50 51 (det x y *p-mouse-x* *p-mouse-y* *mouse-x* *mouse-y*)) 52 53 (+ (dist x y *mouse-x* *mouse-y*) 1))))) 54 55 (set! spin-velocity (* spin-velocity *slow-down-rate*)) 56 57 (set! current-angle (+ current-angle spin-velocity)) 58 59 (let ((d (+ 0.001 (* *base-line-length* spin-velocity)))) 60 61 (glVertex2d x y) 62 (glVertex2d (+ x (* d (cos current-angle))) 63 (+ y (* d (sin current-angle)))))))) 64 65 (vector 'cell sense)))) 66 67(define (sense cell) 68 ((vector-ref cell 1))) 69 70;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 71 72(set! *title* "Empathy by Kyle McDonald") 73 74(size 500 500) 75 76;; (set! *frames-per-second* #t) 77 78(set! *frames-per-second* 30) 79 80(init-nodebox) 81 82(stroke 0.0 0.0 0.0 0.5) 83 84(define *cells* 85 (list-tabulate *number-of-cells* 86 (lambda (i) 87 88 (let ((theta (+ i (random 0 (/ pi 9)))) 89 (dista (+ 3 90 91 (random -3 3) 92 93 (* (/ i *number-of-cells*) 94 95 (/ *width* 2) 96 97 (* (/ (- *number-of-cells* i) *number-of-cells*) 3.3))))) 98 99 (cell (+ (/ *width* 2) (* dista (cos theta))) 100 (+ (/ *height* 2) (* dista (sin theta)))))))) 101 102;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 103 104(set! *draw* 105 106 (lambda () 107 108 (background 1.0) 109 110 (glColor4d 0.0 0.0 0.0 0.5) 111 112 (glBegin GL_LINES) 113 (for-each sense *cells*) 114 (glEnd) 115 116 (set! *p-mouse-x* *mouse-x*) 117 (set! *p-mouse-y* *mouse-y*))) 118 119;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 120 121(run-nodebox) 122 123 124 125 126