A simple and concise (474 bytes minified, 1KB normal) binary clock in Shoes.
Compatible with Shoes 2 (Raisins) and 3 (Policeman).
Design inspired by The Game of Life on the ShoeBox.
A simple and concise (474 bytes minified, 1KB normal) binary clock in Shoes.
Compatible with Shoes 2 (Raisins) and 3 (Policeman).
Design inspired by The Game of Life on the ShoeBox.
Shoes.app(:title=>"Binary Clock",:width=>304,:height=>172,:resizable=>false){ | |
on,off=rgb(0,0,255,0.45),gray(0,0);background rgb(6,6,89) | |
stroke gray(1.0,0.5);strokewidth 2.5;fill off | |
lights=Array.new(3){|i|Array.new(6){|j|next if j-i==5;x,y=250-j*44,30+i*44 | |
para 2**j,:size=>'xx-small',:left=>x+20,:top=>y+20,:stroke=>gray;oval x,y,24}} | |
lights[0].pop;every(1){now=Time.now;[now.hour,now.min,now.sec].zip(lights){|v,r| | |
r.each_with_index{|l,j|l.style:fill=>(v[j]==1?on:off)}}}} |
margin, space, width = 30, 20, 24 | |
with_help = true | |
Shoes.app :title => "Binary Clock", | |
:width => 6*width+5*space+2*margin, | |
:height => 3*width+2*space+2*margin, | |
:resizable => false do | |
on, off = rgb(0, 0, 255, 0.45), gray(0,0) | |
if Shoes::VERSION == 'Policeman' | |
background rgb(6, 6, 89) | |
else | |
background gradient(rgb(0, 0, 128), rgb(12, 12, 50)) | |
end | |
stroke gray(1.0, 0.5) | |
strokewidth 2.5 | |
fill off | |
lights = Array.new(3) { |i| | |
Array.new(6) { |j| | |
next if i == 0 and j == 5 # The first light is not needed for hours | |
x, y = margin + (5-j)*(space+width), margin + i*(space+width) | |
para 2**j, :size => 'xx-small', :left => x+20, :top => y+20, :stroke => gray if with_help | |
oval x, y, width | |
} | |
} and lights.first.compact! | |
every 1 do | |
now = Time.now | |
[now.hour, now.min, now.sec].zip(lights) { |v, row| | |
row.each_with_index { |light, i| | |
light.style :fill => (v[i] == 1 ? on : off) | |
} | |
} | |
end | |
end |