<   2011年 02月 ( 10 )   > この月の画像一覧

ruby/ioおもしろすぎ。
Linuxの楽しさが、まるごと使える感じだ。
今回は、Graphvizだ。

sudo apt-get install graphviz

参考ページ
http://d.hatena.ne.jp/h-yano/20060727/1154010884

pngファイルをつくるのは

eval = <<EOF
digraph sample1 {
node1 -> node2;
node1 -> node3;
node2 -> node3;
node3 -> node4;
}
EOF
IO.popen("dot -Tpng -o sample.png","r+") {|io|
io.puts(eval)
}

ruby/sdlに乗せるには、


#!usr/bin/env ruby

require 'rubygems'
require 'sdl'
require "stringio"

class Item
def initialize(screen)
@screen = screen
eval = <<EOF
digraph sample1 {
node1 -> node2;
node1 -> node3;
node2 -> node3;
node3 -> node4;
}
EOF
IO.popen("dot | convert - bmp:-","r+") {|io|
io.puts(eval)
io.close_write
StringIO.open(io.read){|s| @surface = SDL::Surface.load_bmp_from_io(s)}
}
@x,@y = 10,10
end

def update
@screen.put(@surface,@x,@y)
end
end

class Phase
def initialize(screen)
@screen = screen
@item = Item.new(@screen)
end

def update
@item.update
end

def handling(event)
exit if event.kind_of?(SDL::Event::Quit) || (event.kind_of?(SDL::Event::KeyDown) && event.sym == SDL::Key::ESCAPE)
end

def run
loop do
while e=SDL::Event.poll
handling(e)
end
update
@screen.flip
SDL.delay(50)
end
end
end

SDL.init(SDL::INIT_EVERYTHING)
screen = SDL::setVideoMode(180,350,16,SDL::SWSURFACE)
Phase.new(screen).run
[PR]
by gaziya | 2011-02-19 11:02
ruby/ioでRを使い回せないか、色々試してみた。
ちょっと、トリッキーだけど、見つけた。
これで、スッキリした。

eval = <<EOF
sqrt(2)
sqrt(3)
sqrt(5)
EOF
io = IO.popen("R -q --no-save", "r+")
io.read(2)
eval.each do |e|
io.puts(e)
io.gets
out = ""
loop do
head = io.read(2)
break if head == "> "
out << head + io.gets
end
p out
end
io.close_write
io.read
io.close

<後日記>
もう少しスッキリした奴をクラスを使って書き直しました。
http://gaziya.exblog.jp/15745185/
こちら
[PR]
by gaziya | 2011-02-18 23:54
よくよく、リファレンスを読んでみれば、StringIOが使えるって書いてあるじゃないか。
気づくのに時間が、かかった。

require "stringio"
してから

url = "http://cairographics.org/cairo-banner.png"
IO.popen("wget -q -O - #{url} | convert - bmp:-") do |io|
StringIO.open(io.read){|s| @surface = SDL::Surface.load_bmp_from_io(s)}
end

これで、OKだって。
convertで画像処理してから使うなら

url = "http://cairographics.org/cairo-banner.png"
IO.popen("wget -q -O - #{url} | convert - bmp:-"){|io| @data = io.read}
IO.popen("convert -resize 75% - -" ,"r+") do |io|
io.write(@data)
io.close_write
StringIO.open(io.read){|s| @surface = SDL::Surface.load_bmp_from_io(s)}
end

こんな感じ。
これで、 rcairo 無しで surfaceに読み込める。
わかれば、こんなもんなんだよね。ちょっと、悩みすぎたよ。
[PR]
by gaziya | 2011-02-15 19:17
Rも試した。
インストールは
sudo apt-get install r-base-core

io.read から受け取れるデータを画像データにするのは、難しそう。
とりあえず、一時ファイルに、置いてから SDL::Surface.load で読み取る方法でやってみた。

#!usr/bin/env ruby

require 'rubygems'
require 'sdl'

class Cell
def initialize(screen)
@screen = screen
IO.popen("R -q --no-save", "r+") do |io|
io.puts("png('/tmp/in.png', width=400, height=250)")
io.puts("hist(rnorm(20000), nc=20)")
io.puts("dev.off()")
io.puts("q()")
io.read
end
@surface = SDL::Surface.load("/tmp/in.png")
@x,@y = 25,25
end

def update
@screen.put(@surface,@x,@y)
end
end

class Phase
def initialize(screen)
@screen = screen
@item = Cell.new(@screen)
end

def update
@item.update
end

def handling(event)
exit if event.kind_of?(SDL::Event::Quit) || (event.kind_of?(SDL::Event::KeyDown) && event.sym == SDL::Key::ESCAPE)
end

def run
loop do
while e=SDL::Event.poll
handling(e)
end
update
@screen.flip
SDL.delay(50)
end
end
end

SDL.init(SDL::INIT_EVERYTHING)
screen = SDL::setVideoMode(450,300,16,SDL::SWSURFACE)
Phase.new(screen).run
[PR]
by gaziya | 2011-02-11 17:33
gnuplot も試した。
まず
sudo apt-get install gnuplot-nox gnuplot-x11

convertを使って縮小した。
こんな感じ

#!usr/bin/env ruby

require 'rubygems'
require 'sdl'
require 'cairo'

class Cell
def initialize(screen)
@screen = screen
IO.popen("gnuplot" ,"r+") do |io|
io.puts("set terminal png")
io.puts("set output")
io.puts("plot sin(x)")
io.close_write
@data = io.read
end
IO.popen("convert - -resize 60% -" ,"r+") do |io|
io.write(@data)
io.close_write
@image = Cairo::ImageSurface.from_png(io)
end
stride = Cairo::Format.stride_for_width(C_FORMAT,@image.width)
@surface = SDL::Surface.new_from(@image.data,@image.width,@image.height,32,stride,R,G,B,A)
@x,@y = 30,30
end

def update
@screen.put(@surface,@x,@y)
end
end

class Phase
def initialize(screen)
@screen = screen
@item = Cell.new(@screen)
end

def update
@item.update
end

def handling(event)
exit if event.kind_of?(SDL::Event::Quit) || (event.kind_of?(SDL::Event::KeyDown) && event.sym == SDL::Key::ESCAPE)
end

def run
loop do
while e=SDL::Event.poll
handling(e)
end
update
@screen.flip
SDL.delay(50)
end
end
end

C_FORMAT = Cairo::FORMAT_ARGB32
R,G,B,A = 0x00FF0000,0x0000FF00,0x000000FF,0xFF000000
SDL.init(SDL::INIT_EVERYTHING)
SDL::WM.set_caption("Rotate","")
screen = SDL::setVideoMode(450,350,16,SDL::SWSURFACE)
Phase.new(screen).run
[PR]
by gaziya | 2011-02-11 12:56
ruby/ioに標準入力を入れる方法が、やっと判ったよ。

IO.popen("convert - -rotate 45 -" ,"r+") do |io|
io.write(@data)
io.close_write
@image = Cairo::ImageSurface.from_png(io)
end

io.close_write で、入力のパイプを閉じる事が必要だったみたい。
でも、新たなる課題が、
SDL::Surface.load_bmp_from_io(io)
を使えば rcairo を通さずに直接 ruby/sdl に送れると思ったが、エラーがでる。
あと、回転させたイメージの余白が透明にならない。
でも、これで、出来る事の幅が広がった。

convertのオプションは、ここ
http://www5a.biglobe.ne.jp/~nkgwtty/njaLinuxImageMagick.html
他にも色々画像処理できそうだ。

#!usr/bin/env ruby

require 'rubygems'
require 'sdl'
require 'cairo'

class Cell
def initialize(screen)
@screen = screen
url = "http://cairographics.org/cairo-banner.png"
IO.popen("wget -q -O - #{url} | convert - -resize 50% -"){|io| @data = io.read}
@x,@y,@r = 15,15,0
end

def update
@r += 3
@r = 0 if @r > 359
IO.popen("convert - -rotate #{@r} -" ,"r+") do |io|
io.write(@data)
io.close_write
@image = Cairo::ImageSurface.from_png(io)
end
stride = Cairo::Format.stride_for_width(C_FORMAT,@image.width)
@surface = SDL::Surface.new_from(@image.data,@image.width,@image.height,32,stride,R,G,B,A)
@screen.put(@surface,@x,@y)
end
end

class Phase
def initialize(screen)
@screen = screen
@item = Cell.new(@screen)
end

def update
@screen.fill_rect(0,0,@screen.w,@screen.h,[200,200,200])
@item.update
end

def handling(event)
exit if event.kind_of?(SDL::Event::Quit) || (event.kind_of?(SDL::Event::KeyDown) && event.sym == SDL::Key::ESCAPE)
end

def run
loop do
while e=SDL::Event.poll
handling(e)
end
update
@screen.flip
SDL.delay(50)
end
end
end

C_FORMAT = Cairo::FORMAT_ARGB32
R,G,B,A = 0x00FF0000,0x0000FF00,0x000000FF,0xFF000000
SDL.init(SDL::INIT_EVERYTHING)
SDL::WM.set_caption("Rotate","")
screen = SDL::setVideoMode(230,230,16,SDL::SWSURFACE)
Phase.new(screen).run
[PR]
by gaziya | 2011-02-11 10:23
もう、ちょっと煮詰めてみた。
今回、IO.readを初めて試した。
それで、これ

url = "http://weather.yahoo.co.jp/weather/"
IO.popen("wget -q -O - %s 2" % url) do |io|
if /satellite.html(.*?)width/ =~ io.read
if /(http.*?)"/ =~ $1
url = $1
end
end
end

urlからダイレクトに rcairo にイメージを読み込むには

io = IO.popen("wget -q -O - %s | convert - png:-" % url)
image = Cairo::ImageSurface.from_png(io)
io.close
[PR]
by gaziya | 2011-02-05 12:01
この前は、convertを使ってファイル変換するときに、一旦ハードディスクに保存した。
今度は、ハードディスクを通さない方法を見つけた。
他の形式のファイルも使えると思う。

filename = "input.jpg"
io = IO.popen("convert %s png:-" % filename)
image = Cairo::ImageSurface.from_png(io)
io.close
[PR]
by gaziya | 2011-02-05 11:24
日本語の入力をしたいと思い ruby/tk を試した。
インストールは
sudo apt-get install libtcltk-ruby

Tk.mainloopを終わらせた後に、再度Tk.mainloopだと、エラーがでる。
やっと見つけた。
http://bibibi.info/d/20071213.html
なんとか、Okだ。
Tk.chooseColorを使うとエラーがでる。
これは、保留だ。
で、

text = ''
TkCore::INTERP.restart
TkLabel.new(nil, 'text'=>'Input Text.').pack
entry = TkEntry.new.pack
TkButton.new(nil, 'text'=>'OK', 'command'=>proc{ text = entry.value; Tk.exit}).pack
Tk.mainloop
text

こんな感じで使う。
ruby/tkを設定用のウインドウに使うのは、楽でいいなと思う。
これで、使いかってのよさが、上がった。


#!usr/bin/env ruby

require 'rubygems'
require 'sdl'
require 'cairo'
require 'tk'

class EventHandle
def initialize(hash)
struct = Struct.new(:event,:const,:method)
@handle = {}
hash.each do |key,value|
event,const = key
if const
if event == SDL::Event::KeyDown || event == SDL::Event::KeyUp
@handle[struct.new(event,const,:sym)] = value
elsif event == SDL::Event::MouseButtonDown || event == SDL::Event::MouseButtonUp
@handle[struct.new(event,const,:button)] = value
end
else
@handle[struct.new(event)] = value
end
end
end

def match?(key,event)
if key.const
event.kind_of?(key.event) && key.const == event.method(key.method).call
else
event.kind_of?(key.event)
end
end

def handling(event)
@handle.each do |key,value|
return value.call(event) if match?(key,event)
end
nil
end
end

class Display
attr_reader :text

def initialize(screen)
@screen = screen
@x,@y = 20,20
end

def text=(text)
@text = text
@width,@height = 300,80
@stride = Cairo::Format.stride_for_width(C_FORMAT,@width)
@surface = SDL::Surface.new_from(image.data,@width,@height,32,@stride,R,G,B,A)
end

def image
img = Cairo::ImageSurface.new(C_FORMAT,@width,@height)
Cairo::Context.new(img) do |c|
c.set_source_color(Cairo::Color::LIGHT_SEA_GREEN)
c.font_size = 30
c.move_to(20,30)
c.show_text(@text)
end
img
end

def update
@screen.put(@surface,@x,@y)
end
end

class Label
attr_writer :x,:y
attr_reader :handle

def initialize(screen)
@screen = screen
@handle = EventHandle.new(
SDL::Event::MouseMotion => proc{|event| mouse_motion(event)},
[SDL::Event::MouseButtonDown,SDL::Mouse::BUTTON_LEFT] => proc{|event| mouse_button_down(event)},
[SDL::Event::MouseButtonUp,SDL::Mouse::BUTTON_LEFT] => proc{|event| mouse_motion(event)}
)
end

def text=(text)
@text = text
@width,@height = 80,30
@stride = Cairo::Format.stride_for_width(C_FORMAT,@width)
@surface = {}
@surface_key = :up
{
:on => Cairo::Color::YELLOW,
:up => Cairo::Color::SNOW,
:down => Cairo::Color::RED
}.each do |key,value|
@color = value
@surface[key] = SDL::Surface.new_from(image.data,@width,@height,32,@stride,R,G,B,A)
end
end

def image
img = Cairo::ImageSurface.new(C_FORMAT,@width,@height)
Cairo::Context.new(img) do |c|
c.set_source_color(@color)
c.font_size = 20
c.move_to(0,20)
c.show_text(@text)
end
img
end

def collide_point?(x,y)
@x < x && @x + @width > x && @y < y && @y + @height > y
end

def mouse_motion(event)
if collide_point?(event.x,event.y)
@surface_key = :on
else
@surface_key = :up
end
nil
end

def mouse_button_down(event)
if collide_point?(event.x,event.y)
@surface_key = :down
return action
end
nil
end

def action
nil
end

def update
@screen.put(@surface[@surface_key],@x,@y)
end
end

class Label_text < Label
def initialize(screen)
super
@x,@y = 20,80
self.text = "文字入力"
end

def action
text = ''
TkCore::INTERP.restart
TkLabel.new(nil, 'text'=>'Input Text.').pack
entry = TkEntry.new.pack
TkButton.new(nil, 'text'=>'OK', 'command'=>proc{ text = entry.value; Tk.exit}).pack
Tk.mainloop
text
end
end

class Label_exit < Label
def initialize(screen)
super
@x,@y = 180,80
self.text = "終了"
end
def action
exit
end
end

class Phase
def initialize(screen)
@screen = screen
@display = Display.new(@screen)
@display.text = "Tk Input"
@controls = []
@controls << Label_text.new(@screen)
@controls << Label_exit.new(@screen)
@handle = EventHandle.new(
SDL::Event::Quit => proc{exit},
[SDL::Event::KeyDown,SDL::Key::ESCAPE] => proc{exit}
)
end

def update
@screen.fill_rect(0,0,@screen.w,@screen.h,[0,0,0])
@display.update
@controls.each do |obj|
obj.update
end
end

def handling(event)
@handle.handling(event)
@controls.each do |obj|
if text = obj.handle.handling(event)
@display.text = text
end
end
end

def run
loop do
while event=SDL::Event.poll
handling(event)
end
update
@screen.flip
SDL.delay(50)
end
end
end

C_FORMAT = Cairo::FORMAT_ARGB32
R,G,B,A = 0x00FF0000,0x0000FF00,0x000000FF,0xFF000000
SDL.init(SDL::INIT_EVERYTHING)
SDL::WM.set_caption("Tk Input","")
screen = SDL::setVideoMode(300,120,16,SDL::SWSURFACE)
Phase.new(screen).run
[PR]
by gaziya | 2011-02-04 20:33
rcairo用のカラーパレットをつくった。
以前作った奴の焼き直し。
最初に
sudo apt-get install xclip
で、xclipをインストールしておく。
色のラベルをクリックすると
Cairo::Color::FOREST_GREEN
など、クリップボードに色のクラス名がコピーされる。


#!usr/bin/env ruby

require 'rubygems'
require 'sdl'
require 'cairo'

class EventHandle
def initialize(hash)
struct = Struct.new(:event,:const,:method)
@handle = {}
hash.each do |key,value|
event,const = key
if const
if event == SDL::Event::KeyDown || event == SDL::Event::KeyUp
@handle[struct.new(event,const,:sym)] = value
elsif event == SDL::Event::MouseButtonDown || event == SDL::Event::MouseButtonUp
@handle[struct.new(event,const,:button)] = value
end
else
@handle[struct.new(event)] = value
end
end
end

def match?(key,event)
if key.const
event.kind_of?(key.event) && key.const == event.method(key.method).call
else
event.kind_of?(key.event)
end
end

def handling(event)
@handle.each do |key,value|
return value.call(event) if match?(key,event)
end
nil
end
end

class Back_ground
attr_reader :color

def initialize(screen)
@screen = screen
@width,@height = @screen.w,@screen.h
@color = Cairo::Color::DIM_GRAY
@stride = Cairo::Format.stride_for_width(C_FORMAT,@width)
@surface = SDL::Surface.new_from(image.data,@width,@height,32,@stride,R,G,B,A)
end

def image
img = Cairo::ImageSurface.new(C_FORMAT,@width,@height)
Cairo::Context.new(img) do |c|
c.set_source_color(@color)
c.rectangle(0,0,@width,@height)
c.fill
end
img
end

def update
@screen.put(@surface,0,0)
end
end

class Box
attr_writer :x,:y

def initialize(screen)
@screen = screen
@width,@height = 80,30
@stride = Cairo::Format.stride_for_width(C_FORMAT,@width)
end

def color=(color)
@color = color
@surface = SDL::Surface.new_from(image.data,@width,@height,32,@stride,R,G,B,A)
end

def image
img = Cairo::ImageSurface.new(C_FORMAT,@width,@height)
Cairo::Context.new(img) do |c|
c.set_source_color(@color)
c.rectangle(0,0,@width,@height)
c.fill_preserve
c.set_source_rgb(0, 0, 0)
c.stroke
end
img
end

def update
@screen.put(@surface,@x,@y)
end
end

class Label
attr_writer :x,:y
attr_reader :handle

def initialize(screen)
@screen = screen
@handle = EventHandle.new(
SDL::Event::MouseMotion => proc{|event| mouse_motion(event)},
[SDL::Event::MouseButtonDown,SDL::Mouse::BUTTON_LEFT] => proc{|event| mouse_button_down(event)},
[SDL::Event::MouseButtonUp,SDL::Mouse::BUTTON_LEFT] => proc{|event| mouse_motion(event)}
)
end

def text=(text)
@text = text
@width,@height = @text.size * 15,30
@stride = Cairo::Format.stride_for_width(C_FORMAT,@width)
@surface = {}
@surface_key = :up
{
:on => Cairo::Color::YELLOW,
:up => Cairo::Color::SNOW,
:down => Cairo::Color::RED
}.each do |key,value|
@color = value
@surface[key] = SDL::Surface.new_from(image.data,@width,@height,32,@stride,R,G,B,A)
end
end

def image
img = Cairo::ImageSurface.new(C_FORMAT,@width,@height)
Cairo::Context.new(img) do |c|
c.set_source_color(@color)
c.font_size = 20
c.move_to(0,20)
c.show_text(@text)
end
img
end

def collide_point?(x,y)
@x < x && @x + @width > x && @y < y && @y + @height > y
end

def mouse_motion(event)
if collide_point?(event.x,event.y)
@surface_key = :on
else
@surface_key = :up
end
nil
end

def mouse_button_down(event)
if collide_point?(event.x,event.y)
@surface_key = :down
return action
end
nil
end

def action
nil
end

def update
@screen.put(@surface[@surface_key],@x,@y)
end
end

class Lable_color < Label
def action
IO.popen("echo -n %s | xclip" % "Cairo::Color::#{@text}").close
end
end

class Label_prev < Label
def initialize(screen)
super
@x,@y = 50,380
self.text = "Prev"
end

def action
-10
end
end

class Label_next < Label
def initialize(screen)
super
@x,@y = 225,380
self.text = "Next"
end

def action
10
end
end

class Label_exit < Label
def initialize(screen)
super
@x,@y = 400,380
self.text = "Exit"
end

def action
exit
end
end

class Phase
def initialize(screen)
@screen = screen
@bg = Back_ground.new(@screen)
@colors = []
Pallette.each{|key,value| @colors << [key.to_s,value]}
@colors.sort!{|a,b| a[0] <=> b[0]}
@idx = 0
skip = 32
@boxes = []
10.times do |i|
obj = Box.new(@screen)
obj.x,obj.y = 50,i * skip + 35
@boxes << obj
end
@labels = []
10.times do |i|
obj = Lable_color.new(@screen)
obj.x,obj.y = 150,i * skip + 38
@labels << obj
end
display_labels
@controls = []
@controls << Label_prev.new(@screen)
@controls << Label_next.new(@screen)
@controls << Label_exit.new(@screen)
@handle = EventHandle.new(
SDL::Event::Quit => proc{exit},
[SDL::Event::KeyDown,SDL::Key::ESCAPE] => proc{exit}
)
end

def display_labels
10.times do |i|
if @colors[@idx + i]
@boxes[i].color = @colors[@idx + i][1]
@labels[i].text = @colors[@idx + i][0]
else
@boxes[i].color = @bg.color
@labels[i].text = " "
end
end
end

def update
@bg.update
@boxes.each do |obj|
obj.update
end
@labels.each do |obj|
obj.update
end
@controls.each do |obj|
obj.update
end
end

def handling(event)
@handle.handling(event)
@labels.each do |obj|
obj.handle.handling(event)
end
@controls.each do |obj|
if range = obj.handle.handling(event)
@idx += range
display_labels
end
end
end

def run
loop do
while event=SDL::Event.poll
handling(event)
end
update
@screen.flip
SDL.delay(50)
end
end
end

Pallette = {
:ALICE_BLUE => Cairo::Color::ALICE_BLUE,
:ANTIQUE_WHITE => Cairo::Color::ANTIQUE_WHITE,
:AQUA => Cairo::Color::AQUA,
:AQUAMARINE => Cairo::Color::AQUAMARINE,
:AZURE => Cairo::Color::AZURE,
:BEIGE => Cairo::Color::BEIGE,
:BISQUE => Cairo::Color::BISQUE,
:BLACK => Cairo::Color::BLACK,
:BLANCHED_ALMOND => Cairo::Color::BLANCHED_ALMOND,
:BLUE => Cairo::Color::BLUE,
:BLUE_VIOLET => Cairo::Color::BLUE_VIOLET,
:BROWN => Cairo::Color::BROWN,
:BURLY_WOOD => Cairo::Color::BURLY_WOOD,
:CADET_BLUE => Cairo::Color::CADET_BLUE,
:CHARTREUSE => Cairo::Color::CHARTREUSE,
:CHOCOLATE => Cairo::Color::CHOCOLATE,
:CORAL => Cairo::Color::CORAL,
:CORNFLOWER_BLUE => Cairo::Color::CORNFLOWER_BLUE,
:CORNSILK => Cairo::Color::CORNSILK,
:CRIMSON => Cairo::Color::CRIMSON,
:CYAN => Cairo::Color::CYAN,
:DARK_BLUE => Cairo::Color::DARK_BLUE,
:DARK_CYAN => Cairo::Color::DARK_CYAN,
:DARK_GOLDENROD => Cairo::Color::DARK_GOLDENROD,
:DARK_GRAY => Cairo::Color::DARK_GRAY,
:DARK_GREEN => Cairo::Color::DARK_GREEN,
:DARK_KHAKI => Cairo::Color::DARK_KHAKI,
:DARK_MAGENTA => Cairo::Color::DARK_MAGENTA,
:DARK_OLIVE_GREEN => Cairo::Color::DARK_OLIVE_GREEN,
:DARK_ORANGE => Cairo::Color::DARK_ORANGE,
:DARK_ORCHID => Cairo::Color::DARK_ORCHID,
:DARK_RED => Cairo::Color::DARK_RED,
:DARK_SALMON => Cairo::Color::DARK_SALMON,
:DARK_SEA_GREEN => Cairo::Color::DARK_SEA_GREEN,
:DARK_SLATE_BLUE => Cairo::Color::DARK_SLATE_BLUE,
:DARK_SLATE_GRAY => Cairo::Color::DARK_SLATE_GRAY,
:DARK_TURQUOISE => Cairo::Color::DARK_TURQUOISE,
:DARK_VIOLET => Cairo::Color::DARK_VIOLET,
:DEEP_PINK => Cairo::Color::DEEP_PINK,
:DEEP_SKY_BLUE => Cairo::Color::DEEP_SKY_BLUE,
:DIM_GRAY => Cairo::Color::DIM_GRAY,
:DODGER_BLUE => Cairo::Color::DODGER_BLUE,
:FIRE_BRICK => Cairo::Color::FIRE_BRICK,
:FLORAL_WHITE => Cairo::Color::FLORAL_WHITE,
:FOREST_GREEN => Cairo::Color::FOREST_GREEN,
:FUCHSIA => Cairo::Color::FUCHSIA,
:GAINSBORO => Cairo::Color::GAINSBORO,
:GHOST_WHITE => Cairo::Color::GHOST_WHITE,
:GOLD => Cairo::Color::GOLD,
:GOLDENROD => Cairo::Color::GOLDENROD,
:GRAY => Cairo::Color::GRAY,
:GREEN => Cairo::Color::GREEN,
:GREEN_YELLOW => Cairo::Color::GREEN_YELLOW,
:HONEYDEW => Cairo::Color::HONEYDEW,
:HOT_PINK => Cairo::Color::HOT_PINK,
:INDIAN_RED => Cairo::Color::INDIAN_RED,
:INDIGO => Cairo::Color::INDIGO,
:IVORY => Cairo::Color::IVORY,
:KHAKI => Cairo::Color::KHAKI,
:LAVENDER => Cairo::Color::LAVENDER,
:LAVENDER_BLUSH => Cairo::Color::LAVENDER_BLUSH,
:LAWN_GREEN => Cairo::Color::LAWN_GREEN,
:LEMON_CHIFFON => Cairo::Color::LEMON_CHIFFON,
:LIGHT_BLUE => Cairo::Color::LIGHT_BLUE,
:LIGHT_CORAL => Cairo::Color::LIGHT_CORAL,
:LIGHT_CYAN => Cairo::Color::LIGHT_CYAN,
:LIGHT_GOLDENROD_YELLOW => Cairo::Color::LIGHT_GOLDENROD_YELLOW,
:LIGHT_GREEN => Cairo::Color::LIGHT_GREEN,
:LIGHT_GREY => Cairo::Color::LIGHT_GREY,
:LIGHT_PINK => Cairo::Color::LIGHT_PINK,
:LIGHT_SALMON => Cairo::Color::LIGHT_SALMON,
:LIGHT_SEA_GREEN => Cairo::Color::LIGHT_SEA_GREEN,
:LIGHT_SKY_BLUE => Cairo::Color::LIGHT_SKY_BLUE,
:LIGHT_SLATE_GRAY => Cairo::Color::LIGHT_SLATE_GRAY,
:LIGHT_STEEL_BLUE => Cairo::Color::LIGHT_STEEL_BLUE,
:LIGHT_YELLOW => Cairo::Color::LIGHT_YELLOW,
:LIME => Cairo::Color::LIME,
:LIME_GREEN => Cairo::Color::LIME_GREEN,
:LINEN => Cairo::Color::LINEN,
:MAGENTA => Cairo::Color::MAGENTA,
:MAROON => Cairo::Color::MAROON,
:MEDIUM_AQUAMARINE => Cairo::Color::MEDIUM_AQUAMARINE,
:MEDIUM_BLUE => Cairo::Color::MEDIUM_BLUE,
:MEDIUM_ORCHID => Cairo::Color::MEDIUM_ORCHID,
:MEDIUM_PURPLE => Cairo::Color::MEDIUM_PURPLE,
:MEDIUM_SEA_GREEN => Cairo::Color::MEDIUM_SEA_GREEN,
:MEDIUM_SLATE_BLUE => Cairo::Color::MEDIUM_SLATE_BLUE,
:MEDIUM_SPRING_GREEN => Cairo::Color::MEDIUM_SPRING_GREEN,
:MEDIUM_TURQUOISE => Cairo::Color::MEDIUM_TURQUOISE,
:MEDIUM_VIOLET_RED => Cairo::Color::MEDIUM_VIOLET_RED,
:MIDNIGHT_BLUE => Cairo::Color::MIDNIGHT_BLUE,
:MINT_CREAM => Cairo::Color::MINT_CREAM,
:MISTY_ROSE => Cairo::Color::MISTY_ROSE,
:MOCCASIN => Cairo::Color::MOCCASIN,
:NAVAJO_WHITE => Cairo::Color::NAVAJO_WHITE,
:OLD_LACE => Cairo::Color::OLD_LACE,
:OLIVE => Cairo::Color::OLIVE,
:OLIVE_DRAB => Cairo::Color::OLIVE_DRAB,
:ORANGE => Cairo::Color::ORANGE,
:ORANGE_RED => Cairo::Color::ORANGE_RED,
:ORCHID => Cairo::Color::ORCHID,
:PALE_GOLDENROD => Cairo::Color::PALE_GOLDENROD,
:PALE_GREEN => Cairo::Color::PALE_GREEN,
:PALE_TURQUOISE => Cairo::Color::PALE_TURQUOISE,
:PALE_VIOLET_RED => Cairo::Color::PALE_VIOLET_RED,
:PAPAYA_WHIP => Cairo::Color::PAPAYA_WHIP,
:PEACH_PUFF => Cairo::Color::PEACH_PUFF,
:PERU => Cairo::Color::PERU,
:PINK => Cairo::Color::PINK,
:PLUM => Cairo::Color::PLUM,
:POWDER_BLUE => Cairo::Color::POWDER_BLUE,
:PURPLE => Cairo::Color::PURPLE,
:RED => Cairo::Color::RED,
:ROSY_BROWN => Cairo::Color::ROSY_BROWN,
:ROYAL_BLUE => Cairo::Color::ROYAL_BLUE,
:SADDLE_BROWN => Cairo::Color::SADDLE_BROWN,
:SALMON => Cairo::Color::SALMON,
:SANDY_BROWN => Cairo::Color::SANDY_BROWN,
:SEASHELL => Cairo::Color::SEASHELL,
:SEA_GREEN => Cairo::Color::SEA_GREEN,
:SIENNA => Cairo::Color::SIENNA,
:SILVER => Cairo::Color::SILVER,
:SKY_BLUE => Cairo::Color::SKY_BLUE,
:SLATE_BLUE => Cairo::Color::SLATE_BLUE,
:SLATE_GRAY => Cairo::Color::SLATE_GRAY,
:SNOW => Cairo::Color::SNOW,
:SPRING_GREEN => Cairo::Color::SPRING_GREEN,
:STEEL_BLUE => Cairo::Color::STEEL_BLUE,
:TAN => Cairo::Color::TAN,
:TEAL => Cairo::Color::TEAL,
:THISTLE => Cairo::Color::THISTLE,
:TOMATO => Cairo::Color::TOMATO,
:TURQUOISE => Cairo::Color::TURQUOISE,
:VIOLET => Cairo::Color::VIOLET,
:WHEAT => Cairo::Color::WHEAT,
:WHITE => Cairo::Color::WHITE,
:WHITE_SMOKE => Cairo::Color::WHITE_SMOKE,
:YELLOW => Cairo::Color::YELLOW,
:YELLOW_GREEN => Cairo::Color::YELLOW_GREEN
}

C_FORMAT = Cairo::FORMAT_ARGB32
R,G,B,A = 0x00FF0000,0x0000FF00,0x000000FF,0xFF000000
SDL.init(SDL::INIT_EVERYTHING)
SDL::WM.set_caption("Color Pallete","")
screen = SDL::setVideoMode(500,450,16,SDL::SWSURFACE)
Phase.new(screen).run
[PR]
by gaziya | 2011-02-01 21:15