Skip to content

Latest commit

 

History

History
45 lines (30 loc) · 1.56 KB

README.rdoc

File metadata and controls

45 lines (30 loc) · 1.56 KB

svg_parser README

What is it?

A rubylibrary to read SVG-files (generated with for example inkscape) and convert them easily into coordinates/points. The mainpurpose of this lib is to easily get read out objects from SVGs to use with Gosu / Rubygame / Chipmunk.

You could for example parse out any “path” (Shift+F6) painted in inkscape and then paint it with rubygames #polygon. Therefore bypassing the need to export the SVG to a bitmap, which you then paint. Plus you have the coordinates available for collisiondetection or whatever.

Features:

  • Read out the points of a path

  • Read out the points of a rect

  • Normalize points for any object

  • Convert points to a chipmunk vec2 array with #to_chipmunk

The term “point” here is used for a X,Y pair. svg_parser provides the supportclass Points for this purpose.

Examples:

Basic example:

# Open a SVG-file, get the points for “path” with id @id # Normalize the points/coordinates (meaning the leftmost coordinate will have x=0, same with top) # “boulder” is the uniqe id you set in inkscape @points = SVGParser.new(“inkscape_objects.svg”).path(“boulder”).normalize! # Then the standard chipmunk stuff follows @body = CP::Body.new(Float::MAX, Float::MAX) @shape = CP::Shape::Poly.new(@body, @points.to_chipmunk, CP::Vec2.new(100, 100)) # … etc

The Points-class also adds various other nice things like: points = Points.new(0,0) points.up(10).right(100).up(20).right(20).down(20).right(20).down(10).to(0,0) # This is rubygame-code surface.draw_polygon_s(points, Color)

License

Same as chipmunk.