Skip to content

Instantly share code, notes, and snippets.

@ashbb
Created August 2, 2012 11:42
Show Gist options
  • Save ashbb/3236475 to your computer and use it in GitHub Desktop.
Save ashbb/3236475 to your computer and use it in GitHub Desktop.
Shoes Large Analog Clock written by Douglas Allen
# Shoes Large Analog Clock written by Douglas Allen
Shoes.app :width => 1024,
:height => 760,
:title => 'Welcome to Shoes' do
@radius = 600
@centerx = width / 2
@centery = height / 2
@msg = para ""#, margin: 4, align: 'center'
stack do
para ""
@msg
end
def big_oval
stroke yellowgreen
strokewidth 4
nofill
oval @centerx - @radius / 2, @centery - @radius / 2, @radius, @radius
end
def center_dot
fill yellowgreen
nostroke
oval @centerx - 7, @centery - 7, 14, 14
end
def hour_dot(x, y)
fill yellowgreen
nostroke
oval @centerx + x - 9, @centery + y - 9, 18, 18
end
def min_dot(x, y)
fill yellowgreen
nostroke
oval @centerx + x - 6, @centery + y - 6, 12, 12
end
def draw_background
background black
big_oval
center_dot
for i in 0..59
x_m = (@radius / 2) * Math.sin(i * Math::PI / 30)
y_m = (@radius / 2) * Math.cos(i * Math::PI / 30)
min_dot(x_m, y_m)
x = (@radius / 2) * Math.sin(i * Math::PI / 6)
y = (@radius / 2) * Math.cos(i * Math::PI / 6)
hour_dot(x, y)
end
end
def sec_dot(time, color)
x_s = (@radius / 2) * Math.sin(time * Math::PI / 30)
y_s = (@radius / 2) * Math.cos(time * Math::PI / 30)
fill color
nostroke
oval @centerx + x_s - 4, @centery - y_s - 4, 8, 8
end
def clock_hand(time, unit=30, color, sw)
radius_local = unit == 30 ? @radius / 2 - 8 : @radius / 2 - 55
_x = radius_local * Math.sin(time * Math::PI / unit)
_y = radius_local * Math.cos(time * Math::PI / unit)
stroke color
strokewidth sw
line(@centerx, @centery, @centerx + _x, @centery - _y)
end
def update_message(time)
@week_day = time.strftime("%a")
@date = time.strftime(" %b %d, %Y ")
@now = time.strftime("%H:%M:%S")
fg(@week_day, tr_color("#00f")) +
fg(@date, tr_color("#0f0")) +
strong(fg(@now, tr_color("#0f0"))) # +
#fg(t.strftime(".%S"), tr_color("#666"))
end
draw_background
animate(8) do
@time = Time.now
clear do
draw_background
stack do
#@msg.replace update_message(@time)
@hour = @time.hour + @time.min / 60.0
hour = clock_hand @hour, 6, yellowgreen, 10
@min = @time.min + @time.sec / 60.0
min = clock_hand @min, 30, yellowgreen, 5
@sec = @time.sec + (@time.usec * 0.000001)
sec = clock_hand @sec, 30, red, 2
sec = sec_dot(@sec, red)
sec
min
hour
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment