Skip to content

Frtime to racket #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 57 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
669d950
Change require from mzlib/class to racket/class.
paddymahoney Aug 3, 2012
5fdb596
Change lang of struct.rkt from scheme/base to racket/base.
paddymahoney Aug 3, 2012
0574596
Require racket/struct-info instead of scheme/struct-info.
paddymahoney Aug 3, 2012
9c04c9f
Update syntax and template requires to use racket/base
paddymahoney Aug 3, 2012
8a96aef
Require syntax/struct instead of frtime/struct
paddymahoney Aug 3, 2012
74c6982
Refactor mzlib/list syntax require into two Racket requires.
paddymahoney Aug 3, 2012
b70ac1b
Explicitly import identifiers from syntax/struct.
paddymahoney Aug 3, 2012
a6195ef
Require imports from frtime/core/frp explicitly
paddymahoney Aug 3, 2012
b24aff0
Remove srfi/43/vector-lib dependency in favor of racket/vector
paddymahoney Aug 3, 2012
a3356d2
Remove srfi/43/vector-lib dependency
paddymahoney Aug 3, 2012
61b5315
Reduce dependency on mzlib/etc requires.
paddymahoney Aug 3, 2012
96c6b5b
Reorder and cleanup requires in lang-core.rkt.
paddymahoney Aug 3, 2012
f9201b1
Reorder provides in lang-core.rkt
paddymahoney Aug 3, 2012
d2fdd61
Move lang-ext.rkt to racket/base lang
paddymahoney Aug 3, 2012
3bb0c24
Remove scheme/bool dependency
paddymahoney Aug 3, 2012
5338de9
Remove scheme/list dependency in favor of racket/list
paddymahoney Aug 3, 2012
e054254
Remove mzlib/etc dependency
paddymahoney Aug 3, 2012
2b6e602
Remove scheme/list, scheme/base requires for-syntax
paddymahoney Aug 3, 2012
dc90540
Explicit requires from frtime/core/frp
paddymahoney Aug 3, 2012
857df11
Small provides cleanup.
paddymahoney Aug 3, 2012
c4aef82
Begin transition to racket lang in lang-utils.rkt
paddymahoney Aug 3, 2012
936ab22
Require racket/match instead of mzlib/match
paddymahoney Aug 3, 2012
1d05608
Switch instances of mzlib/list to racket/list
paddymahoney Aug 3, 2012
e90a51e
Remove unnecessary require
paddymahoney Aug 14, 2012
a0de69e
Remove mzlib/list require from gui.rkt
paddymahoney Aug 14, 2012
44ee83f
Remove unnecessary gui.rkt imports.
paddymahoney Aug 14, 2012
0a5337f
Move date.rkt to racket lang.
paddymahoney Aug 14, 2012
7f3a015
Use racket for syntax in animation.rkt
paddymahoney Aug 14, 2012
4af5cd0
Use racket lang for graphics.rkt
paddymahoney Aug 14, 2012
4d16bc1
Move graphics-posn-less to lang racket
paddymahoney Aug 15, 2012
ce2a7a6
Move graphics-sig.rkt to racket lang.
paddymahoney Aug 15, 2012
076567c
Move graphics-unit.rkt to racket lang.
paddymahoney Aug 15, 2012
2b21840
Move core to racket lang.
paddymahoney Aug 15, 2012
13d59f8
Move the gui modules to lang racket
paddymahoney Aug 15, 2012
cba7001
Big Commit that introduces the freeze in demos relying on animation
paddymahoney Aug 16, 2012
8b2a8b6
Add the helper to begin developing frtime
paddymahoney Aug 17, 2012
5e92c3b
Change all instances of make-hash to make-hasheq
paddymahoney Aug 21, 2012
c25f927
Use lifted Racket math definitions
paddymahoney Aug 21, 2012
bca99a7
Remove mzlib opt-lambda uses
paddymahoney Aug 21, 2012
ab94122
Remove opt-lambda uses, unused imports
paddymahoney Aug 21, 2012
8121e55
Remove unnecessary frtime/frlibs/etc import.
paddymahoney Aug 21, 2012
df7d5ea
Use racket/class in lieu of mzlib/class
paddymahoney Aug 21, 2012
69a579f
Remove mzlib/etc require
paddymahoney Aug 21, 2012
f83e24e
Revert to frtime/struct
paddymahoney Aug 21, 2012
168535f
Move tetris.rkt to racket frtime
paddymahoney Aug 21, 2012
d65d1a6
Use racket for the Dr Racket tool info
paddymahoney Aug 21, 2012
67447a7
Update the scribbling-frtime extends Racket now
paddymahoney Aug 21, 2012
386d976
Remove mzlib/etc import
paddymahoney Aug 21, 2012
bfb2b89
require racket async-channel instead of scheme
paddymahoney Aug 21, 2012
2922da9
Remove mzlib/match dependency
paddymahoney Aug 21, 2012
089d663
Responding to Gregory Cooper's github comments.
paddymahoney Aug 23, 2012
c8c74af
End file at a newline char.
paddymahoney Aug 23, 2012
6eaf70e
Implement Gregory Cooper's changes
paddymahoney Aug 23, 2012
c6541ea
Implement Gregory Cooper's suggested changes
paddymahoney Aug 23, 2012
760861e
Implement changes suggested by Gregory Cooper
paddymahoney Aug 23, 2012
ea67ac3
Apply Gregory Cooper's changes
paddymahoney Aug 23, 2012
1b7fea7
Apply Gregory Cooper's suggestions
paddymahoney Aug 23, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 63 additions & 65 deletions collects/frtime/animation.rkt
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
(module animation frtime

(require (all-except frtime/animation/graphics
make-posn posn-x posn-y make-rgb)
(lifted frtime/animation/graphics
posn-x posn-y make-posn make-rgb)
mzlib/match
(require (for-syntax racket/base (only-in racket/function identity))
racket/match
racket/class
(except-in frtime/animation/graphics make-posn posn-x posn-y make-rgb)
(lifted (only-in frtime/animation/graphics posn-x) posn-x)
(lifted (only-in frtime/animation/graphics posn-y) posn-y)
(lifted (only-in frtime/animation/graphics make-posn) make-posn)
(lifted (only-in frtime/animation/graphics make-rgb) make-rgb)
(as-is:unchecked frtime/lang-ext lift)
mzlib/class
frtime/frlibs/list
frtime/frlibs/etc
frtime/frlibs/math
(rename mzscheme mz:define-struct define-struct))

(require-for-syntax mzlib/etc)
frtime/frlibs/math)

(open-graphics)

(define fresh-anim
(let ([first #t])
(opt-lambda ([x 400] [y 400] [title "Animation - DrRacket"])
(lambda ([x 400] [y 400] [title "Animation - DrRacket"])
(if first
(set! first #f)
(begin
Expand All @@ -41,7 +39,7 @@
(set! left-clicks ((viewport-mouse-events window) . =#> . (lambda (ev) (send ev button-down? 'left))))
(set! middle-clicks ((viewport-mouse-events window) . =#> . (lambda (ev) (send ev button-down? 'middle))))
(set! right-clicks ((viewport-mouse-events window) . =#> . (lambda (ev) (send ev button-down? 'right)))))))))

(define window
(open-viewport "Animation - DrRacket" 400 400))

Expand Down Expand Up @@ -75,7 +73,7 @@
(syntax-case stx ()
[(_ name (field ...))
(with-syntax
([ctor-name (datum->syntax-object stx (string->symbol (format "make-~a" (syntax-e #'name))))]
([ctor-name (datum->syntax stx (string->symbol (format "make-~a" (syntax-e #'name))))]
[(accessor-name ...)
(map (lambda (fd)
(string->symbol (format "~a-~a" (syntax-e #'name) (syntax-e fd))))
Expand Down Expand Up @@ -104,11 +102,11 @@

(define (prep-image file)
(draw-pixmap-posn file))

(define (make-circle center r color)
(make-solid-ellipse (make-posn (- (posn-x center) r)
(- (posn-y center) r))
(* 2 r) (* 2 r) color))
(* 2 r) (* 2 r) color))

(define l (new-cell empty))

Expand Down Expand Up @@ -136,7 +134,7 @@
(lambda (v)
(match (v-n v)
[(? undefined?) (void)]
[($ ring center radius color)
[(ring center radius color)
(let ([center (v-n center)]
[radius (v-n radius)]
[color (v-n color)])
Expand All @@ -148,25 +146,25 @@
(* 2 radius)
(* 2 radius)
(if (undefined? color) "black" color))))]
[($ arc pos width height start-radians end-radians color)
[(arc pos width height start-radians end-radians color)
(let ([pos (v-n pos)]
[width (v-n width)]
[height (v-n height)]
[start-radians (v-n start-radians)]
[end-radians (v-n end-radians)])
((draw-arc pixmap) pos width height start-radians end-radians color))]
[($ solid-arc pos width height start-radians end-radians color)
[(solid-arc pos width height start-radians end-radians color)
(let ([pos (v-n pos)]
[width (v-n width)]
[height (v-n height)]
[start-radians (v-n start-radians)]
[end-radians (v-n end-radians)])
((draw-solid-arc pixmap) pos width height start-radians end-radians color))]
[($ image pos renderer)
[(image pos renderer)
(let ([renderer (v-n renderer)]
[pos (v-n pos)])
((renderer pixmap) pos))]
[($ solid-ellipse ul w h color)
[(solid-ellipse ul w h color)
(let ([ul (v-n ul)]
[w (v-n w)]
[h (v-n h)]
Expand All @@ -175,26 +173,26 @@
(undefined? w)
(undefined? h))
((draw-solid-ellipse pixmap) ul w h (if (undefined? color) "black" color))))]
[($ graph-string pos text color) ((draw-string pixmap) (v-n pos) (v-n text) (v-n color))]
[($ line p1 p2 color)
[(graph-string pos text color) ((draw-string pixmap) (v-n pos) (v-n text) (v-n color))]
[(line p1 p2 color)
(let ([p1 (v-n p1)]
[p2 (v-n p2)]
[color (v-n color)])
(unless (or (undefined? p1)
(undefined? p2))
((draw-line pixmap) p1 p2 (if (undefined? color) "black" color))))]
[($ rect ul w h color)
[(rect ul w h color)
(let ([ul (v-n ul)]
[w (v-n w)]
[h (v-n h)]
[color (v-n color)])
(cond
[(and (>= w 0) (>= h 0)) ((draw-solid-rectangle pixmap) ul w h color)]
[(>= h 0) ((draw-solid-rectangle pixmap) (make-posn (+ (posn-x ul) w) (posn-y ul)) (- w) h color)]
[(>= w 0) ((draw-solid-rectangle pixmap) (make-posn (posn-x ul) (+ (posn-y ul) h)) w (- h) color)]
[else ((draw-solid-rectangle pixmap) (make-posn (+ (posn-x ul) w) (+ (posn-y ul) h)) (- w) (- h) color)]))]
[($ polygon pts offset color) ((draw-polygon pixmap) pts offset color)]
[($ solid-polygon pts offset color) ((draw-solid-polygon pixmap) pts offset color)]
(cond
[(and (>= w 0) (>= h 0)) ((draw-solid-rectangle pixmap) ul w h color)]
[(>= h 0) ((draw-solid-rectangle pixmap) (make-posn (+ (posn-x ul) w) (posn-y ul)) (- w) h color)]
[(>= w 0) ((draw-solid-rectangle pixmap) (make-posn (posn-x ul) (+ (posn-y ul) h)) w (- h) color)]
[else ((draw-solid-rectangle pixmap) (make-posn (+ (posn-x ul) w) (+ (posn-y ul) h)) (- w) (- h) color)]))]
[(polygon pts offset color) ((draw-polygon pixmap) pts offset color)]
[(solid-polygon pts offset color) ((draw-solid-polygon pixmap) pts offset color)]
[(? list? x) (loop (v-n x))]
[(? void?) (void)]))
a-los v-n)))
Expand All @@ -206,7 +204,7 @@
(define (draw-graph-color pm gc)
(let ([dp (draw-pixel pm)])
(match gc
[($ graph-color fn xmin xmax ymin ymax)
[(graph-color fn xmin xmax ymin ymax)
(let ([xincr (/ (- xmax xmin) 300)]
[yincr (/ (- ymax ymin) 300)])
(let loop ([i 50] [y ymin])
Expand All @@ -220,7 +218,7 @@
(define (valid-posn? v)
(and (posn? v) (number? (posn-x v)) (number? (posn-y v))))



(define (key sym)
(key-strokes
Expand All @@ -230,23 +228,23 @@
(define (draw vp pm posl)
((clear-viewport pm))
(for-each (lambda (elt)
(cond
[(graph-color? elt) (draw-graph-color pm elt)]
[(string? elt) ((draw-string pm) (make-posn 8 20) elt)]
[(valid-posn? elt) ((draw-solid-ellipse pm)
(make-posn (- (posn-x elt) 10)
(- (posn-y elt) 10))
20 20
(make-rgb 0 .6 .6))]
[(and (cons? elt)
(valid-posn? (first elt))
(valid-posn? (rest elt))) ((draw-line pm)
(first elt)
(rest elt)
"black")]
[else (void)])) posl)
(cond
[(graph-color? elt) (draw-graph-color pm elt)]
[(string? elt) ((draw-string pm) (make-posn 8 20) elt)]
[(valid-posn? elt) ((draw-solid-ellipse pm)
(make-posn (- (posn-x elt) 10)
(- (posn-y elt) 10))
20 20
(make-rgb 0 .6 .6))]
[(and (cons? elt)
(valid-posn? (first elt))
(valid-posn? (rest elt))) ((draw-line pm)
(first elt)
(rest elt)
"black")]
[else (void)])) posl)
(copy-viewport pm vp))

#|
(define foldl
(case-lambda
Expand Down Expand Up @@ -275,9 +273,9 @@
(define (fix-rgb r g b)
(let ([fix (lambda (n) (min 1 (max 0 n)))])
(apply make-rgb (map fix (list r g b)))))

(define range-control
(opt-lambda (up down limit [init 0])
(lambda (up down limit [init 0])
(accum-b
(merge-e (up . -=> . (inc-max limit))
(down . -=> . (dec-min 0)))
Expand All @@ -301,9 +299,9 @@
(make-wave-state (value-now hz) 0)
(lambda (new-freq+time old-state)
(match new-freq+time
[(h1 t)
[(list h1 t)
(match old-state
[($ wave-state h0 o0)
[(wave-state h0 o0)
(make-wave-state
h1
(+ o0 (* .002 pi t (- h0 h1))))])])))])
Expand All @@ -320,14 +318,14 @@
(define (last-value signal)
(second (current-and-last-value signal)))

; (define (last-value signal)
; (let ([init (value-now signal)])
; (rest
; (collect-b (changes signal)
; (cons init init)
; (lambda (new old-pair)
; (cons new (first old-pair)))))))
; (define (last-value signal)
; (let ([init (value-now signal)])
; (rest
; (collect-b (changes signal)
; (cons init init)
; (lambda (new old-pair)
; (cons new (first old-pair)))))))

(define (posn+ . args)
(make-posn (apply + (map posn-x args))
(apply + (map posn-y args))))
Expand Down Expand Up @@ -367,14 +365,14 @@
(define (posn-diff p1 p2)
(sqrt (+ (sqr (- (posn-x p1) (posn-x p2)))
(sqr (- (posn-y p1) (posn-y p2))))))

(define (posn-derivative p)
(make-posn (derivative (posn-x p)) (derivative (posn-y p))))

(define (posn-integral p)
(make-posn (integral (posn-x p)) (integral (posn-y p))))

(provide
(all-defined-except pixmap window draw-list l d
make-wave-state wave-state-hz wave-state-offset)
(all-from frtime/animation/graphics)))
(except-out (all-defined-out) pixmap window draw-list l d
make-wave-state wave-state-hz wave-state-offset)
(all-from-out frtime/animation/graphics)))
Loading