File: test_poly.rb

package info (click to toggle)
libimlib2-ruby 0.5.2-2.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,552 kB
  • sloc: ansic: 4,671; ruby: 250; makefile: 7
file content (29 lines) | stat: -rwxr-xr-x 572 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/ruby

require 'imlib2'

filename = 'test_poly_1.png'

im = Imlib2::Image.new 320, 320
fg = Imlib2::Color::BLUE
bg = Imlib2::Gradient.new [0, Imlib2::Color::BLACK],
                          [1, Imlib2::Color::WHITE]

im.gradient bg, 0, 0, im.width, im.height, 135.0


points = []

0.upto(im.height / 10) { |y|
  points.push [5, y * im.height / 10], [im.width - 5, y * im.height / 10] 
}

poly = Imlib2::Polygon::new *points

im.fill_poly poly, fg

begin
  im.save filename
rescue Imlib2::FileError
  $stderr.puts "Couldn't save file \"#{filename}\": " + $!
end