[racket-users] Science graphics with Racket?
I'd like to use Racket to generate scalable (svg?) graphics like gnuplot or GeoGebra does. For example, I'd like to create a cartesian coordinate graph system, then draw functions on it. One thing in particular would be to draw a graph of a circle based on the standard form of a circle, e.g., x^2 + y^2 = r^2. Again, I'd prefer being able to create an svg file. Is there a tutorial that might give me more insight than the reference pages or the Quick: An Introduction to Racket with Pictures? Or am I barking up the wrong tree? LB -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Science graphics with Racket?
Here is how to do it using MetaPict: #lang racket (require racket/draw metapict) (set-curve-pict-size 300 300) ; width and height of image (ahlength 1.0); size of arrow head (define p (with-window (window -12 12 -12 12) ; xmin, xmax, ymin, ymax (draw (draw-arrow (curve (pt -10 0) -- (pt 10 0))) ; x-axis (draw-arrow (curve (pt 0 -10) -- (pt 0 10))) ; y-axis (label-rt "x" (pt 10.2 0)) ; label for x axis (label-top "y" (pt 0 10.2)) ; label for y axis (circle (pt 2 1) 3 ; center (2,1) radius 3 p ; show pict in repl (define (save-pict-as-svg p width height filename [exists 'replace]) (define dc (new svg-dc% [width width] [height height] [output filename] [exists exists])) (send dc start-doc "An SVG Test") ; a message (send dc start-page) (draw-pict p dc 0 0) (send dc end-page) (send dc end-doc)) (save-pict-as-svg p 300 300 "output.svg") 2017-10-23 21:04 GMT+02:00 Lawrence Bottorff : > I'd like to use Racket to generate scalable (svg?) graphics like gnuplot > or GeoGebra does. For example, I'd like to create a cartesian coordinate > graph system, then draw functions on it. One thing in particular would be > to draw a graph of a circle based on the standard form of a circle, e.g., > x^2 + y^2 = r^2. Again, I'd prefer being able to create an svg file. Is > there a tutorial that might give me more insight than the reference pages > or the Quick: An Introduction to Racket with Pictures? Or am I barking up > the wrong tree? > > LB > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- -- Jens Axel Søgaard -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Science graphics with Racket?
On Mon, Oct 23, 2017 at 3:04 PM, Lawrence Bottorff wrote: > I'd like to use Racket to generate scalable (svg?) graphics like gnuplot or > GeoGebra does. For example, I'd like to create a cartesian coordinate graph > system, then draw functions on it. One thing in particular would be to draw > a graph of a circle based on the standard form of a circle, e.g., x^2 + y^2 > = r^2. Again, I'd prefer being able to create an svg file. Is there a > tutorial that might give me more insight than the reference pages or the > Quick: An Introduction to Racket with Pictures? Or am I barking up the wrong > tree? > > LB > Hi Lawrence, Have you looked at the plot library? [https://docs.racket-lang.org/plot/] - Jon -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Science graphics with Racket?
I forgot to show how to make a graph. #lang racket (require racket/draw metapict metapict/graph) (set-curve-pict-size 300 300) ; width and height of image (ahlength 1.0); size of arrow head (define (f x) (sin x)) (define p (with-window (window -12 12 -12 12) ; xmin, xmax, ymin, ymax (draw (draw-arrow (curve (pt -10 0) -- (pt 10 0))) ; x-axis (draw-arrow (curve (pt 0 -10) -- (pt 0 10))) ; y-axis (label-rt "x" (pt 10.2 0)) ; label for x axis (label-top "y" (pt 0 10.2)) ; label for y axis (color "blue" (draw (circle (pt 2 1) 3))); center (2,1) radius 3 (color "red" (draw (graph f -10 10 #:samples 50)) p ; show pict in repl (define (save-pict-as-svg p width height filename [exists 'replace]) (define dc (new svg-dc% [width width] [height height] [output filename] [exists exists])) (send dc start-doc "An SVG Test") ; a message (send dc start-page) (draw-pict p dc 0 0) (send dc end-page) (send dc end-doc)) (save-pict-as-svg p 300 300 "output.svg") 2017-10-23 21:39 GMT+02:00 Jens Axel Søgaard : > Here is how to do it using MetaPict: > > #lang racket > (require racket/draw metapict) > > (set-curve-pict-size 300 300) ; width and height of image > (ahlength 1.0); size of arrow head > > (define p > (with-window (window -12 12 -12 12) ; xmin, xmax, ymin, ymax > (draw (draw-arrow (curve (pt -10 0) -- (pt 10 0))) ; x-axis > (draw-arrow (curve (pt 0 -10) -- (pt 0 10))) ; y-axis > (label-rt "x" (pt 10.2 0)) ; label for x > axis > (label-top "y" (pt 0 10.2)) ; label for y > axis > (circle (pt 2 1) 3 ; center (2,1) > radius 3 > > p ; show pict in repl > > (define (save-pict-as-svg p width height filename [exists 'replace]) > (define dc (new svg-dc% > [width width] > [height height] > [output filename] > [exists exists])) > (send dc start-doc "An SVG Test") ; a message > (send dc start-page) > (draw-pict p dc 0 0) > (send dc end-page) > (send dc end-doc)) > > > > (save-pict-as-svg p 300 300 "output.svg") > > > 2017-10-23 21:04 GMT+02:00 Lawrence Bottorff : > >> I'd like to use Racket to generate scalable (svg?) graphics like gnuplot >> or GeoGebra does. For example, I'd like to create a cartesian coordinate >> graph system, then draw functions on it. One thing in particular would be >> to draw a graph of a circle based on the standard form of a circle, e.g., >> x^2 + y^2 = r^2. Again, I'd prefer being able to create an svg file. Is >> there a tutorial that might give me more insight than the reference pages >> or the Quick: An Introduction to Racket with Pictures? Or am I barking up >> the wrong tree? >> >> LB >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Racket Users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to racket-users+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > -- > Jens Axel Søgaard > > -- -- Jens Axel Søgaard -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-users] Science graphics with Racket?
This is amazing! Thank you very much! On Mon, Oct 23, 2017 at 4:49 PM, Jens Axel Søgaard wrote: > I forgot to show how to make a graph. > > #lang racket > (require racket/draw metapict metapict/graph) > > (set-curve-pict-size 300 300) ; width and height of image > (ahlength 1.0); size of arrow head > > (define (f x) (sin x)) > > (define p > (with-window (window -12 12 -12 12) ; xmin, xmax, ymin, ymax > (draw (draw-arrow (curve (pt -10 0) -- (pt 10 0))) ; x-axis > (draw-arrow (curve (pt 0 -10) -- (pt 0 10))) ; y-axis > (label-rt "x" (pt 10.2 0)) ; label for x > axis > (label-top "y" (pt 0 10.2)) ; label for y > axis > (color "blue" (draw (circle (pt 2 1) 3))); center (2,1) > radius 3 > (color "red" (draw (graph f -10 10 #:samples 50)) > > p ; show pict in repl > > (define (save-pict-as-svg p width height filename [exists 'replace]) > (define dc (new svg-dc% > [width width] > [height height] > [output filename] > [exists exists])) > (send dc start-doc "An SVG Test") ; a message > (send dc start-page) > (draw-pict p dc 0 0) > (send dc end-page) > (send dc end-doc)) > > > > (save-pict-as-svg p 300 300 "output.svg") > > > 2017-10-23 21:39 GMT+02:00 Jens Axel Søgaard : > >> Here is how to do it using MetaPict: >> >> #lang racket >> (require racket/draw metapict) >> >> (set-curve-pict-size 300 300) ; width and height of image >> (ahlength 1.0); size of arrow head >> >> (define p >> (with-window (window -12 12 -12 12) ; xmin, xmax, ymin, ymax >> (draw (draw-arrow (curve (pt -10 0) -- (pt 10 0))) ; x-axis >> (draw-arrow (curve (pt 0 -10) -- (pt 0 10))) ; y-axis >> (label-rt "x" (pt 10.2 0)) ; label for x >> axis >> (label-top "y" (pt 0 10.2)) ; label for y >> axis >> (circle (pt 2 1) 3 ; center (2,1) >> radius 3 >> >> p ; show pict in repl >> >> (define (save-pict-as-svg p width height filename [exists 'replace]) >> (define dc (new svg-dc% >> [width width] >> [height height] >> [output filename] >> [exists exists])) >> (send dc start-doc "An SVG Test") ; a message >> (send dc start-page) >> (draw-pict p dc 0 0) >> (send dc end-page) >> (send dc end-doc)) >> >> >> >> (save-pict-as-svg p 300 300 "output.svg") >> >> >> 2017-10-23 21:04 GMT+02:00 Lawrence Bottorff : >> >>> I'd like to use Racket to generate scalable (svg?) graphics like gnuplot >>> or GeoGebra does. For example, I'd like to create a cartesian coordinate >>> graph system, then draw functions on it. One thing in particular would be >>> to draw a graph of a circle based on the standard form of a circle, e.g., >>> x^2 + y^2 = r^2. Again, I'd prefer being able to create an svg file. Is >>> there a tutorial that might give me more insight than the reference pages >>> or the Quick: An Introduction to Racket with Pictures? Or am I barking up >>> the wrong tree? >>> >>> LB >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Racket Users" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to racket-users+unsubscr...@googlegroups.com. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> -- >> Jens Axel Søgaard >> >> > > > -- > -- > Jens Axel Søgaard > > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.