File: RotateScale.rb

package info (click to toggle)
librmagick-ruby 2.13.1-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,444 kB
  • ctags: 1,716
  • sloc: ansic: 16,755; ruby: 9,730; makefile: 16; sh: 12
file content (37 lines) | stat: -rw-r--r-- 1,546 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'rvg/rvg'

rvg = Magick::RVG.new(400, 120) do |canvas|
    canvas.desc = 'Example RotateScale - Rotate and scale transforms'
    canvas.background_fill = 'white'
    canvas.g.styles(:fill=>'none', :stroke=>'black', :stroke_width=>3) do |grp|
        # Draw the axes of the original coordinate system
        grp.line(0, 1.5, 400, 1.5)
        grp.line(1.5, 0, 1.5, 120)
    end
    # Establish a new coordinate system whose origin is at (50,30)
    # in the original coord. system and which is rotated by 30 degrees.
    canvas.g.translate(50,30) do |grp|
        grp.g.rotate(30) do |grp2|
            grp2.g.styles(:fill=>'none',:stroke=>'red',:stroke_width=>3) do |grp3|
                grp3.line(0, 0, 50, 0)
                grp3.line(0, 0, 0, 50)
            end
            grp2.text(0, 0, "ABC (rotate)").styles(:font_size=>20, :fill=>'blue', :font_family=>'Verdana', :font_weight=>'normal', :font_style=>'normal')
        end
    end

    # Establish a new coordinate system whose origin is at (200,40)
    # in the original coord. systm and which is scaled by 1.5
    canvas.g.translate(200,40) do |grp|
        grp.g.scale(1.5) do |grp2|
            grp2.g.styles(:fill=>'none',:stroke=>'red',:stroke_width=>3) do |grp3|
                grp3.line(0, 0, 50, 0)
                grp3.line(0, 0, 0, 50)
            end
            grp2.text(0, 0, "ABC (scale)").styles(:font_size=>20, :fill=>'blue', :font_family=>'Verdana', :font_weight=>'normal', :font_style=>'normal')
        end
    end
end

rvg.draw.write('RotateScale.gif')