Skip to content

Instantly share code, notes, and snippets.

@todesking
Created March 31, 2012 08:11
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 todesking/2260813 to your computer and use it in GitHub Desktop.
Save todesking/2260813 to your computer and use it in GitHub Desktop.
likestorm
require 'net/http'
def hsv_to_rgb(h, s, v)
h_i = (h*6).to_i
f = h*6 - h_i
p = v * (1 - s)
q = v * (1 - f*s)
t = v * (1 - (1 - f) * s)
r, g, b = v, t, p if h_i==0
r, g, b = q, v, p if h_i==1
r, g, b = p, v, t if h_i==2
r, g, b = p, q, v if h_i==3
r, g, b = t, p, v if h_i==4
r, g, b = v, p, q if h_i==5
[(r*256).to_i, (g*256).to_i, (b*256).to_i]
end
@h=0;@diff=0.001
def gen_uri(color);URI.parse("http://reallike.geekday.jp/?post=1&color=#{color}");end
def like n,w=0;n.times{|i| sleep w;Thread.start{ Net::HTTP.get(get_uri);puts i } }; end
# 1
def get_uri; u=gen_uri('%02x%02x%02x'%hsv_to_rgb(@h,0.99,0.99)) ; @h=@h+@diff;@h=0 if @h>0.99; u;end
# 2
@i=0
@c=['FF0000','0000FF','00FF00']
@cycle=100
def get_uri; u=gen_uri(@c[(@i/@cycle)% @c.length]); @i+=1; u; end
# 3
@color='FF0000'
def get_uri; gen_uri @color; end
# 10.times {|i| @color=@c[i% @c.length]; like 100; sleep 1 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment