Recently I've been playing around with generating Scalable Vector Graphics in Arc. The code can be found at http://github.com/skenney26/sarc/tree/master/svg.arc For SVG to display properly the content-type of the document needs to be set to xhtml rather than html. For these examples header* in srv.arc needs to be changed to: (= header* "HTTP/1.0 200 OK
Content-Type: application/xhtml+xml; charset=utf-8
Connection: close")
(If you're using the anarki version you'll need to change textmime* instead. Btw, I downloaded anarki on saturday and had to comment out ffi.scm from as.scm and ffi.arc from lib.arc in order to make everything work. I don't know if this is still an issue.)Then just (load "svg.arc") and run (asv) to view the following examples in your browser (http://localhost:8080/...). (These examples have been tested in Firefox, Safari, and Opera.) Display a blue circle: (defop circle req
(svgpage
(svg (svg width 400 height 400)
(svg (circle cx 200 cy 200 r 50 fill 'blue)))))
This can be shortened (but it won't work properly in Opera) to: (svgop circle2
(circle 200 200 50 "#00ff00"))
Display several circles with random positions, colors, and opacities: (defop circles req
(svgpage
(svg (svg width 500 height 500)
(repeat 20
(svg (circle cx (rand-range 100 400)
cy (rand-range 100 400)
r (rand-range 10 70)
fill (rand-hex-color)
opacity (num (/ (rand-range 4 8) 10))))))))
Display several rectangles in a row with random colors: (defop rects req
(svgpage
(svg (svg width 800 height 600)
(for i 1 20
(svg (rect x (* i 10) y (* i 10)
width 40 height 40
fill (rand-hex-color)
opacity .5))))))
There's alot more that can be added to this library. Over the next few weeks I'll add support for lines, patterns, transformations, etc. |