rplot 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,105 @@
1
+ = rplot
2
+
3
+ *rplot* is a C extension for Ruby of GNU libplot.
4
+
5
+ {GNU
6
+ libplot}[http://www.gnu.org/software/plotutils/manual/html_mono/plotutils.html#SEC45]
7
+ is a free function library for drawing two-dimensional vector
8
+ graphics. It can produce smooth, double-buffered animations for the X
9
+ Window System, and can export files in many graphics file formats. It
10
+ is `device-independent' in the sense that its API (application
11
+ programming interface) is to a large extent independent of the display
12
+ type or output format. Rplot is a C extension for Ruby of GNU libplot.
13
+
14
+ == Requirements
15
+
16
+ * libplot-dev
17
+
18
+ For Debian/Ubuntu users: <tt>apt-get install libplot-dev</tt>.
19
+
20
+ For Max OS X users use {port}[http://www.macports.org/]: <tt>port
21
+ install plotutils</tt>.
22
+
23
+ == Installation
24
+
25
+ gem install rplot
26
+
27
+ == Usage
28
+
29
+ Here two little examples.
30
+
31
+ The first invokes rplot operations to draw vector graphics. It draws
32
+ an intricate and beautiful path (Bill Gosper's "C" curve, discussed as
33
+ Item #135 in HAKMEM, MIT Artificial Intelligence Laboratory Memo #239,
34
+ 1972). As the numeric constant MAXORDER (here equal to 12) is
35
+ increased, the path will take on the shape of a curly letter "C",
36
+ which is the envelope of a myriad of epicyclic octagons.
37
+
38
+ require 'rubygems'
39
+ require 'rplot'
40
+
41
+ module MyCurve
42
+ MAXORDER = 12
43
+ def draw_curve(dx, dy, order)
44
+ if order >= MAXORDER
45
+ self.cont(dx, dy, :rel => true)
46
+ else
47
+ self.draw_curve(0.5*(dx-dy), 0.5*(dx+dy), order+1)
48
+ self.draw_curve(0.5*(dx+dy), 0.5*(dy-dx), order+1)
49
+ end
50
+ end
51
+ end
52
+ Plotter.send(:include, MyCurve)
53
+
54
+ Plotter.params(:pagesize => 'letter')
55
+
56
+ Plotter.draw('png', 'RUBYtest3.png')do |p|
57
+ p.space(0,0, 1000,1000)
58
+ p.linewidth(0.25)
59
+ p.pencolor('red')
60
+ p.move(600, 300)
61
+ p.draw_curve(0, 400, 0)
62
+ end
63
+
64
+ The second example creates a simple animated pseudo-GIF, 150 pixels
65
+ wide and 100 pixels high.
66
+
67
+ require 'rubygems'
68
+ require 'rplot'
69
+
70
+ Plotter.params(:bitmapsize => '150x100',
71
+ :bg_color => 'orange',
72
+ :transparent_color => 'orange',
73
+ :gif_iterations => 100,
74
+ :gif_delay => 5)
75
+ p = Plotter.new('gif', 'image.gif')
76
+ p.open
77
+ p.space(0,0,149,99)
78
+ p.pencolor('red')
79
+ p.linewidth(5)
80
+ p.filltype(1)
81
+ p.fillcolor('black')
82
+ i = 0
83
+ while i < 180
84
+ p.erase
85
+ p.erase
86
+ p.ellipse(75,50,40,20,i)
87
+ i += 15
88
+ end
89
+ p.delete
90
+
91
+ <b>{Here the complete documentation with
92
+ API}[http://pioz.github.com/rplot/Plotter.html]</b>.
93
+
94
+ == Questions or problems?
95
+
96
+ If you have any issues with rplot please add an {issue on
97
+ GitHub}[https://github.com/pioz/rplot/issues] or fork the project and
98
+ send a pull request.
99
+
100
+ == Copyright
101
+
102
+ Copyright (c) 2010 Enrico Pilotto. See
103
+ {LICENSE}[http://github.com/pioz/rplot/blob/master/LICENSE] for
104
+ details.
105
+
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/rdoctask'
5
+ Rake::RDocTask.new do |rdoc|
6
+ rdoc.rdoc_dir = 'rdoc'
7
+ rdoc.rdoc_files.include('README*')
8
+ rdoc.main = 'README.rdoc'
9
+ rdoc.options = ["--exclude=lib/rplot/", "--exclude=ext/"]
10
+ end
@@ -0,0 +1,40 @@
1
+ ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
2
+
3
+ require 'mkmf'
4
+
5
+ LIBDIR = Config::CONFIG['libdir']
6
+ INCLUDEDIR = Config::CONFIG['includedir']
7
+
8
+ HEADER_DIRS = [
9
+ # First search /opt/local for macports
10
+ '/opt/local/include',
11
+ # Then search /usr/local for people that installed from source
12
+ '/usr/local/include',
13
+ # Check the ruby install locations
14
+ INCLUDEDIR,
15
+ # Finally fall back to /usr
16
+ '/usr/include',
17
+ ]
18
+
19
+ LIB_DIRS = [
20
+ # First search /opt/local for macports
21
+ '/opt/local/lib',
22
+ # Then search /usr/local for people that installed from source
23
+ '/usr/local/lib',
24
+ # Check the ruby install locations
25
+ LIBDIR,
26
+ # Finally fall back to /usr
27
+ '/usr/lib',
28
+ ]
29
+
30
+ dir_config('rplot', HEADER_DIRS, LIB_DIRS)
31
+
32
+ unless find_header('plot.h')
33
+ abort "libplot is missing. Please install libplot (apt-get install libplot-dev)"
34
+ end
35
+
36
+ unless find_library('plot', 'pl_newpl')
37
+ abort "libplot is missing. Please install libplot (apt-get install libplot-dev)"
38
+ end
39
+
40
+ create_makefile('rplot/rplot')
@@ -0,0 +1,959 @@
1
+ /***********************************************************
2
+ * Copyright (C) 2011 Enrico Pilotto (enrico@megiston.it)
3
+ *
4
+ * Binding all functions of C libplot in 'Rplot' Ruby class.
5
+ ***********************************************************/
6
+
7
+ #include "rplot.h"
8
+
9
+ static int
10
+ get_handler (VALUE self)
11
+ {
12
+ int handler = NUM2INT (rb_iv_get (self, "@handler"));
13
+ if (pl_selectpl (handler) < 0)
14
+ rb_raise(select_plotter_error, "Couldn't select Plotter with id %d!", handler);
15
+ return handler;
16
+ }
17
+
18
+ /* 4 base functions */
19
+
20
+ static VALUE
21
+ newpl (VALUE self, VALUE type, VALUE in_path, VALUE out_path, VALUE err_path)
22
+ {
23
+ FILE *in_file, *out_file, *err_file;
24
+ if (TYPE (in_path) == T_NIL)
25
+ in_file = stdin;
26
+ else
27
+ in_file = fopen (StringValuePtr (in_path), "w");
28
+ if (TYPE (out_path) == T_NIL)
29
+ out_file = stdout;
30
+ else
31
+ out_file = fopen (StringValuePtr (out_path), "w");
32
+ if (TYPE (err_path) == T_NIL)
33
+ err_file = stderr;
34
+ else
35
+ err_file = fopen (StringValuePtr (err_path), "w");
36
+
37
+ int handler = pl_newpl (StringValuePtr (type), stdin, out_file, stderr);
38
+ if (handler < 0)
39
+ rb_raise(create_plotter_error, "Couldn't create Plotter!");
40
+ rb_iv_set (self, "@handler", INT2NUM (handler));
41
+ return self;
42
+ }
43
+
44
+ // static VALUE
45
+ // selectpl (VALUE self)
46
+ // {
47
+ // No need to bind this function.
48
+ // Use an object-oriented style.
49
+ // }
50
+
51
+ static VALUE
52
+ deletepl (VALUE self) {
53
+ int handler = get_handler (self);
54
+ pl_closepl ();
55
+ pl_selectpl (0);
56
+ if (pl_deletepl (handler) < 0)
57
+ rb_raise(delete_plotter_error, "Couldn't delete Plotter with id %d!", handler);
58
+ return INT2FIX (0);
59
+ }
60
+
61
+ static VALUE
62
+ parampl (VALUE self, VALUE param, VALUE value)
63
+ {
64
+ return INT2FIX (pl_parampl (StringValuePtr (param), (void*)(StringValuePtr (value))));
65
+ }
66
+
67
+ /* Setup functions */
68
+
69
+ static VALUE
70
+ openpl (VALUE self)
71
+ {
72
+ get_handler (self);
73
+ if (pl_openpl () < 0)
74
+ rb_raise(open_plotter_error, "Couldn't open Plotter!");
75
+ return INT2FIX (0);
76
+ }
77
+
78
+ static VALUE
79
+ bgcolor (VALUE self, VALUE red, VALUE green, VALUE blue)
80
+ {
81
+ return INT2FIX (pl_bgcolor (FIX2INT (red),
82
+ FIX2INT (green),
83
+ FIX2INT (blue)));
84
+ }
85
+
86
+ static VALUE
87
+ bgcolorname (VALUE self, VALUE name)
88
+ {
89
+ get_handler (self);
90
+ return INT2FIX (pl_bgcolorname (StringValuePtr (name)));
91
+ }
92
+
93
+ static VALUE
94
+ erase (VALUE self)
95
+ {
96
+ get_handler (self);
97
+ return INT2FIX (pl_erase ());
98
+ }
99
+
100
+ static VALUE
101
+ space (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1)
102
+ {
103
+ get_handler (self);
104
+ return INT2FIX (pl_space (FIX2INT (x0),
105
+ FIX2INT (y0),
106
+ FIX2INT (x1),
107
+ FIX2INT (y1)));
108
+ }
109
+
110
+ static VALUE
111
+ fspace (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1)
112
+ {
113
+ get_handler (self);
114
+ return INT2FIX (pl_fspace (NUM2DBL (x0),
115
+ NUM2DBL (y0),
116
+ NUM2DBL (x1),
117
+ NUM2DBL (y1)));
118
+ }
119
+
120
+ static VALUE
121
+ space2 (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
122
+ {
123
+ return INT2FIX (pl_space2 (FIX2INT (x0),
124
+ FIX2INT (y0),
125
+ FIX2INT (x1),
126
+ FIX2INT (y1),
127
+ FIX2INT (x2),
128
+ FIX2INT (y2)));
129
+ }
130
+
131
+ static VALUE
132
+ fspace2 (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
133
+ {
134
+ return INT2FIX (pl_fspace2 (NUM2DBL (x0),
135
+ NUM2DBL (y0),
136
+ NUM2DBL (x1),
137
+ NUM2DBL (y1),
138
+ NUM2DBL (x2),
139
+ NUM2DBL (y2)));
140
+ }
141
+
142
+ static VALUE
143
+ havecap (VALUE self, VALUE s)
144
+ {
145
+ return INT2FIX (pl_havecap (StringValuePtr (s)));
146
+ }
147
+
148
+ static VALUE
149
+ flushpl (VALUE self)
150
+ {
151
+ return INT2FIX (pl_flushpl ());
152
+ }
153
+
154
+ static VALUE
155
+ closepl (VALUE self)
156
+ {
157
+ get_handler (self);
158
+ if (pl_closepl () < 0)
159
+ rb_raise(close_plotter_error, "Couldn't close Plotter!");
160
+ return INT2FIX (0);
161
+ }
162
+
163
+ /* Object-drawing functions */
164
+
165
+ static VALUE
166
+ alabel (VALUE self, VALUE horiz_justify, VALUE vert_justify, VALUE s)
167
+ {
168
+ return INT2FIX (pl_alabel (FIX2INT (horiz_justify),
169
+ FIX2INT (vert_justify),
170
+ StringValuePtr (s)));
171
+ }
172
+
173
+ static VALUE
174
+ arc (VALUE self, VALUE xc, VALUE yc, VALUE x0, VALUE y0, VALUE x1, VALUE y1)
175
+ {
176
+ return INT2FIX (pl_arc (FIX2INT (xc),
177
+ FIX2INT (yc),
178
+ FIX2INT (x0),
179
+ FIX2INT (y0),
180
+ FIX2INT (x1),
181
+ FIX2INT (y1)));
182
+ }
183
+
184
+ static VALUE
185
+ farc (VALUE self, VALUE xc, VALUE yc, VALUE x0, VALUE y0, VALUE x1, VALUE y1)
186
+ {
187
+ return INT2FIX (pl_farc (NUM2DBL (xc),
188
+ NUM2DBL (yc),
189
+ NUM2DBL (x0),
190
+ NUM2DBL (y0),
191
+ NUM2DBL (x1),
192
+ NUM2DBL (y1)));
193
+ }
194
+
195
+ static VALUE
196
+ arcrel (VALUE self, VALUE xc, VALUE yc, VALUE x0, VALUE y0, VALUE x1, VALUE y1)
197
+ {
198
+ return INT2FIX (pl_arcrel (FIX2INT (xc),
199
+ FIX2INT (yc),
200
+ FIX2INT (x0),
201
+ FIX2INT (y0),
202
+ FIX2INT (x1),
203
+ FIX2INT (y1)));
204
+ }
205
+
206
+ static VALUE
207
+ farcrel (VALUE self, VALUE xc, VALUE yc, VALUE x0, VALUE y0, VALUE x1, VALUE y1)
208
+ {
209
+ return INT2FIX (pl_farcrel (NUM2DBL (xc),
210
+ NUM2DBL (yc),
211
+ NUM2DBL (x0),
212
+ NUM2DBL (y0),
213
+ NUM2DBL (x1),
214
+ NUM2DBL (y1)));
215
+ }
216
+
217
+ static VALUE
218
+ bezier2 (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
219
+ {
220
+ return INT2FIX (pl_bezier2 (FIX2INT (x0),
221
+ FIX2INT (y0),
222
+ FIX2INT (x1),
223
+ FIX2INT (y1),
224
+ FIX2INT (x2),
225
+ FIX2INT (y2)));
226
+ }
227
+
228
+ static VALUE
229
+ fbezier2 (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
230
+ {
231
+ return INT2FIX (pl_fbezier2 (NUM2DBL (x0),
232
+ NUM2DBL (y0),
233
+ NUM2DBL (x1),
234
+ NUM2DBL (y1),
235
+ NUM2DBL (x2),
236
+ NUM2DBL (y2)));
237
+ }
238
+
239
+ static VALUE
240
+ bezier2rel (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
241
+ {
242
+ return INT2FIX (pl_bezier2rel (FIX2INT (x0),
243
+ FIX2INT (y0),
244
+ FIX2INT (x1),
245
+ FIX2INT (y1),
246
+ FIX2INT (x2),
247
+ FIX2INT (y2)));
248
+ }
249
+
250
+ static VALUE
251
+ fbezier2rel (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
252
+ {
253
+ return INT2FIX (pl_fbezier2rel (NUM2DBL (x0),
254
+ NUM2DBL (y0),
255
+ NUM2DBL (x1),
256
+ NUM2DBL (y1),
257
+ NUM2DBL (x2),
258
+ NUM2DBL (y2)));
259
+ }
260
+
261
+ static VALUE
262
+ bezier3 (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3)
263
+ {
264
+ return INT2FIX (pl_bezier3 (FIX2INT (x0),
265
+ FIX2INT (y0),
266
+ FIX2INT (x1),
267
+ FIX2INT (y1),
268
+ FIX2INT (x2),
269
+ FIX2INT (y2),
270
+ FIX2INT (x3),
271
+ FIX2INT (y3)));
272
+ }
273
+
274
+ static VALUE
275
+ fbezier3 (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3)
276
+ {
277
+ return INT2FIX (pl_fbezier3 (NUM2DBL (x0),
278
+ NUM2DBL (y0),
279
+ NUM2DBL (x1),
280
+ NUM2DBL (y1),
281
+ NUM2DBL (x2),
282
+ NUM2DBL (y2),
283
+ NUM2DBL (x3),
284
+ NUM2DBL (y3)));
285
+ }
286
+
287
+ static VALUE
288
+ bezier3rel (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3)
289
+ {
290
+ return INT2FIX (pl_bezier3rel (FIX2INT (x0),
291
+ FIX2INT (y0),
292
+ FIX2INT (x1),
293
+ FIX2INT (y1),
294
+ FIX2INT (x2),
295
+ FIX2INT (y2),
296
+ FIX2INT (x3),
297
+ FIX2INT (y3)));
298
+ }
299
+
300
+ static VALUE
301
+ fbezier3rel (VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE x3, VALUE y3)
302
+ {
303
+ return INT2FIX (pl_fbezier3rel (NUM2DBL (x0),
304
+ NUM2DBL (y0),
305
+ NUM2DBL (x1),
306
+ NUM2DBL (y1),
307
+ NUM2DBL (x2),
308
+ NUM2DBL (y2),
309
+ NUM2DBL (x3),
310
+ NUM2DBL (y3)));
311
+ }
312
+
313
+ static VALUE
314
+ box (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
315
+ {
316
+ return INT2FIX (pl_box (FIX2INT (x1),
317
+ FIX2INT (y1),
318
+ FIX2INT (x2),
319
+ FIX2INT (y2)));
320
+ }
321
+
322
+ static VALUE
323
+ fbox (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
324
+ {
325
+ return INT2FIX (pl_fbox (NUM2DBL (x1),
326
+ NUM2DBL (y1),
327
+ NUM2DBL (x2),
328
+ NUM2DBL (y2)));
329
+ }
330
+
331
+ static VALUE
332
+ boxrel (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
333
+ {
334
+ return INT2FIX (pl_boxrel (FIX2INT (x1),
335
+ FIX2INT (y1),
336
+ FIX2INT (x2),
337
+ FIX2INT (y2)));
338
+ }
339
+
340
+ static VALUE
341
+ fboxrel (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
342
+ {
343
+ return INT2FIX (pl_fboxrel (NUM2DBL (x1),
344
+ NUM2DBL (y1),
345
+ NUM2DBL (x2),
346
+ NUM2DBL (y2)));
347
+ }
348
+
349
+ static VALUE
350
+ circle (VALUE self, VALUE xc, VALUE yc, VALUE r)
351
+ {
352
+ return INT2FIX (pl_circle (FIX2INT (xc),
353
+ FIX2INT (yc),
354
+ FIX2INT (r)));
355
+ }
356
+
357
+ static VALUE
358
+ fcircle (VALUE self, VALUE xc, VALUE yc, VALUE r)
359
+ {
360
+ return INT2FIX (pl_fcircle (NUM2DBL (xc),
361
+ NUM2DBL (yc),
362
+ NUM2DBL (r)));
363
+ }
364
+
365
+ static VALUE
366
+ circlerel (VALUE self, VALUE xc, VALUE yc, VALUE r)
367
+ {
368
+ return INT2FIX (pl_circlerel (FIX2INT (xc),
369
+ FIX2INT (yc),
370
+ FIX2INT (r)));
371
+ }
372
+
373
+ static VALUE
374
+ fcirclerel (VALUE self, VALUE xc, VALUE yc, VALUE r)
375
+ {
376
+ return INT2FIX (pl_fcirclerel (NUM2DBL (xc),
377
+ NUM2DBL (yc),
378
+ NUM2DBL (r)));
379
+ }
380
+
381
+ static VALUE
382
+ cont (VALUE self, VALUE x, VALUE y)
383
+ {
384
+ return INT2FIX (pl_cont (FIX2INT (x),
385
+ FIX2INT (y)));
386
+ }
387
+
388
+ static VALUE
389
+ fcont (VALUE self, VALUE x, VALUE y)
390
+ {
391
+ return INT2FIX (pl_fcont (NUM2DBL (x),
392
+ NUM2DBL (y)));
393
+ }
394
+
395
+ static VALUE
396
+ contrel (VALUE self, VALUE x, VALUE y)
397
+ {
398
+ return INT2FIX (pl_contrel (FIX2INT (x),
399
+ FIX2INT (y)));
400
+ }
401
+
402
+ static VALUE
403
+ fcontrel (VALUE self, VALUE x, VALUE y)
404
+ {
405
+ return INT2FIX (pl_fcontrel (NUM2DBL (x),
406
+ NUM2DBL (y)));
407
+ }
408
+
409
+ static VALUE
410
+ ellarc (VALUE self, VALUE xc, VALUE yc, VALUE x0, VALUE y0, VALUE x1, VALUE y1)
411
+ {
412
+ return INT2FIX (pl_ellarc (FIX2INT (xc),
413
+ FIX2INT (yc),
414
+ FIX2INT (x0),
415
+ FIX2INT (y0),
416
+ FIX2INT (x1),
417
+ FIX2INT (y1)));
418
+ }
419
+
420
+ static VALUE
421
+ fellarc (VALUE self, VALUE xc, VALUE yc, VALUE x0, VALUE y0, VALUE x1, VALUE y1)
422
+ {
423
+ return INT2FIX (pl_fellarc (NUM2DBL (xc),
424
+ NUM2DBL (yc),
425
+ NUM2DBL (x0),
426
+ NUM2DBL (y0),
427
+ NUM2DBL (x1),
428
+ NUM2DBL (y1)));
429
+ }
430
+
431
+ static VALUE
432
+ ellarcrel (VALUE self, VALUE xc, VALUE yc, VALUE x0, VALUE y0, VALUE x1, VALUE y1)
433
+ {
434
+ return INT2FIX (pl_ellarcrel (FIX2INT (xc),
435
+ FIX2INT (yc),
436
+ FIX2INT (x0),
437
+ FIX2INT (y0),
438
+ FIX2INT (x1),
439
+ FIX2INT (y1)));
440
+ }
441
+
442
+ static VALUE
443
+ fellarcrel (VALUE self, VALUE xc, VALUE yc, VALUE x0, VALUE y0, VALUE x1, VALUE y1)
444
+ {
445
+ return INT2FIX (pl_fellarcrel (NUM2DBL (xc),
446
+ NUM2DBL (yc),
447
+ NUM2DBL (x0),
448
+ NUM2DBL (y0),
449
+ NUM2DBL (x1),
450
+ NUM2DBL (y1)));
451
+ }
452
+
453
+ static VALUE
454
+ ellipse (VALUE self, VALUE xc, VALUE yc, VALUE rx, VALUE ry, VALUE angle)
455
+ {
456
+ return INT2FIX (pl_ellipse (FIX2INT (xc),
457
+ FIX2INT (yc),
458
+ FIX2INT (rx),
459
+ FIX2INT (ry),
460
+ FIX2INT (angle)));
461
+ }
462
+
463
+ static VALUE
464
+ fellipse (VALUE self, VALUE xc, VALUE yc, VALUE rx, VALUE ry, VALUE angle)
465
+ {
466
+ return INT2FIX (pl_fellipse (NUM2DBL (xc),
467
+ NUM2DBL (yc),
468
+ NUM2DBL (rx),
469
+ NUM2DBL (ry),
470
+ NUM2DBL (angle)));
471
+ }
472
+
473
+ static VALUE
474
+ ellipserel (VALUE self, VALUE xc, VALUE yc, VALUE rx, VALUE ry, VALUE angle)
475
+ {
476
+ return INT2FIX (pl_ellipserel (FIX2INT (xc),
477
+ FIX2INT (yc),
478
+ FIX2INT (rx),
479
+ FIX2INT (ry),
480
+ FIX2INT (angle)));
481
+ }
482
+
483
+ static VALUE
484
+ fellipserel (VALUE self, VALUE xc, VALUE yc, VALUE rx, VALUE ry, VALUE angle)
485
+ {
486
+ return INT2FIX (pl_fellipserel (NUM2DBL (xc),
487
+ NUM2DBL (yc),
488
+ NUM2DBL (rx),
489
+ NUM2DBL (ry),
490
+ NUM2DBL (angle)));
491
+ }
492
+
493
+ static VALUE
494
+ endpath (VALUE self)
495
+ {
496
+ return INT2FIX (pl_endpath ());
497
+ }
498
+
499
+ static VALUE
500
+ label (VALUE self, VALUE s)
501
+ {
502
+ return INT2FIX (pl_label (StringValuePtr (s)));
503
+ }
504
+
505
+ static VALUE
506
+ labelwidth (VALUE self, VALUE s)
507
+ {
508
+ return INT2FIX (pl_labelwidth (StringValuePtr (s)));
509
+ }
510
+
511
+ static VALUE
512
+ flabelwidth (VALUE self, VALUE s)
513
+ {
514
+ return DBL2NUM (pl_flabelwidth (StringValuePtr (s)));
515
+ }
516
+
517
+ static VALUE
518
+ line (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
519
+ {
520
+ get_handler (self);
521
+ return INT2FIX (pl_line (FIX2INT (x1),
522
+ FIX2INT (y1),
523
+ FIX2INT (x2),
524
+ FIX2INT (y2)));
525
+ }
526
+
527
+ static VALUE
528
+ fline (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
529
+ {
530
+ get_handler (self);
531
+ return INT2FIX (pl_fline (NUM2DBL (x1),
532
+ NUM2DBL (y1),
533
+ NUM2DBL (x2),
534
+ NUM2DBL (y2)));
535
+ }
536
+
537
+ static VALUE
538
+ linerel (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
539
+ {
540
+ return INT2FIX (pl_linerel (FIX2INT (x1),
541
+ FIX2INT (y1),
542
+ FIX2INT (x2),
543
+ FIX2INT (y2)));
544
+ }
545
+
546
+ static VALUE
547
+ flinerel (VALUE self, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
548
+ {
549
+ return INT2FIX (pl_flinerel (NUM2DBL (x1),
550
+ NUM2DBL (y1),
551
+ NUM2DBL (x2),
552
+ NUM2DBL (y2)));
553
+ }
554
+
555
+ static VALUE
556
+ marker (VALUE self, VALUE x, VALUE y, VALUE type, VALUE size)
557
+ {
558
+ return INT2FIX (pl_marker (FIX2INT (x),
559
+ FIX2INT (y),
560
+ FIX2INT (type),
561
+ FIX2INT (size)));
562
+ }
563
+
564
+ static VALUE
565
+ fmarker (VALUE self, VALUE x, VALUE y, VALUE type, VALUE size)
566
+ {
567
+ return INT2FIX (pl_fmarker (NUM2DBL (x),
568
+ NUM2DBL (y),
569
+ FIX2INT (type),
570
+ NUM2DBL (size)));
571
+ }
572
+
573
+ static VALUE
574
+ markerrel (VALUE self, VALUE x, VALUE y, VALUE type, VALUE size)
575
+ {
576
+ return INT2FIX (pl_markerrel (FIX2INT (x),
577
+ FIX2INT (y),
578
+ FIX2INT (type),
579
+ FIX2INT (size)));
580
+ }
581
+
582
+ static VALUE
583
+ fmarkerrel (VALUE self, VALUE x, VALUE y, VALUE type, VALUE size)
584
+ {
585
+ return INT2FIX (pl_fmarkerrel (NUM2DBL (x),
586
+ NUM2DBL (y),
587
+ FIX2INT (type),
588
+ NUM2DBL (size)));
589
+ }
590
+
591
+ static VALUE
592
+ point (VALUE self, VALUE x, VALUE y)
593
+ {
594
+ return INT2FIX (pl_point (FIX2INT (x),
595
+ FIX2INT (y)));
596
+ }
597
+
598
+ static VALUE
599
+ fpoint (VALUE self, VALUE x, VALUE y)
600
+ {
601
+ return INT2FIX (pl_fpoint (NUM2DBL (x),
602
+ NUM2DBL (y)));
603
+ }
604
+
605
+ static VALUE
606
+ pointrel (VALUE self, VALUE x, VALUE y)
607
+ {
608
+ return INT2FIX (pl_pointrel (FIX2INT (x),
609
+ FIX2INT (y)));
610
+ }
611
+
612
+ static VALUE
613
+ fpointrel (VALUE self, VALUE x, VALUE y)
614
+ {
615
+ return INT2FIX (pl_fpoint (NUM2DBL (x),
616
+ NUM2DBL (y)));
617
+ }
618
+
619
+ /* Attribute-setting functions */
620
+
621
+ static VALUE
622
+ capmod (VALUE self, VALUE s)
623
+ {
624
+ return INT2FIX (pl_capmod (StringValuePtr (s)));
625
+ }
626
+
627
+ static VALUE
628
+ color (VALUE self, VALUE red, VALUE green, VALUE blue)
629
+ {
630
+ return INT2FIX (pl_color (FIX2INT (red),
631
+ FIX2INT (green),
632
+ FIX2INT (blue)));
633
+ }
634
+
635
+ static VALUE
636
+ colorname (VALUE self, VALUE name)
637
+ {
638
+ return INT2FIX (pl_colorname (StringValuePtr (name)));
639
+ }
640
+
641
+ static VALUE
642
+ fillcolor (VALUE self, VALUE red, VALUE green, VALUE blue)
643
+ {
644
+ return INT2FIX (pl_fillcolor (FIX2INT (red),
645
+ FIX2INT (green),
646
+ FIX2INT (blue)));
647
+ }
648
+
649
+ static VALUE
650
+ fillcolorname (VALUE self, VALUE name)
651
+ {
652
+ return INT2FIX (pl_fillcolorname (StringValuePtr (name)));
653
+ }
654
+
655
+ static VALUE
656
+ fillmod (VALUE self, VALUE s)
657
+ {
658
+ return INT2FIX (pl_fillmod (StringValuePtr (s)));
659
+ }
660
+
661
+ static VALUE filltype (VALUE self, VALUE level)
662
+ {
663
+ return INT2FIX (pl_filltype (FIX2INT (level)));
664
+ }
665
+
666
+ static VALUE
667
+ fmiterlimit (VALUE self, VALUE limit)
668
+ {
669
+ return INT2FIX (pl_fmiterlimit (NUM2DBL (limit)));
670
+ }
671
+
672
+ static VALUE
673
+ fontname (VALUE self, VALUE font_name)
674
+ {
675
+ return INT2FIX (pl_fontname (StringValuePtr (font_name)));
676
+ }
677
+
678
+ static VALUE
679
+ ffontname (VALUE self, VALUE font_name)
680
+ {
681
+ return DBL2NUM (pl_ffontname (StringValuePtr (font_name)));
682
+ }
683
+
684
+ static VALUE
685
+ fontsize (VALUE self, VALUE size)
686
+ {
687
+ return INT2FIX (pl_fontsize (FIX2INT (size)));
688
+ }
689
+
690
+ static VALUE ffontsize (VALUE self, VALUE size)
691
+ {
692
+ return DBL2NUM (pl_ffontsize (NUM2DBL (size)));
693
+ }
694
+
695
+ static VALUE
696
+ joinmod (VALUE self, VALUE s)
697
+ {
698
+ return INT2FIX (pl_joinmod (StringValuePtr (s)));
699
+ }
700
+
701
+ static VALUE
702
+ linedash (VALUE self, VALUE n, VALUE dashes, VALUE offset)
703
+ {
704
+ int size = RARRAY_LEN (dashes); // Use n instead?
705
+ VALUE *dashes_p = RARRAY_PTR (dashes);
706
+ int c_dashes[size];
707
+ int i;
708
+ for (i = 0; i < size; i++)
709
+ c_dashes[i] = FIX2INT(dashes_p[i]);
710
+
711
+ return INT2FIX (pl_linedash (size, c_dashes, FIX2INT (offset)));
712
+ }
713
+
714
+ static VALUE
715
+ flinedash (VALUE self, VALUE n, VALUE dashes, VALUE offset)
716
+ {
717
+ int size = RARRAY_LEN (dashes); // Use n instead?
718
+ VALUE *dashes_p = RARRAY_PTR (dashes);
719
+ double c_dashes[size];
720
+ int i;
721
+ for (i = 0; i < size; i++)
722
+ c_dashes[i] = NUM2DBL(dashes_p[i]);
723
+
724
+ return INT2FIX (pl_flinedash (size, c_dashes, NUM2DBL (offset)));
725
+ }
726
+
727
+ static VALUE
728
+ linemod (VALUE self, VALUE s)
729
+ {
730
+ return INT2FIX (pl_linemod (StringValuePtr (s)));
731
+ }
732
+
733
+ static VALUE
734
+ linewidth (VALUE self, VALUE size)
735
+ {
736
+ return INT2FIX (pl_linewidth (FIX2INT (size)));
737
+ }
738
+
739
+ static VALUE
740
+ flinewidth (VALUE self, VALUE size)
741
+ {
742
+ return INT2FIX (pl_flinewidth (NUM2DBL (size)));
743
+ }
744
+
745
+ static VALUE
746
+ move (VALUE self, VALUE x, VALUE y)
747
+ {
748
+ return INT2FIX (pl_move (FIX2INT (x),
749
+ FIX2INT (y)));
750
+ }
751
+
752
+ static VALUE
753
+ fmove (VALUE self, VALUE x, VALUE y)
754
+ {
755
+ return INT2FIX (pl_fmove (NUM2DBL (x),
756
+ NUM2DBL (y)));
757
+ }
758
+
759
+ static VALUE
760
+ moverel (VALUE self, VALUE x, VALUE y)
761
+ {
762
+ return INT2FIX (pl_moverel (FIX2INT (x),
763
+ FIX2INT (y)));
764
+ }
765
+
766
+ static VALUE
767
+ fmoverel (VALUE self, VALUE x, VALUE y)
768
+ {
769
+ return INT2FIX (pl_fmoverel (NUM2DBL (x),
770
+ NUM2DBL (y)));
771
+ }
772
+
773
+ static VALUE
774
+ pencolor (VALUE self, VALUE red, VALUE green, VALUE blue)
775
+ {
776
+ return INT2FIX (pl_pencolor (FIX2INT (red),
777
+ FIX2INT (green),
778
+ FIX2INT (blue)));
779
+ }
780
+
781
+ static VALUE
782
+ pencolorname (VALUE self, VALUE name)
783
+ {
784
+ return INT2FIX (pl_pencolorname (StringValuePtr (name)));
785
+ }
786
+
787
+ static VALUE
788
+ restorestate (VALUE self)
789
+ {
790
+ return INT2FIX (pl_restorestate ());
791
+ }
792
+
793
+ static VALUE
794
+ savestate (VALUE self)
795
+ {
796
+ return INT2FIX (pl_savestate ());
797
+ }
798
+
799
+ static VALUE
800
+ textangle (VALUE self, VALUE angle)
801
+ {
802
+ return INT2FIX (pl_textangle (FIX2INT (angle)));
803
+ }
804
+
805
+ static VALUE
806
+ ftextangle (VALUE self, VALUE angle)
807
+ {
808
+ return DBL2NUM (pl_ftextangle (NUM2DBL (angle)));
809
+ }
810
+
811
+ /* Mapping functions */
812
+
813
+ static VALUE
814
+ fconcat (VALUE self, VALUE m0, VALUE m1, VALUE m2, VALUE m3, VALUE tx, VALUE ty)
815
+ {
816
+ return INT2FIX (pl_fconcat (NUM2DBL (m0),
817
+ NUM2DBL (m1),
818
+ NUM2DBL (m2),
819
+ NUM2DBL (m3),
820
+ NUM2DBL (tx),
821
+ NUM2DBL (ty)));
822
+ }
823
+
824
+ static VALUE
825
+ frotate (VALUE self, VALUE theta)
826
+ {
827
+ return INT2FIX (pl_frotate (NUM2DBL (theta)));
828
+ }
829
+
830
+ static VALUE
831
+ fscale (VALUE self, VALUE sx, VALUE sy)
832
+ {
833
+ return INT2FIX (pl_fscale (NUM2DBL (sx),
834
+ NUM2DBL (sy)));
835
+ }
836
+
837
+ static VALUE
838
+ ftranslate (VALUE self, VALUE tx, VALUE ty)
839
+ {
840
+ return INT2FIX (pl_ftranslate (NUM2DBL (tx),
841
+ NUM2DBL (ty)));
842
+ }
843
+
844
+ /* Init rplot */
845
+
846
+ void
847
+ Init_rplot ()
848
+ {
849
+ /* Define exceptions */
850
+ create_plotter_error = rb_define_class ("CreatePlotterError", rb_eStandardError);
851
+ select_plotter_error = rb_define_class ("SelectPlotterError", rb_eStandardError);
852
+ open_plotter_error = rb_define_class ("OpenPlotterError", rb_eStandardError);
853
+ close_plotter_error = rb_define_class ("ClosePlotterError", rb_eStandardError);
854
+ delete_plotter_error = rb_define_class ("DeletePlotterError", rb_eStandardError);
855
+ operation_plotter_error = rb_define_class ("OperationPlotterError", rb_eStandardError);
856
+ /* Define Rplot class */
857
+ VALUE rplot = rb_define_class ("Rplot", rb_cObject);
858
+ /* Base functions */
859
+ rb_define_protected_method (rplot, "initialize", newpl, 4);
860
+ rb_define_protected_method (rplot, "delete", deletepl, 0);
861
+ rb_define_singleton_method (rplot, "param", parampl, 2);
862
+ /* Setup functions */
863
+ rb_define_protected_method (rplot, "open", openpl, 0);
864
+ rb_define_protected_method (rplot, "bgcolor", bgcolor, 3);
865
+ rb_define_protected_method (rplot, "bgcolorname", bgcolorname, 1);
866
+ rb_define_protected_method (rplot, "erase", erase, 0);
867
+ rb_define_protected_method (rplot, "space", space, 4);
868
+ rb_define_protected_method (rplot, "fspace", fspace, 4);
869
+ rb_define_protected_method (rplot, "space2", space2, 6);
870
+ rb_define_protected_method (rplot, "fspace2", fspace2, 6);
871
+ rb_define_protected_method (rplot, "havecap", havecap, 1);
872
+ rb_define_protected_method (rplot, "flush", flushpl, 0);
873
+ rb_define_protected_method (rplot, "close", closepl, 0);
874
+ /* Object-drawing functions */
875
+ rb_define_protected_method (rplot, "alabel", alabel, 3);
876
+ rb_define_protected_method (rplot, "arc", arc, 6);
877
+ rb_define_protected_method (rplot, "farc", farc, 6);
878
+ rb_define_protected_method (rplot, "arcrel", arcrel, 6);
879
+ rb_define_protected_method (rplot, "farcrel", farcrel, 6);
880
+ rb_define_protected_method (rplot, "bezier2", bezier2, 6);
881
+ rb_define_protected_method (rplot, "fbezier2", fbezier2, 6);
882
+ rb_define_protected_method (rplot, "bezier2rel", bezier2rel, 6);
883
+ rb_define_protected_method (rplot, "fbezier2rel", fbezier2rel, 6);
884
+ rb_define_protected_method (rplot, "bezier3", bezier3, 8);
885
+ rb_define_protected_method (rplot, "fbezier3", fbezier3, 8);
886
+ rb_define_protected_method (rplot, "bezier3rel", bezier3rel, 8);
887
+ rb_define_protected_method (rplot, "fbezier3rel", fbezier3rel, 8);
888
+ rb_define_protected_method (rplot, "box", box, 4);
889
+ rb_define_protected_method (rplot, "fbox", fbox, 4);
890
+ rb_define_protected_method (rplot, "boxrel", boxrel, 4);
891
+ rb_define_protected_method (rplot, "fboxrel", fboxrel, 4);
892
+ rb_define_protected_method (rplot, "circle", circle, 3);
893
+ rb_define_protected_method (rplot, "fcircle", fcircle, 3);
894
+ rb_define_protected_method (rplot, "circlerel", circlerel, 3);
895
+ rb_define_protected_method (rplot, "fcirclerel", fcirclerel, 3);
896
+ rb_define_protected_method (rplot, "cont", cont, 2);
897
+ rb_define_protected_method (rplot, "fcont", fcont, 2);
898
+ rb_define_protected_method (rplot, "contrel", contrel, 2);
899
+ rb_define_protected_method (rplot, "fcontrel", fcontrel, 2);
900
+ rb_define_protected_method (rplot, "ellarc", ellarc, 6);
901
+ rb_define_protected_method (rplot, "fellarc", fellarc, 6);
902
+ rb_define_protected_method (rplot, "ellarcrel", ellarcrel, 6);
903
+ rb_define_protected_method (rplot, "fellarcrel", fellarcrel, 6);
904
+ rb_define_protected_method (rplot, "ellipse", ellipse, 5);
905
+ rb_define_protected_method (rplot, "fellipse", fellipse, 5);
906
+ rb_define_protected_method (rplot, "ellipserel", ellipserel, 5);
907
+ rb_define_protected_method (rplot, "fellipserel", fellipserel, 5);
908
+ rb_define_protected_method (rplot, "endpath", endpath, 0);
909
+ rb_define_protected_method (rplot, "label", label, 1);
910
+ rb_define_protected_method (rplot, "labelwidth", labelwidth, 1);
911
+ rb_define_protected_method (rplot, "flabelwidth", flabelwidth, 1);
912
+ rb_define_protected_method (rplot, "line", line, 4);
913
+ rb_define_protected_method (rplot, "fline", fline, 4);
914
+ rb_define_protected_method (rplot, "linerel", linerel, 4);
915
+ rb_define_protected_method (rplot, "flinerel", flinerel, 4);
916
+ rb_define_protected_method (rplot, "marker", marker, 4);
917
+ rb_define_protected_method (rplot, "fmarker", fmarker, 4);
918
+ rb_define_protected_method (rplot, "markerrel", markerrel, 4);
919
+ rb_define_protected_method (rplot, "fmarkerrel", fmarkerrel, 4);
920
+ rb_define_protected_method (rplot, "point", point, 2);
921
+ rb_define_protected_method (rplot, "fpoint", fpoint, 2);
922
+ rb_define_protected_method (rplot, "pointrel", pointrel, 2);
923
+ rb_define_protected_method (rplot, "fpointrel", fpointrel, 2);
924
+ /* Attribute-setting functions */
925
+ rb_define_protected_method (rplot, "capmod", capmod, 1);
926
+ rb_define_protected_method (rplot, "color", color, 3);
927
+ rb_define_protected_method (rplot, "colorname", colorname, 1);
928
+ rb_define_protected_method (rplot, "fillcolor", fillcolor, 3);
929
+ rb_define_protected_method (rplot, "fillcolorname", fillcolorname, 1);
930
+ rb_define_protected_method (rplot, "fillmod", fillmod, 1);
931
+ rb_define_protected_method (rplot, "filltype", filltype, 1);
932
+ rb_define_protected_method (rplot, "fmiterlimit", fmiterlimit, 1);
933
+ rb_define_protected_method (rplot, "fontname", fontname, 1);
934
+ rb_define_protected_method (rplot, "ffontname", ffontname, 1);
935
+ rb_define_protected_method (rplot, "fontsize", fontsize, 1);
936
+ rb_define_protected_method (rplot, "ffontsize", ffontsize, 1);
937
+ rb_define_protected_method (rplot, "joinmod", joinmod, 1);
938
+ rb_define_protected_method (rplot, "linedash", linedash, 3);
939
+ rb_define_protected_method (rplot, "flinedash", flinedash, 3);
940
+ rb_define_protected_method (rplot, "linemod", linemod, 1);
941
+ rb_define_protected_method (rplot, "linewidth", linewidth, 1);
942
+ rb_define_protected_method (rplot, "flinewidth", flinewidth, 1);
943
+ rb_define_protected_method (rplot, "move", move, 2);
944
+ rb_define_protected_method (rplot, "fmove", fmove, 2);
945
+ rb_define_protected_method (rplot, "moverel", moverel, 2);
946
+ rb_define_protected_method (rplot, "fmoverel", fmoverel, 2);
947
+ rb_define_protected_method (rplot, "pencolor", pencolor, 3);
948
+ rb_define_protected_method (rplot, "pencolorname", pencolorname, 1);
949
+ rb_define_protected_method (rplot, "restorestate", restorestate, 0);
950
+ rb_define_protected_method (rplot, "savestate", savestate, 0);
951
+ rb_define_protected_method (rplot, "textangle", textangle, 1);
952
+ rb_define_protected_method (rplot, "ftextangle", ftextangle, 1);
953
+ /* Mapping functions */
954
+ rb_define_protected_method (rplot, "fconcat", fconcat, 6);
955
+ rb_define_protected_method (rplot, "frotate", frotate, 1);
956
+ rb_define_protected_method (rplot, "fscale", fscale, 2);
957
+ rb_define_protected_method (rplot, "ftranslate", ftranslate, 2);
958
+ }
959
+