[cairo-commit] rcairo/src/tests ps, NONE, 1.1 spline, NONE, 1.1 test-nox, NONE, 1.1 text, NONE, 1.1

Evan Martin commit at pdx.freedesktop.org
Fri May 28 12:34:02 PDT 2004


Committed by: martine

Update of /cvs/cairo/rcairo/src/tests
In directory pdx:/tmp/cvs-serv28838/src/tests

Added Files:
	ps spline test-nox text 
Log Message:
move files around

--- NEW FILE: ps ---
#!/usr/bin/env ruby
# vim: set ts=2 sw=2 et :

$LOAD_PATH << ".."
require 'cairo'

cr = Cairo::Cairo.new

# tweak these:
SIZE = 4
DPI = 200
FILENAME = 'ps.ps'

# derived constants:
PIXELS = SIZE * DPI
MARGIN = PIXELS/40

File.open(FILENAME, "w") { |f|
  cr.set_target_ps(f, SIZE, SIZE, DPI, DPI)
  cr.set_rgb_color(0,0,0)
  cr.line_cap = Cairo::LineCap::ROUND
  cr.line_width = PIXELS/40
  cr.stroke {
    cr.move_to(MARGIN, MARGIN)
    cr.line_to(PIXELS-MARGIN, PIXELS-MARGIN)
  }
  cr.show_page
}
puts "wrote #{SIZE}x#{SIZE}in, #{DPI}dpi image to #{FILENAME}."


--- NEW FILE: spline ---
#!/usr/bin/env ruby
# vim: set ts=2 sw=2 et :

$LOAD_PATH << ".."
require 'cairo'

class SplineWindow < Cairo::Xlib::Window
  def initialize(dpy)
    @width = @height = 400
    super(dpy, @width, @height, false)
  end

  def randx
    10 + rand(@width-20)
  end
  def randy
    10 + rand(@height-20)
  end

  def draw
    @cairo.set_rgb_color(1, 1, 1)
    @cairo.line_cap = Cairo::LineCap::ROUND
    @cairo.line_width = 2 + ((rand**2.0) * 50)
    @cairo.stroke {
      @cairo.move_to(randx, randy)
      @cairo.curve_to(randx, randy, randx, randy, randx, randy)
    }
  end

  def keypress(key)
    case key.chr
    when 'q'
      @dpy.quit
    end
  end
end

dpy = Cairo::Xlib::Display.new
sw = SplineWindow.new(dpy)
puts "Tap keys to get new splines..."
dpy.mainloop



--- NEW FILE: test-nox ---
#!/usr/bin/env ruby
# vim: set ts=2 sw=2 et :

$LOAD_PATH << ".."
require 'cairo'

puts <<EOT
A diagonal line, from top-left to bottom-right, looks like this:

EOT

img = Cairo::Image.new(0, 8, 8, 8*4)

cairo = Cairo::Cairo.new
cairo.target_image = img

# cairo.set_rgb_color(0, 0, 0)
# cairo.fill {
#   cairo.move_to(0, 0)
#   cairo.line_to(8, 0)
#   cairo.line_to(8, 8)
#   cairo.line_to(0, 8)
#   cairo.close_path
# }

cairo.set_rgb_color(1, 1, 1)
cairo.stroke {
  cairo.move_to(0, 0)
  cairo.line_to(8, 8)
}

lasty = 0
img.each_pixel { |x, y, p|
  (puts; puts) if y != lasty
  print ("%08x" % p) + " "
  lasty = y
}
puts; puts


--- NEW FILE: text ---
#!/usr/bin/env ruby
# vim: set ts=2 sw=2 et :

$LOAD_PATH << ".."
require 'cairo'

class TextWindow < Cairo::Xlib::Window
  def initialize(dpy)
    super(dpy, 400, 40, true)
    @text = ">"
    @cairo.scale_font(20)
    @cairo.set_rgb_color(0, 0, 0)
  end
  def draw
    @cairo.move_to(10, 30)
    @cairo.show_text(@text)
  end
  def keypress(key)
    case key.chr
    when 'q'
      @dpy.quit
    else
      @text << key.chr if key > 0
    end
  end
end

dpy = Cairo::Xlib::Display.new
w = TextWindow.new(dpy)
dpy.mainloop






More information about the cairo-commit mailing list