Skip to content

Instantly share code, notes, and snippets.

@komiyake
Created December 12, 2014 03:37
Show Gist options
  • Save komiyake/a48bd0002b205a5cee51 to your computer and use it in GitHub Desktop.
Save komiyake/a48bd0002b205a5cee51 to your computer and use it in GitHub Desktop.
RubyのTkを用いてニコニコ動画みたいにツイートを左に流す
#!/usr/bin/ruby
require 'tk'
require "twitter"
require "rubygems"
WIDTH = 1200
HEIGHT = 400
FONT_SIZE = 16
c = Tk::Canvas.new(nil, :width=>WIDTH, :height=>HEIGHT, :relief=>:sunken,
:borderwidth=>3).pack(:fill=>:both, :expand=>true)
f = TkFont.new('Helvetica -' + FONT_SIZE.to_s)
tag = TkcTag.new(c)
Thread.new do
@client = Twitter::Streaming::Client.new do |config|
config.consumer_key = #CONSUMER_KEY
config.consumer_secret = #CONSUMER_SECRET
config.access_token = #ACCESS_TOKEN
config.access_token_secret = #ACCESS_TOKEN_SECRET
end
@client.user do |tweet|
case tweet
when Twitter::Tweet
str = "@#{tweet.user.screen_name}: #{tweet.text}"
Thread.new(str, rand(HEIGHT/30)+1) do
|str, height|
for i in 0..WIDTH+str.size*FONT_SIZE
t = TkcText.new(c, WIDTH-i*3+str.size*FONT_SIZE, height*30, :text=>str, :font=>f, :tags=>tag)
sleep 0.01
t.delete
end
end
end
end
end
Tk.mainloop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment