(define Time 0.5)

;
; sky dome
;
(define SKY (surface BLEND_TURBULENCE SURF_CONSTANT BUMP_FLAT SURF_CONSTANT BUMP_FLAT 0 1))

(define (skyDome) (scale 30 30 30 (move 0 3985 0
(scale 20 20 20 (shade SKY (rgb 0.1 0.3 0.9) (rgb 0.9 0.9 0.9)
(scale 0.05 0.05 0.05 (diff
(scale 4100 4100 4100 (sphere))
(scale 4000 4000 4000 (sphere))
))
))
)))


;
; quadric robot with parameterized joins
;

(define (Robot L_SHOULDER L_ELBOW R_SHOULDER R_ELBOW L_HIP L_KNEE R_HIP R_KNEE)
(bound (union
(bound (union ; head and trunk
(move 0 210 0 (rotate 20 '(0 0 1) (scale 32 48 32 (sphere))))
(move 0 160 0 (scale 20 40 20 (sphere))) ; neck
(move 0 120 15 (scale 30 40 55 (sphere))) ; chest and shoulders
(move 0 120 -15 (scale 30 40 55 (sphere)))
(move 0 80 0 (scale 30 80 50 (sphere))) ; abdomen and hip
(move 0 -50 0 (scale 35 35 55 (sphere)))
(move 0 34 0 (scale 25 25 35 (sphere)))
(move 0 17 0 (scale 25 25 35 (sphere)))
(move 0 0 0 (scale 25 25 35 (sphere)))
(move 0 -17 0 (scale 25 25 35 (sphere)))
))

; left arm
(bound (move 0 130 70 (rotate L_SHOULDER '(0 0 1) (union
; forearm and hand
(move 0 -110 0 (rotate L_ELBOW '(0 0 1) (union
(move 0 0 0 (scale 13 20 13 (sphere)))
(move 0 -50 0 (scale 12 50 12 (sphere)))
(move 0 -100 0 (scale 10 10 10 (sphere)))
(move 0 -120 0 (scale 12 25 6 (sphere)))
)))
; upper arm
(move 0 -55 0 (scale 23 55 16 (sphere)))
(move 0 -10 -10 (rotate -35 '(1 0 0) (scale 22 33 22 (sphere))))
))))

; right arm
(bound (move 0 130 -70 (scale 1 1 -1 (rotate R_SHOULDER '(0 0 1) (union
; forearm and hand
(move 0 -110 0 (rotate R_ELBOW '(0 0 1) (union
(move 0 0 0 (scale 13 20 13 (sphere)))
(move 0 -50 0 (scale 12 50 12 (sphere)))
(move 0 -100 0 (scale 10 10 10 (sphere)))
(move 0 -120 0 (scale 12 25 6 (sphere)))
)))
; upper arm
(move 0 -55 0 (scale 23 55 16 (sphere)))
(move 0 -10 -10 (rotate -35 '(1 0 0) (scale 22 33 22 (sphere))))
)))))

; left leg
(bound (move 0 -50 30 (rotate L_HIP '(0 0 1) (union
(move 0 -160 0 (rotate L_KNEE '(0 0 1) (union ; calf and foot
(move 0 0 0 (scale 20 20 20 (sphere)))
(move 0 -75 0 (scale 20 75 20 (sphere)))
(move 0 -150 0 (scale 20 12 12 (sphere)))
(move 20 -160 0 (scale 45 10 20 (sphere)))
)))
(move 0 -80 0 (scale 30 80 27 (sphere))) ; thigh
))))

; right leg
(bound (move 0 -50 -30 (scale 1 1 -1 (rotate R_HIP '(0 0 1) (union
(move 0 -160 0 (rotate R_KNEE '(0 0 1) (union ; calf and foot
(move 0 0 0 (scale 20 20 20 (sphere)))
(move 0 -75 0 (scale 20 75 20 (sphere)))
(move 0 -150 0 (scale 20 12 12 (sphere)))
(move 20 -160 0 (scale 45 10 20 (sphere)))
)))
(move 0 -80 0 (scale 30 80 27 (sphere))) ; thigh
)))))
))
)

;
; robot riding a unicycle
;
(define PI 3.14159265358979323846)
(define RTD 57.29577951308232087721)
(define (S angle)
(sin (* angle RTD))
)
(define (C angle)
(cos (* angle RTD))
)
(define (A angle)
(/ (atan angle) RTD)
)
(define (sqr x)
(* x x)
)

(define (unicyclist time)
(let* (
(s (* PI (- 2 time))) ; pedal angle (0-2 PI)
(f (* 0.8 (S s))) ; foot(z)
(g (* 0.8 (C s))) ; foot(y)
(h (- 5.33333 1)) ; height of hip joint
(l 2.66667) ; length of thigh (and calf)
(d (sqrt (+ (sqr (- h g)) (sqr f)))); dist foot to hip
(v (sqrt (- (sqr l) (/ (sqr d) 4)))); knee-chord dist
(a (A (* 2 (/ v d)))) ; internal angle
(k (* -360 (/ a PI))) ; knee angle (with thigh)
(c (A (/ f (- g h)))) ; external angle
(j (* 180 (/ (+ a c) PI))) ; hip angle

(s (+ s PI)) ; pedal angle (1-3 PI)
(f (* 0.8 (S s))) ; foot(z)
(g (* 0.8 (C s))) ; foot(y)
(h (- 5.33333 1)) ; height of hip joint
(l 2.66667) ; length of thigh (and calf)
(d (sqrt (+ (sqr (- h g)) (sqr f)))); dist foot to hip
(v (sqrt (- (sqr l) (/ (sqr d) 4)))); knee-chord dist
(a (A (* 2 (/ v d)))) ; internal angle
(n (* -360 (/ a PI))) ; knee angle (with thigh)
(c (A (/ f (- g h)))) ; external angle
(m (* 180 (/ (+ a c) PI))) ; hip angle

(le (+ 15 (* 15 (C (* (+ time 1) PI))))) ; left elbow
(ls (* 20 (C (* (+ time 1) PI)))) ; left shoulder
(re (+ 15 (* 15 (C (* time PI))))) ; right elbow
(rs (* 20 (C (* time PI)))) ; right shoulder
)
(move 0 -0.13662 0 (scale 0.5 0.5 0.5 (union
(move 0 -6.1666667 0 (scale 0.016667 -0.016667 -0.016667
(rotate 90 '(0 1 0)
(shade SURF_PLASTIC (rgb 1.5 0.65 .1)
(Robot ls le rs re j k m n)
)
)
))
(move 0 -1 0 (rotate 90 '(0 1 0)
(scale 1.27324 1.27324 0.1
(move 0 0 1 (cylinder))
)
))
)))
)
)

(define figure (def-prim (unicyclist Time)))
;
; generate peano-curve maze with recursive instancing
; D. P. Mitchell 90/06/09.
;

;
; Unit cell of peano-curve maze is slab with origin at O
; and three figures beginning at R0, R1, and R2. There are
; three varieties, where R2 goes forward, turns left, or
; turns right. The final location of R2 will then be F, L,
; or R respectively. The cycle time is 2 seconds.
;
; -2 2 6 10 14
; -2 +---------------------------L---+
;
; 0 O R0 R1 R2 F ----> Z axis
;
; 2 +---------------------------R---+
;

(define eF (def-prim
(bound (union
(move 0 32 6 (scale 2 32 8 (cube)))
(move 0 0 2 (velocity 0 0 2 (figure)))
(move 0 0 6 (velocity 0 0 2 (figure)))
(move 0 0 10 (velocity 0 0 2 (figure)))
))
))

(define eR (def-prim
(bound (union
(move 0 32 6 (scale 2 32 8 (cube)))
(move 0 0 2 (velocity 0 0 2 (figure)))
(move 0 0 6 (velocity 0 0 2 (figure)))
(move 2 0 10 (spin 45 '(0 1 0) (move -2 0 0 (figure))))
))
))

(define eL (def-prim
(bound (union
(move 0 32 6 (scale 2 32 8 (cube)))
(move 0 0 2 (velocity 0 0 2 (figure)))
(move 0 0 6 (velocity 0 0 2 (figure)))
(move -2 0 10 (spin -45 '(0 1 0) (move 2 0 0 (figure))))
))
))

;
; first order peano curves are just made out of edges
;
(define (clock1 turn) (def-prim (bound (union
(eR)
(move 0 0 12 (rotate 90 '(0 1 0) (eR)))
(move 12 0 12 (rotate 180 '(0 1 0) (turn)))
))))

(define clock1R (clock1 eR))
(define clock1F (clock1 eF))
(define clock1L (clock1 eL))

(define (counter1 turn) (def-prim (bound (union
(move 12 0 0 (eL))
(move 12 0 12 (rotate -90 '(0 1 0) (eL)))
(move 0 0 12 (rotate -180 '(0 1 0) (turn)))
))))

(define counter1R (counter1 eR))
(define counter1F (counter1 eF))
(define counter1L (counter1 eL))

;
; higher order peano curves are build out of edges and
; lower order curves
;
; six curves are needed at each order, three going clockwise
; and three counterclockwise and the figures turning left, right
; or going straight as they leave the curve.
;
(define (clockWise size quad1 edge1 quad2 edge2 quad3 edge3 quad4)
(def-prim (bound (union
(move 0 0 size (rotate 90 '(0 1 0) (quad1)))
(move 0 0 size (edge1))
(move 0 0 (+ 12 size) (quad2))
(move size 0 (+ 12 size) (rotate 90 '(0 1 0) (edge2)))
(move (+ 12 size) 0 (+ 12 size) (quad3))
(move (+ 12 size size) 0 (+ 12 size) (rotate 180 '(0 1 0) (edge3)))
(move (+ 12 size size) 0 0 (rotate -90 '(0 1 0) (quad4)))
)))
)

(define (counterWise size quad1 edge1 quad2 edge2 quad3 edge3 quad4)
(def-prim (bound (union
(move 0 0 size (rotate 90 '(0 1 0) (quad1)))
(move 0 0 (+ 12 size) (rotate 180 '(0 1 0) (edge1)))
(move 0 0 (+ 12 size) (quad2))
(move (+ 12 size) 0 (+ 12 size) (rotate -90 '(0 1 0) (edge2)))
(move (+ 12 size) 0 (+ 12 size) (quad3))
(move (+ 12 size size) 0 size (edge3))
(move (+ 12 size size) 0 0 (rotate -90 '(0 1 0) (quad4)))
)))
)

(define (oddPeanos size primitives) (let
(
(cR (car primitives))
(cF (car (cdr primitives)))
(cL (car (cdr (cdr primitives))))
(ccR (car (cdr (cdr (cdr primitives)))))
(ccF (car (cdr (cdr (cdr (cdr primitives))))))
(ccL (car (cdr (cdr (cdr (cdr (cdr primitives)))))))
)
(list
(clockWise size ccF eR cF eF cR eF ccR)
(clockWise size ccF eR cF eF cR eF ccF)
(clockWise size ccF eR cF eF cR eF ccL)
(counterWise size cR eF ccL eF ccF eL cF)
(counterWise size cF eF ccL eF ccF eL cF)
(counterWise size cL eF ccL eF ccF eL cF)
)
))

(define (evenPeanos size primitives) (let
(
(cR (car primitives))
(cF (car (cdr primitives)))
(cL (car (cdr (cdr primitives))))
(ccR (car (cdr (cdr (cdr primitives)))))
(ccF (car (cdr (cdr (cdr (cdr primitives))))))
(ccL (car (cdr (cdr (cdr (cdr (cdr primitives)))))))
)
(list
(clockWise size ccR eF cL eL cF eR ccR)
(clockWise size ccR eF cL eL cF eR ccF)
(clockWise size ccR eF cL eL cF eR ccL)
(counterWise size cR eL ccF eR ccR eF cL)
(counterWise size cF eL ccF eR ccR eF cL)
(counterWise size cL eL ccF eR ccR eF cL)
)
))

(define (peano n size odd even primitives)
(if (= n 1)
;
; return clockwise forward version
;
(let ((curve (car (cdr primitives)))) (curve))
(peano
(- n 1)
(+ 12 size size)
even odd ; swap even and odd
(even size primitives)
)
)
)

(define (peanoCurve n)
(peano n 12 oddPeanos evenPeanos
(list clock1R clock1F clock1L
counter1R counter1F counter1L
)
)
)

(define (peanoSize n)
(if (= n 0)
0
(+ 12 (* 2 (peanoSize (- n 1))))
)
)

(define CHECKER (surface MASK_CHECKER SURF_MATTE BUMP_FLAT SURF_MATTE BUMP_FLAT
0 0))

(globals (rgb 0 0 0) 0.05 0.0)

(render (cine 256 256 1) (union
(move -100 -4000 -1000 (light 4400))
; (move -4000 -1000 -1000 (light 250))
(move 6 -14 6 (rotate 45 '(0 1 0) (rotate -10 '(1 0 0) (move 0 0 -50
(scale 12 12 40 (camera))
))))

(scale 2 2 2
(move 0 0.125 0 (scale 0.5 0.5 0.5 (peanoCurve 5)))
)
))

Advertisements