class Demo::CairoPatternFill

Constants

SPIKES
TEXT
X_FUZZ
X_INNER_RADIUS
X_OUTER_RADIUS
Y_FUZZ
Y_INNER_RADIUS
Y_OUTER_RADIUS

Public Class Methods

new() click to toggle source
Calls superclass method
# File gtk2/sample/gtk-demo/cairo-pattern-fill.rb, line 28
def initialize
  super('cairo pattern fill')
end

Public Instance Methods

draw(cr) click to toggle source
# File gtk2/sample/gtk-demo/cairo-pattern-fill.rb, line 32
def draw(cr)
  srand(45)
  
  cr.set_line_width(0.01)

  x = y = nil
  0.step(SPIKES * 2 - 1, 2) do |i|
    x = x_position(i, X_INNER_RADIUS)
    y = y_position(i, Y_INNER_RADIUS)
    
    if (i == 0)
      cr.move_to(x, y)
    else
      cr.line_to(x, y)
    end
        
    i += 1
        
    x = x_position(i, X_OUTER_RADIUS)
    y = y_position(i, Y_OUTER_RADIUS)
    
    cr.line_to(x, y)
  end

  cr.close_path
  cr.stroke
      
  cr.select_font_face("Sans",
                      Cairo::FONT_SLANT_NORMAL,
                      Cairo::FONT_WEIGHT_BOLD)

  cr.move_to(x - 0.5, y)
  cr.set_font_size(0.1)
  cr.text_path(TEXT)
  cr.set_source_rgba(1, 0, 0.5)
  cr.fill
      
  cr.set_font_size(0.2)
  extents = cr.text_extents(TEXT)
  x = 0.5 - (extents.width / 2 + extents.x_bearing)
  y = 0.5 - (extents.height / 2 + extents.y_bearing)

  cr.move_to(x, y)
  cr.text_path(TEXT)
  cr.set_source_rgba(1, 0, 0)
  cr.stroke
end
x_position(i, radius) click to toggle source
# File gtk2/sample/gtk-demo/cairo-pattern-fill.rb, line 80
def x_position(i, radius)
  0.5 + Math.cos(Math::PI * i / SPIKES) * radius + rand * X_FUZZ
end
y_position(i, radius) click to toggle source
# File gtk2/sample/gtk-demo/cairo-pattern-fill.rb, line 84
def y_position(i, radius)
  0.5 + Math.sin(Math::PI * i / SPIKES) * radius + rand * Y_FUZZ      
end