Skip to content

Instantly share code, notes, and snippets.

@toothrot
Forked from evanfarrar/sorty.rb
Created March 16, 2009 21:57
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 toothrot/80111 to your computer and use it in GitHub Desktop.
Save toothrot/80111 to your computer and use it in GitHub Desktop.
Shoes.app(:width => 200, :height => 70 * 4 + 40) do
background black
colors = [red, blue, green, yellow]
people = ["steve","ed","nick","tom"]
@next_color = colors.cycle
@next_color.next
@previous_color = colors.cycle
(colors.length - 1).times { @previous_color.next }
def names_n_colors(people, colors)
clear do
background black
names_n_colors = colors.zip(people).map do |color, person|
flow(:height => 70, :width => 200) do
border color, :strokewidth => 2
my_label = subtitle person, :stroke => white
fill @previous_color.next
rotate(90)
a = arrow(104, 5, 30)
a.click { names_n_colors(swap_previous(people, person), colors) }
fill @next_color.next
rotate(180)
a = arrow(90, 45, 30)
a.click { names_n_colors(swap_next(people, person), colors) }
end
end
button "ok!"
end
end
def swap_previous(array, item)
idx = array.index(item)
array[(idx-1) % array.length],array[idx] = array[idx],array[(idx-1) % array.length]
array
end
def swap_next(array, item)
idx = array.index(item)
array[(idx+1) % array.length],array[idx] = array[idx],array[(idx+1) % array.length]
array
end
names_n_colors(people, colors)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment