Skip to content

Instantly share code, notes, and snippets.

@toothrot
Forked from evanfarrar/sorty.rb
Created March 16, 2009 21:57

Revisions

  1. toothrot revised this gist Mar 16, 2009. 2 changed files with 3 additions and 3 deletions.
    Empty file removed gistfile2.txt
    Empty file.
    6 changes: 3 additions & 3 deletions sorty.rb
    Original file line number Diff line number Diff line change
    @@ -13,8 +13,8 @@ def names_n_colors(people, colors)
    background black
    names_n_colors = colors.zip(people).map do |color, person|
    flow(:height => 70, :width => 200) do
    border color
    my_label = subtitle person, :stroke => color
    border color, :strokewidth => 2
    my_label = subtitle person, :stroke => white
    fill @previous_color.next
    rotate(90)
    a = arrow(104, 5, 30)
    @@ -41,4 +41,4 @@ def swap_next(array, item)
    array
    end
    names_n_colors(people, colors)
    end
    end
  2. @evanfarrar evanfarrar created this gist Mar 16, 2009.
    Empty file added gistfile2.txt
    Empty file.
    44 changes: 44 additions & 0 deletions sorty.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    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
    my_label = subtitle person, :stroke => color
    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