(define turtle-draw! (lambda (turtle distance turn counter width n) (if (> counter 80) (turtle-down! turtle)) (cond ((< (* distance counter) (* width 80)) (turtle-forward! turtle distance) (turtle-turn! turtle turn) (turtle-draw! turtle distance (modulo (+ n turn) 80) (+ counter 1) width (+ (* n 2) 1))) (else (display "turtle is finnished!") (newline))))) (define go-go-go! (lambda (canvas n) (let ((width (image-width canvas)) (height (image-height canvas))) (image-compute-pixels! canvas 0 0 (- (image-width canvas) 1) (- (image-height canvas) 1) (lambda (pos) (let* ((xpos (position-col pos)) (ypos (position-row pos)) (xin (* xpos (/ 3 width))) (yin (* ypos (/ 3 height))) (zval (* (+ (- (* xin xin xin) (* 3 xin)) (- (* yin yin yin) (* 3 yin))) (cos (* xin yin yin (+ (modulo n 2) 1)))))) (cond ((and (< zval (* 5.5 (sqrt (/ n 27)))) (> zval (* 4.5 (sqrt (/ n 27))))) (rgb-new (* 200 (/ xpos width)) (* 100 (/ ypos height)) 0)) ((and (> zval (* -5.5 (sqrt (/ n 27)))) (< zval (* -4.5 (sqrt (/ n 27))))) (rgb-new (* (* 100 (/ (mod n 28) 27)) (/ xpos width)) 0 (* (* 200 (/ (mod n 28) 27)) (/ ypos height)))) ((negative? zval) (rgb-new 0 (/ (abs (* 44 zval)) 2) 0)) (else (rgb-new 0 0 (/ (abs (* 44 zval)) 2)))))))))) (define circle-draw! (lambda (canvas xcent ycent rad type) (image-select-ellipse! canvas type (- xcent rad) (- ycent rad) (* 2 rad) (* 2 rad)))) (define symbol! (lambda (canvas n width height) (context-set-fgcolor! (rgb-new (+ (modulo (* n n) 100) 100) (modulo (* n n n) 68) (modulo (* n n n) 250))) (define rad (quotient (quotient (+ height width) 2) 20)) (circle-draw! canvas (quotient width 2) (quotient height 2) rad selection-add) (context-set-brush! "Sparks") (image-stroke! canvas) ;(image-stroke! canvas) (image-select-nothing! canvas) (context-update-displays!) )) (define image-series (lambda (n width height) (define n (+ n 1)) (define canvas (image-new width height)) (image-show canvas) ;***********************sets up turtle (define distance (+ (* (+ (modulo n 2) 1) (/ width 40)) 1)) (define pen1 (turtle-new canvas)) (turtle-teleport! pen1 (+ (modulo n (quotient width 3)) (quotient width 6)) (+ (modulo n (quotient height 3)) (quotient height 6))) (turtle-set-color! pen1 (rgb-new 255 255 255)) ;***********************sets up turtle ;@@@@@@@@@@@@@@@@@@@@@@@renders background (display "Rendering background") (newline) ;(define layer (image-get-drawable canvas)) ;(drawable-begin-caching! layer) ;(go-go-function! canvas layer 0 0 n width height) ;(drawable-end-caching! layer) (go-go-go! canvas n) (display "Background complete!") (newline) ;@@@@@@@@@@@@@@@@@@@@@@@renders background ;&&&&&&&creates small shape (symbol! canvas n width height) ;&&&&&&&creates small shape ;******************runs turtle (turtle-up! pen1) (turtle-draw! pen1 distance 0 0 width n) ;******************runs turtle (define n (- n 1)) ;(display n) (if (or (equal? n 2) (equal? n 4) (equal? n 8) (equal? n 16) (equal? n 32) (equal? n 64) (equal? n 128) (equal? n 256) (equal? n 512) (equal? n 1024) (equal? n 2048) (equal? n 4096)) (((image-transform! canvas rgb-complement)))) (display "COMPLETE!") ;occassionally, an image will create successfully, but the next will not. Its sometimes necessary to hit the run button ;between images. I'm not sure why. Everything should take between 5 and 10 minutes for a desktop background size image (thanks in large part to help from Sam Rebelsky in the efficiency department) (newline) ))