[cairo-commit] rcairo/samples blur.rb, 1.1, 1.2 pac.rb, 1.7,
1.8 pac2.rb, 1.7, 1.8 png.rb, 1.13, 1.14 scalable.rb, 1.5,
1.6 text-on-path.rb, 1.4, 1.5 text2.rb, 1.7, 1.8
Kouhei Sutou
commit at pdx.freedesktop.org
Mon Apr 16 00:31:53 PDT 2007
Committed by: kou
Update of /cvs/cairo/rcairo/samples
In directory kemper:/tmp/cvs-serv31172/samples
Modified Files:
blur.rb pac.rb pac2.rb png.rb scalable.rb text-on-path.rb
text2.rb
Log Message:
* src/lib/cairo/color.rb, src/lib/cairo/pattern.rb,
src/lib/cairo/context/color.rb, src/rb_cairo_pattern.c: improved
Cairo::Color interface.
* sample/: used Cairo::Color.
Index: blur.rb
===================================================================
RCS file: /cvs/cairo/rcairo/samples/blur.rb,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- blur.rb 15 Apr 2007 06:15:22 -0000 1.1
+++ blur.rb 16 Apr 2007 07:31:43 -0000 1.2
@@ -1,4 +1,9 @@
-#!/USO/bin/env ruby
+#!/usr/bin/env ruby
+
+top = File.expand_path(File.join(File.dirname(__FILE__), ".."))
+src = File.join(top, "src")
+$LOAD_PATH.unshift src
+$LOAD_PATH.unshift File.join(src, "lib")
require 'cairo'
@@ -12,22 +17,28 @@
surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, width, height)
context = Cairo::Context.new(surface)
-context.set_source_rgb(1, 1, 1)
+context.set_source_color(:white)
context.paint
-context.set_source_rgb(0.3, 0.3, 0.3)
+module Cairo
+ module Color
+ GRAY30 = Cairo::Color::RGB.new(0.3, 0.3, 0.3)
+ end
+end
+
+context.set_source_color(:gray30)
context.rectangle(margin, margin, rectangle_width, rectangle_height)
context.fill
context.pseudo_blur do
- context.set_source_rgb(0.3, 0.3, 0.3)
+ context.set_source_color(:gray30)
context.rectangle(margin, rectangle_height + 2 * margin + margin / 2,
rectangle_width, rectangle_height)
context.fill
end
context.pseudo_blur(5) do
- context.set_source_rgb(0.3, 0.3, 0.3)
+ context.set_source_color(:gray30)
context.rectangle(margin, (rectangle_height + 2 * margin) * 2 + margin / 2,
rectangle_width, rectangle_height)
context.fill
Index: pac.rb
===================================================================
RCS file: /cvs/cairo/rcairo/samples/pac.rb,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- pac.rb 8 Apr 2007 06:04:02 -0000 1.7
+++ pac.rb 16 Apr 2007 07:31:43 -0000 1.8
@@ -15,42 +15,35 @@
HEIGHT = 595.275590551181
def pac(surface)
- white = [1, 1, 1]
- black = [0, 0, 0]
- magenta = [1, 0, 1]
- cyan = [0, 1, 1]
- yellow = [1, 1, 0]
- blue = [0, 0, 1]
-
cr = Cairo::Context.new(surface)
- cr.set_source_rgb(*black)
+ cr.set_source_color(:black)
cr.rectangle(0, 0, WIDTH, HEIGHT).fill
# Wall
- cr.set_source_rgb(*magenta)
+ cr.set_source_color(:magenta)
cr.rounded_rectangle(20, 80, 750, 20, 10)
cr.fill
- cr.set_source_rgb(*cyan)
+ cr.set_source_color(:cyan)
cr.rounded_rectangle(20, 80, 750, 20, 10)
cr.stroke
-
- cr.set_source_rgb(*magenta)
+
+ cr.set_source_color(:magenta)
cr.rounded_rectangle(20, 380, 750, 20, 10)
cr.fill
- cr.set_source_rgb(*cyan)
+ cr.set_source_color(:cyan)
cr.rounded_rectangle(20, 380, 750, 20, 10)
cr.stroke
-
+
# Body
- cr.set_source_rgb(*yellow)
+ cr.set_source_color(:yellow)
cr.fill do
cr.arc(150, 250, 100, 30 * (Math::PI / 180), 330 * (Math::PI / 180))
cr.line_to(150, 250)
end
# Dot
- cr.set_source_rgb(*yellow)
+ cr.set_source_color(:yellow)
cr.circle(250, 250, 20).fill
cr.circle(300, 250, 10).fill
cr.circle(350, 250, 10).fill
@@ -69,20 +62,20 @@
cr.line_to(525, 325)
cr.line_to(500, 350)
- cr.set_source_rgb(*blue)
+ cr.set_source_color(:blue)
cr.fill_preserve
- cr.set_source_rgb(*cyan)
+ cr.set_source_color(:cyan)
cr.stroke
# Ghost Eyes
- cr.set_source_rgb(*white)
+ cr.set_source_color(:white)
cr.rectangle(525, 200, 25, 25).fill
cr.rectangle(575, 200, 25, 25).fill
-
- cr.set_source_rgb(*black)
+
+ cr.set_source_color(:black)
cr.rectangle(525, 215, 10, 10).fill
cr.rectangle(575, 215, 10, 10).fill
-
+
cr.show_page
end
Index: pac2.rb
===================================================================
RCS file: /cvs/cairo/rcairo/samples/pac2.rb,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- pac2.rb 8 Apr 2007 06:04:02 -0000 1.7
+++ pac2.rb 16 Apr 2007 07:31:43 -0000 1.8
@@ -12,22 +12,15 @@
require "cairo"
def pac(surface, width, height)
- white = [1, 1, 1]
- black = [0, 0, 0]
- magenta = [1, 0, 1]
- cyan = [0, 1, 1]
- yellow = [1, 1, 0]
- blue = [0, 0, 1]
-
cr = Cairo::Context.new(surface)
# NOTE: You may need to set line width when use Cairo::Context#scale
cr.set_line_width(cr.line_width / [width, height].max)
-
+
cr.scale(width, height)
cr.save do
- cr.set_source_rgb(*black)
+ cr.set_source_color(:black)
cr.rectangle(0, 0, 1, 1)
cr.fill
end
@@ -40,30 +33,30 @@
wall1_y = 1 - 0.86
wall2_y = wall1_y + wall_space
wall_radius = 0.01
-
- cr.set_source_rgb(*magenta)
+
+ cr.set_source_color(:magenta)
cr.rounded_rectangle(wall_x, wall1_y, wall_width, wall_height, wall_radius)
cr.fill
- cr.set_source_rgb(*cyan)
+ cr.set_source_color(:cyan)
cr.rounded_rectangle(wall_x, wall1_y, wall_width, wall_height, wall_radius)
cr.stroke
-
- cr.set_source_rgb(*magenta)
+
+ cr.set_source_color(:magenta)
cr.rounded_rectangle(wall_x, wall2_y, wall_width, wall_height, wall_radius)
cr.fill
- cr.set_source_rgb(*cyan)
+ cr.set_source_color(:cyan)
cr.rounded_rectangle(wall_x, wall2_y, wall_width, wall_height, wall_radius)
cr.stroke
-
+
# Body
body_x = 0.17
body_y = 1 - 0.58
body_width = 0.23
body_height = 0.33
-
+
cr.save do
cr.translate(body_x, body_y)
- cr.set_source_rgb(*yellow)
+ cr.set_source_color(:yellow)
cr.scale(body_width, body_height)
cr.arc(0, 0, 0.5, 30 * (Math::PI / 180), 330 * (Math::PI / 180))
cr.line_to(0, 0)
@@ -79,9 +72,9 @@
dot_x = 0.29
dot_y = 1 - 0.58
dot_step = 0.05
-
+
cr.save do
- cr.set_source_rgb(*yellow)
+ cr.set_source_color(:yellow)
cr.save do
cr.translate(dot_x, dot_y)
cr.scale(dot_width, dot_height)
@@ -120,10 +113,10 @@
i += 1
end
cr.close_path
-
- cr.set_source_rgb(*blue)
+
+ cr.set_source_color(:blue)
cr.fill_preserve
- cr.set_source_rgb(*cyan)
+ cr.set_source_color(:cyan)
cr.stroke
# Ghost Eyes
@@ -135,15 +128,15 @@
black_eye_width = 0.01
black_eye_height = 0.02
- cr.set_source_rgb(*white)
+ cr.set_source_color(:white)
cr.rectangle(eye_x, eye_y - white_eye_height,
white_eye_width, white_eye_height)
cr.fill
cr.rectangle(eye_x + eye_space, eye_y - white_eye_height,
white_eye_width, white_eye_height)
cr.fill
-
- cr.set_source_rgb(*black)
+
+ cr.set_source_color(:black)
cr.rectangle(eye_x, eye_y - black_eye_height,
black_eye_width, black_eye_height)
cr.fill
Index: png.rb
===================================================================
RCS file: /cvs/cairo/rcairo/samples/png.rb,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- png.rb 8 Apr 2007 06:04:02 -0000 1.13
+++ png.rb 16 Apr 2007 07:31:43 -0000 1.14
@@ -17,7 +17,7 @@
cr = Cairo::Context.new(surface)
# fill background with white
- cr.set_source_rgba(1.0, 1.0, 1.0, 0.8)
+ cr.set_source_color("#fffc")
cr.paint
# create shape
@@ -27,9 +27,9 @@
cr.line_to(50, 150)
cr.close_path
- cr.set_source_rgb(0.0, 0.0, 0.0)
+ cr.set_source_color(:black)
cr.fill_preserve
- cr.set_source_rgb(1.0, 0.0, 0.0)
+ cr.set_source_color(:red)
cr.set_line_join(Cairo::LINE_JOIN_MITER)
cr.set_line_width(4)
cr.stroke
Index: scalable.rb
===================================================================
RCS file: /cvs/cairo/rcairo/samples/scalable.rb,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- scalable.rb 8 Apr 2007 06:12:50 -0000 1.5
+++ scalable.rb 16 Apr 2007 07:31:43 -0000 1.6
@@ -13,7 +13,7 @@
cr = Cairo::Context.new(surface)
# fill background with white
- cr.set_source_rgba(1.0, 1.0, 1.0, 0.8)
+ cr.set_source_color("#fffc")
cr.paint
# create shape
@@ -23,9 +23,9 @@
cr.line_to(50, 150)
cr.close_path
- cr.set_source_rgb(0.0, 0.0, 0.0)
+ cr.set_source_color(:black)
cr.fill_preserve
- cr.set_source_rgb(1.0, 0.0, 0.0)
+ cr.set_source_color(:red)
cr.set_line_join(Cairo::LINE_JOIN_MITER)
cr.set_line_width(4)
cr.stroke
Index: text-on-path.rb
===================================================================
RCS file: /cvs/cairo/rcairo/samples/text-on-path.rb,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- text-on-path.rb 8 Apr 2007 06:04:02 -0000 1.4
+++ text-on-path.rb 16 Apr 2007 07:31:43 -0000 1.5
@@ -9,7 +9,7 @@
require 'pango'
def render_background(cr)
- cr.set_source_rgba(1.0, 1.0, 1.0)
+ cr.set_source_color(:white)
cr.paint
end
@@ -28,7 +28,7 @@
render_background(cr)
- cr.set_source_rgba(1, 0, 0, 1)
+ cr.set_source_color(:red)
cr.move_to(25, 350)
cr.line_to(150, 375)
cr.curve_to(275, 400, 450, 350, 450, 200)
Index: text2.rb
===================================================================
RCS file: /cvs/cairo/rcairo/samples/text2.rb,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- text2.rb 8 Apr 2007 06:04:02 -0000 1.7
+++ text2.rb 16 Apr 2007 07:31:43 -0000 1.8
@@ -35,7 +35,7 @@
end
def render_background(cr)
- cr.set_source_rgba(1.0, 1.0, 1.0)
+ cr.set_source_color(:white)
cr.paint
end
@@ -50,9 +50,9 @@
def setup_fade_out(cr, width)
fade_out = Cairo::LinearPattern.new(0, 0, width, 0)
- fade_out.add_color_stop_rgba(0, 0, 0, 0, 1)
- fade_out.add_color_stop_rgba(0.66, 0, 0, 0, 1)
- fade_out.add_color_stop_rgba(1, 0, 0, 0, 0)
+ fade_out.add_color_stop(0, "#000f")
+ fade_out.add_color_stop(0.66, "#000f")
+ fade_out.add_color_stop(1, "#0000")
cr.set_source(fade_out)
end
@@ -101,7 +101,7 @@
if fade_out
setup_fade_out(cr, body_width)
else
- cr.set_source_rgba(0, 0, 0, 1)
+ cr.set_source_color(:black)
end
render_layout(cr, layout, margin_left, margin_top, body_height)
More information about the cairo-commit
mailing list