[racket] use plot as render in universe
Sorry I'm late. :D
You can make your plots more robust to "can't determine bounds" errors
by including an `invisible-rect' or `invisible-rect3d' renderer in the
plot, with fully specified (i.e. non-#f) bounds. The plots' bounds will
always include the invisible rectangle.
Another option is to explicitly pass #:x-min, #:x-max, etc. keyword
arguments to `plot'. Any bounds you set that way will be fixed.
Do you mind if I ask what you're up to?
Neil ⊥
On 08/11/2013 01:40 PM, J G Cho wrote:
> Thanks for the assurance. It helped me to focus on my
> world->list-of-vectors It turns out it did not return enough vectors (at
> least 2, I think) for initial-world.
>
>
>
>
> On Sun, Aug 11, 2013 at 12:34 PM, Matthias Felleisen
> <matthias at ccs.neu.edu <mailto:matthias at ccs.neu.edu>> wrote:
>
>
> On Aug 10, 2013, at 7:04 PM, J G Cho wrote:
>
>> I get an error (somewhat expectedly) when I try
>>
>> (big-bang init
>> (on-tick random-walk 1)
>> ;(on-key door-actions)
>> (to-draw plot-render)
>> ))
>>
>> where plot-render is defined as
>>
>> (define (plot-render world)
>> (p:plot (p:lines
>> (world->list-of-vectors world)
>> #:color 6 #:label "Random walk")))
>>
>> with the following at the top
>>
>> (require (prefix-in p: plot))
>>
>> The error msg is
>>
>> plot: could not determine sensible plot bounds; got x ∈ [0,0], y ∈
>> [1,1]
>>
>> Is there way to let plot know of the context? Or pass a context to
>> plot and extract the pixels and hand it over to via some proc in
>> 2htdp/image? Or maybe there is a simple way?
>
>
> This works like a charm for me:
>
> #lang racket
>
> (require (prefix-in p: plot) 2htdp/universe)
>
> (define (plot-render world)
> (p:plot (p:lines (world->list-of-vectors world)
> #:color 6 #:label "Random walk")))
>
> (define (world->list-of-vectors world)
> `(#(1 3) #(2 -2) #(4 3)))
>
> (define (random-walk world)
> 'more-dummy)
>
> (big-bang 'dummy ; init
> (on-tick random-walk 1)
> (to-draw plot-render))
>
> ;; ---
>
> When I had a student implement the first plot version, I
> intentionally made sure that plot returned something I could use in
> big-bang.
>
> And btw, this works too:
>
> #lang racket
>
> (require (prefix-in p: plot) 2htdp/universe 2htdp/image)
>
> (define (plot-render world)
> (overlay
> (p:plot (p:lines (world->list-of-vectors world)
> #:color 6 #:label "Random walk"))
> (square 800 'solid 'blue)))
>
> (define (world->list-of-vectors world)
> `(#(1 3) #(2 -2) #(4 3)))
>
> (define (random-walk world)
> 'more-dummy)
>
> (big-bang 'dummy ; init
> (on-tick random-walk 1)
> (to-draw plot-render))
>
>
>
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>