File: cairo-gradient.rb

package info (click to toggle)
ruby-gnome2 3.1.0-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 16,072 kB
  • ctags: 17,433
  • sloc: ansic: 93,621; ruby: 62,273; xml: 335; sh: 246; makefile: 25
file content (35 lines) | stat: -rw-r--r-- 924 bytes parent folder | download | duplicates (10)
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
# Copyright (c) 2005 Ruby-GNOME2 Project Team
# This program is licenced under the same licence as Ruby-GNOME2.
#
# $Id: cairo-gradient.rb,v 1.2 2005/10/12 15:23:49 ktou Exp $
=begin
= cairo/Gradient

This demo shows how to use GDK and cairo to gradient.
From http://cairographics.org/samples/gradient.html.
=end
require 'common'

module Demo
  class CairoGradient < CairoWindow
    def initialize
      super('cairo gradient')
    end

    def draw(cr)
      pat = Cairo::LinearPattern.new(0.0, 0.0,  0.0, 1.0)
      pat.add_color_stop_rgb(1, 0, 0, 0)
      pat.add_color_stop_rgb(0, 1, 0, 0)
      cr.rectangle(0, 0, 1, 1)
      cr.set_source(pat)
      cr.fill

      pat = Cairo::RadialPattern.new(0.45, 0.4, 0.1, 0.4, 0.4, 0.5)
      pat.add_color_stop_rgba(0, 1, 1, 1, 0.8)
      pat.add_color_stop_rgba(1, 0, 0, 0)
      cr.set_source(pat)
      cr.arc(0.5, 0.5, 0.3, 0, 2 * Math::PI)
      cr.fill
    end
  end
end