Created
October 27, 2012 04:48
-
-
Save nodename/3962971 to your computer and use it in GitHub Desktop.
Racket program to create image sequence morphing from eight-petal rose to Lissajous curve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require plot) | |
(require plot/utils) | |
(define (plot-zeros-to-file xy-function file-name epsilon) | |
(parameterize ([plot-x-axis? #f] | |
[plot-x-label #f] | |
[plot-x-far-axis? #f] | |
[plot-y-axis? #f] | |
[plot-y-label #f] | |
[plot-y-far-axis? #f] | |
[plot-foreground (->color 'white)] | |
[plot-background (->color 'black)]) | |
(call-with-output-file file-name | |
#:exists 'truncate | |
(λ (out) | |
(plot-file (contours xy-function -2 2 -2 2 #:samples 600 #:levels (list (- epsilon) epsilon) #:colors '("white" "white")) out 'svg))))) | |
#! polynomial equivalent of { x = cos 3t, y = sin 2t } | |
(define (lissajous-three-two x y) | |
(+ (- (- (+ (* 16 (expt y 6)) (* 4 (expt x 4))) (* 24 (expt y 4))) (* 4 (expt x 2))) (* 9 (expt y 2)))) | |
#! polynomial equivalent of r = cos 4θ | |
(define (eight-petal-rose x y) | |
(let* ([xsq (* x x)] | |
[ysq (* y y)] | |
[ z (+ xsq ysq)] | |
[ w (+ (- (* xsq xsq) (* 6 xsq ysq)) (* ysq ysq))]) | |
(- (expt z 5) (* w w)))) | |
(define (lerp t f g) | |
(λ (x y) | |
(let ([a (f x y)] | |
[b (g x y)]) | |
(+ (* (- 1 t) a) (* t b))))) | |
(define epsilon .0000000000000000000000001) | |
#! We use epsilon because plot-file contours shows nothing for the exact zeroes of eight-petal-rose | |
(define (lerp-curves-step step of) | |
(plot-zeros-to-file (lerp (/ step of) eight-petal-rose lissajous-three-two) (string-append (number->string step) ".svg") epsilon)) | |
(define (lerp-curves first last) | |
(map (λ (step) (lerp-curves-step step 1000)) (range first (+ 1 last)))) | |
(lerp-curves (- 1500) 1500) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment