Skip to content

Instantly share code, notes, and snippets.

@melborne
Created July 24, 2008 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melborne/1981 to your computer and use it in GitHub Desktop.
Save melborne/1981 to your computer and use it in GitHub Desktop.
some ruby_Shoes sample codes
@app = Shoes.app do
img0 = ask_open_file #select a first image in sequence.
NUM_IMGS = 5
imgs = []
NUM_IMGS.times do |n|
imgs << img0.sub(/\d+/) { |m| n }
end
background black
@stack = stack :top => 30, :left => 30 do end
animate 5 do |i|
@stack.clear do
image imgs[i%NUM_IMGS]
end
end
end
Shoes.app :width => 1500 do
@w = 50
(width/@w).times do |n|
background rgb((0.0..0.5).rand,(0.3..1.0).rand,(0.1..0.7).rand),
:width => @w*(n+1), :margin_left => @w*n
end
end
CHeight = 20
Shoes.app :width => 450, :height => CHeight*17, :resizable => false do
@sec = {}
flow :width => '100%' do
15.times do |i|
s = stack :width => width/15, :height => CHeight do
background black
end
@sec[(i+53)%60] = s
end
end
flow :width => '100%' do
stack :width => width/15 do
15.times do |i|
s = flow :width => '100%', :height => CHeight do
background black
inscription ''
end
@sec[52-i] = s
end
end
stack :width => (width - width/15*2) do
begin
background "sea.jpg"
rescue
background '#eed'
end
@time = title
@time.move width/2-60, CHeight*7
end
stack :width => width/15 do
15.times do |i|
s = flow :width => '100%', :height => CHeight do
background black
inscription ''
end
@sec[i+8] = s
end
end
end
flow :width => '100%' do
15.times do |i|
s = stack :width => width/15, :height => CHeight do
background black
inscription ""
end
@sec[37-i] = s
end
end
every 1 do
t = Time.now
@time.text = t.strftime("%H:%M:%S")
@sec.values.each { |s| s.background black } if t.sec == 0
@sec[t.sec].background rgb((0.0..1.0).rand,(0.0..1.0).rand,(0.0..1.0).rand)
end
end
Shoes.app :width => 400, :height => 400 do
background "#eed"
stack do
@r = para strong("Ruby"), :stroke => "#7B0B00"
@s = para strong("Shoes"), :stroke => "#425506"
end
stack :margin => width/2-70 do
@meet = image "http://www.logomaker.com/logo-images/0eadc93f63584ade.gif"
@meet.hide
end
motion do |x, y|
@s.move x - 50, y - 20
@r.move width - x, height - y
@meet.show if @r.top == @s.top && @r.left == @s.left
end
@meet.click { @meet.hide }
end
# ScanAnimaker is a image creater for using ScanAnimator.
# Each image must have sequence number which start from 0.
# ex. img0.png, img1.png, img2.png...
Shoes.app do
BASE_IMG = ask_open_file
NUM_IMGS = 5 #ask("Please enter number of images").to_i
MASK_WIDTH = 1
IMG_WIDTH, IMG_HEIGHT = imagesize(BASE_IMG)
def make_mask(id)
mask do
(IMG_WIDTH / (MASK_WIDTH*NUM_IMGS) ).ceil.times do |i|
strokewidth MASK_WIDTH
stroke white
x_pos = MASK_WIDTH*id + i*MASK_WIDTH*NUM_IMGS
line x_pos, 0, x_pos, IMG_HEIGHT
end
end
end
background black
NUM_IMGS.times do |i|
stack :top => 0, :left => 0 do
make_mask i
image BASE_IMG.sub(/\d+/, i.to_s)
end
end
stack :top => IMG_HEIGHT, :left => 0 do
(IMG_WIDTH / (MASK_WIDTH*NUM_IMGS) ).times do |i|
strokewidth MASK_WIDTH
stroke white
x_pos = MASK_WIDTH + i*MASK_WIDTH*NUM_IMGS
line x_pos, 0, x_pos, IMG_HEIGHT+10
end
end
end
# ScanAnimator is viewer of a image which create with ScanAnimaker.
Shoes.app do
IMAGE = ask_open_file
NUM_IMGS = 5
MASK_WIDTH = 1
IMG_WIDTH, IMG_HEIGHT = imagesize(IMAGE)
background black
stack :top => 30, :left => 30 do
@mask = mask do
(IMG_WIDTH / (MASK_WIDTH*NUM_IMGS) ).ceil.times do |i|
strokewidth MASK_WIDTH
stroke white
x_pos = i*MASK_WIDTH*NUM_IMGS
line x_pos, 0, x_pos, IMG_HEIGHT
end
end
image IMAGE
end
animate 3 do |i|
@mask.move i%NUM_IMGS, 0
end
end
Shoes.app do
background "#eed"
BLOCKS = %w(banner title subtitle tagline caption para inscription)
FORMATS = %w(em del strong ins link span span)
@title = "Hello, Shoes!"
@text_objs = []
BLOCKS.each_with_index do |t, i|
stack do
flow do
para "#{t} & #{FORMATS[i]}: "
@text_objs << send(t, send(FORMATS[i], @title))
end
end
end
animate 10 do |f|
@text_objs.each_with_index do |t, i|
i += 1
t.displace(0, (Math.sin(f)*i*2).to_i)
t.style(:stroke => rgb((0.0..1.0).rand,(0.0..1.0).rand,(0.0..1.0).rand))
end
end
end
W = 300; H = 300
BG1 = '#fff'; BG2 = '#fff'
Shoes.app :width => W, :height => H, :resizable => false do
def slide_animation(pattern)
color = ''
if @st.height <= 10 or @st.width <= 10
case pattern
when 'vertical'
@st.width = W; @st.height = 0
p = lambda { |a| @st.height += 10; a.stop if @st.height >= H }
color = BG1
when 'horizontal'
@st.height = H; @st.width = 0
p = lambda { |a| @st.width += 10; a.stop if @st.width >= W }
color = BG1
end
else
case pattern
when 'vertical'
p = lambda { |a| @st.height -= 10; a.stop if @st.height <= 0 }
color = BG2
when 'horizontal'
p = lambda { |a| @st.width -= 10; a.stop if @st.width <= 0 }
color = BG2
end
end
a = animate 60 do
p.call a
end
@clock.style(:stroke => color)
end
background BG1
@st = stack :width => W, :height => H do
background BG2
end
clock = stack :width => W, :height => H do
@clock = title ''
end
clock.move((W-190)/2, (H-60)/2)
every 1 do
BG2 = rgb((0.0..0.9).rand, (0.0..0.9).rand, (0.0..0.9).rand)
@st.background BG2
slide_animation(['vertical','horizontal'][rand(2)])
time = Time.now
if (55..59).include?(time.sec)
@clock.style(:stroke => '#b00')
end
@clock.text = time.strftime("%H %M %S")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment