rasem 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +135 -1
  2. data/VERSION +1 -1
  3. data/lib/rasem/application.rb +0 -1
  4. metadata +3 -3
@@ -1,7 +1,141 @@
1
- = rasem
1
+ = Rasem
2
2
 
3
3
  rasem is a ruby gem that allows you to describe your images in ruby code.
4
4
 
5
+ == Why Rasem
6
+
7
+ * Have you ever wanted to visualize some data in a nice image?
8
+ * Do you want to draw a complex image that is easier to describe using a code?
9
+ * Would you like to power your HTML 5 site with nicely drawn SVG images?
10
+ * Do you need to generate nice images from your ruby code?
11
+
12
+ Rasem allows you to generate SVG images that can be easily exported to other
13
+ formats and embed in an HTML 5 page.
14
+
15
+ == Features
16
+
17
+ * Draw basic elements: line, rectangle, rouned rectangle, circle, ellipse, polygon and polyline.
18
+ * Use SVG styles such as stroke-width, opacity and fill.
19
+ * Create SVG groups for better editing in SVG editors.
20
+
21
+ == Installation
22
+ gem install rasem
23
+
24
+ == Usage
25
+ There are two main methods to generate images with Rasem.
26
+
27
+ === Command line
28
+ Create a file with extension .rasem. Here is a sample file test.rasem
29
+ set_width 100
30
+ set_height 100
31
+ circle 20, 20, 5
32
+ circle 50, 50, 5
33
+ line 20, 20, 50, 50
34
+
35
+ Save this file and execute the command
36
+ rasem test.rasem
37
+
38
+ A file test.svg will be generated.
39
+
40
+ === Ruby code
41
+ You can generate the image from your ruby code. This has several uses such as
42
+ sending the image on the fly from a Rails application.
43
+
44
+ Here is a simple example
45
+ require 'rasem'
46
+ img = Rasem::SVGImage.new(100,100) do
47
+ circle 20, 20, 5
48
+ circle 50, 50, 5
49
+ line 20, 20, 50, 50
50
+ end
51
+
52
+ puts img.output
53
+
54
+ img.output is the SVG code generated for this images.
55
+
56
+ == More Examples
57
+ The following examples are for .rasem files. These are actually ruby
58
+ scripts that are executed to generate the image. So, you can write arbitrary
59
+ ruby code in .rasem files as you will see.
60
+
61
+ simple_graph.rasem
62
+ nodes = [[10,10], [20,20], [10,20]]
63
+ radius = 3
64
+ with_style :fill=>"white", :stroke=>"black" do
65
+ for node in nodes
66
+ circle node.first, node.last, radius
67
+ end
68
+ end
69
+
70
+ line nodes[0].first, nodes[0].last, nodes[1].first, nodes[1].last,
71
+ :stroke=>"blue"
72
+
73
+ Here is a more sophisticated example.
74
+
75
+ tictactoe.rasem
76
+ set_width 150
77
+ set_height 150
78
+ board = [['x','o','x'], ['o', '-', 'o'], ['x', 'o', 'x']]
79
+ def draw_x(x,y)
80
+ group :stroke=>"red" do
81
+ line x-20, y-20, x+20, y+20
82
+ line x-20, y+20, x+20, y-20
83
+ end
84
+ end
85
+
86
+ def draw_o(x,y)
87
+ circle x, y, 20, :stroke=>"blue", :fill=>"white"
88
+ end
89
+
90
+ # Draw the board
91
+ group :stroke=>"black" do
92
+ rectangle 0, 0, 150, 150, :stroke_width=>2, :fill=>"white"
93
+ line 50, 0, 50, 150
94
+ line 100, 0, 100, 150
95
+ line 0, 50, 150, 50
96
+ line 0, 100, 150, 100
97
+ end
98
+
99
+ board.each_with_index do |row, row_index|
100
+ row.each_with_index do |cell, column_index|
101
+ if cell == "x"
102
+ draw_x row_index * 50 + 25, column_index * 50 + 25
103
+ elsif cell == "o"
104
+ draw_o row_index * 50 + 25, column_index * 50 + 25
105
+ end
106
+ end
107
+ end
108
+
109
+ Here are some examples that show how you can generate images from your ruby code.
110
+
111
+ You can generate SVG and store it to file
112
+ img = Rasem::SVGImage.new(100, 100)
113
+ img.line(0, 0, 100, 100)
114
+ img.close
115
+
116
+ File.open("test.svg", w") do |f|
117
+ f << img.output
118
+ end
119
+
120
+ You can use pass a block to SVGImage.new to make things more compact
121
+ img = Rasem::SVGImage.new(100, 100) do
122
+ line(0, 0, 100, 100)
123
+ end
124
+ # Image is closed automatically
125
+ # Write to file
126
+
127
+ You can make your code even more compact by passing the file as a last argument
128
+ to SVGImage.new
129
+ File.open("test.svg", "w") do |f|
130
+ Rasem::SVGImage.new(100, 100, f) do |f|
131
+ line(0, 0, 100, 100)
132
+ end
133
+ end
134
+
135
+ The previous example has another advantage of not buffering the whole image to
136
+ memory before writing to file. Rasem is smart enough to detect that the output
137
+ can be passed directly to the file, hence, saving unnecessary memory buffers.
138
+
5
139
  == Contributing to rasem
6
140
 
7
141
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.5.3
@@ -12,7 +12,6 @@ class Rasem::Application
12
12
  end
13
13
 
14
14
  for source_file in source_files
15
- puts "Source file #{source_file}"
16
15
  if source_file =~ /\.rasem$/
17
16
  svg_file = source_file.sub(/\.rasem$/, '.svg')
18
17
  else
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 2
9
- version: 0.5.2
8
+ - 3
9
+ version: 0.5.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ahmed Eldawy
@@ -112,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
112
  requirements:
113
113
  - - ">="
114
114
  - !ruby/object:Gem::Version
115
- hash: -1380337936267073737
115
+ hash: 1518989641663935495
116
116
  segments:
117
117
  - 0
118
118
  version: "0"