Created
August 20, 2008 04:36
-
-
Save nakajima/6320 to your computer and use it in GitHub Desktop.
A pixel painting app for shoes, sort of like looklooksee.com.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LookLookSee < Shoes | |
url '/', :index | |
# TODO Use actual Shoes::Color objects for these values? | |
BACKGROUND = [20,20,20] | |
START_COLOR = [24,24,24] | |
HOVER_COLOR = [36,36,36] | |
PIXEL_SIZE = 20 | |
ANIMATING = { } | |
PAINTED = { } | |
@@painting = false | |
@@paint_color = [240,240,240] | |
# A pixel-painting app for Shoes | |
def index | |
nostroke | |
background rgb(*BACKGROUND) | |
release { @@painting = false } | |
500.times do | |
# TODO Subclass widget with a Pixel class | |
stack :width => PIXEL_SIZE, :height => PIXEL_SIZE, :margin_left => 1, :margin_bottom => 1 do | |
background rgb(*START_COLOR) | |
hover { |p| handle_hover(p) unless PAINTED[p] } | |
leave { |p| handle_leave(p) unless PAINTED[p] } | |
click { @@painting = true } | |
end | |
end | |
button("Reset") do | |
@@painting = false | |
PAINTED.keys.each do |p| | |
PAINTED.delete(p) | |
handle_leave(p) | |
end | |
end | |
button("Color") do | |
m = ask_color("Pick a Color").inspect.match(/rgb\((\d+), (\d+), (\d+)\)/) | |
@@paint_color = [m[1], m[2], m[3]].map { |p| p.to_i } | |
end | |
animate(60) do | |
ANIMATING.each { |p, c| fade(p, c) } | |
end | |
end | |
private | |
def handle_hover(pixel) | |
@@painting ? paint(pixel) : pixel.background(rgb(*HOVER_COLOR)) | |
end | |
def handle_leave(pixel) | |
ANIMATING[pixel] = HOVER_COLOR.first unless @@painting | |
end | |
def fade(pixel, color) | |
ANIMATING.delete(pixel) and return if color <= START_COLOR.first | |
ANIMATING[pixel] = color -= 2 | |
pixel.background rgb(color,color,color) | |
end | |
def paint(pixel) | |
return if PAINTED[pixel] | |
pixel.background rgb(*@@paint_color) | |
PAINTED[pixel] = true | |
end | |
end | |
Shoes.app :height => 436, :width => 500, :title => 'looklooksee' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment