ドットインストールでTwitterBot
ドットインストールとは、プログラミング学習サイトです。
無料であることと、動画でのレッスンが魅力です。
個人的に、こちらのサイトに嵌まっていて、
専門外の知識の学習に役立てています。
私のプロフィールページです。
http://dotinstall.com/users/shom5xg
今回、こちらのサイトのガイダンスに従って、TwitterBotを作りました。
恥ずかしながら、PHPもcronも初めてでしたが、楽しく制作できました。
StarRubyで波紋生成シミュレーション
実行ファイル:RippleSimulator.exe
####################################################################### # # DESCRIPTION: タスクシステム管理 # AUTHOR: shom # DATE: 2012/10/13 # ####################################################################### require "starruby" include StarRuby class Task def exec( tex, keys, mouse, mouseLocat ) #virtual end end load "Ripple.rb" # 中間レンダリングバッファ生成 midTex = Texture.new( 480, 480 ) # タスク生成 # -タスクリスト HashTask = Hash.new # -移動体 HashTask.store( :ripple, Ripple.new(midTex) ) # フォント生成 font = Font.new( "MS UI Gothic", 20 ) font_color = Color.new( 255, 255, 255 ) # ゲームループ w = midTex.width() h = midTex.height() title = "Ripple Simulator ( powered by StarRuby )" Game.run( w, h, :cursor => true, :fps => 15, :title => title ) do |game| # 中間バッファリセット midTex.clear # 入力受付 keys = Input.keys( :keyboard ) mouse = Input.keys( :mouse ) mouseLocat = Input.mouse_location() # ESCキーで中断 break if keys.include?( :escape ) # タスク毎時処理 HashTask.each_value do |task| task.exec( midTex, mouse, mouseLocat ) end # 中間バッファ反映 game.screen.clear game.screen.render_texture( midTex, 0, 0 ) # デバッグテキスト出力 debug_text = "" debug_text << "[ fps ( ideal : "; debug_text << game.fps().to_i().to_s(); debug_text << " ) ] : "; debug_text << game.real_fps().to_i().to_s(); game.screen.render_text( debug_text, 8, 8, font, font_color ) debug_text = "[ produce ripple ] : "; if mouse.include?( :left ) debug_text << "on" else debug_text << "off" end game.screen.render_text( debug_text, 8, 8 + 24, font, font_color ) debug_text = "[ update ] : "; if mouse.include?( :right ) debug_text << "stopping" else debug_text << "working" end game.screen.render_text( debug_text, 8, 8 + 24 * 2, font, font_color ) if mouse.include?( :middle ) game.screen.render_text( "CLEAR!", 240 - 24 / 2 * 3, 240 - 24 / 2, font, font_color ) end end
####################################################################### # # DESCRIPTION: 波紋生成 # AUTHOR: shom # DATE: 2012/10/13 # ####################################################################### require "starruby" include StarRuby class Ripple < Task #定数 GRID_HEIGHT = 6 GRID_WIDTH = 6 ATTENUATION = 0.999 #減衰率(1に限りなく近いほど、波の伝搬力が高くなる) def initialize(tex) @xmax = ( (tex.width())/GRID_WIDTH ).floor() @ymax = ( (tex.height())/GRID_HEIGHT ).floor() @heightTbl = Array.new @heightPrevTbl = Array.new for y in 0..(@ymax-1) for x in 0..(@xmax-1) @heightTbl.push( 0 ) @heightPrevTbl.push( 0 ) end end end # 関数:色情報獲得:クリア def getHeightClear(tex, elColors = @heightTbl) for y in 0..(@ymax-1) for x in 0..(@xmax-1) @heightTbl[y*@xmax+x] = 0 @heightPrevTbl[y*@xmax+x] = 0 end end end # 関数:色情報獲得:マウスの位置を黒に def getHeightMouse(tex, mouse, mouseLocat) #マウスの位置を高さを最大にする if mouse.include?( :left ) then x,y = mouseLocat idxX = (x/GRID_WIDTH).floor idxY = (y/GRID_HEIGHT).floor idx = idxY * @xmax + idxX @heightTbl[ idx ] = 100 end end # 関数:色情報に波の効果を出す def effectRipple(tex) # バッファ確保 nextHeightTbl = Array.new(@heightTbl) # for y in 0..(@ymax-1) for x in 0..(@xmax-1) surroundSum = 0 if x!=0 surroundSum += @heightTbl[y*@xmax+(x-1)] else surroundSum += @heightTbl[y*@xmax+x] end if x!=(@xmax-1) surroundSum += @heightTbl[y*@xmax+(x+1)] else surroundSum += @heightTbl[y*@xmax+x] end if y!=0 surroundSum += @heightTbl[(y-1)*@xmax+x] else surroundSum += @heightTbl[y*@xmax+x] end if y!=(@ymax-1) surroundSum += @heightTbl[(y+1)*@xmax+x] else surroundSum += @heightTbl[y*@xmax+x] end if x!=0 and y!=0 surroundSum += @heightTbl[(y-1)*@xmax+(x-1)] else surroundSum += @heightTbl[y*@xmax+x] end if x!=(@xmax-1) and y!=0 surroundSum += @heightTbl[(y-1)*@xmax+(x+1)] else surroundSum += @heightTbl[y*@xmax+x] end if x!=0 and y!=(@ymax-1) surroundSum += @heightTbl[(y+1)*@xmax+(x-1)] else surroundSum += @heightTbl[y*@xmax+x] end if x!=(@xmax-1) and y!=(@ymax-1) surroundSum += @heightTbl[(y+1)*@xmax+(x+1)] else surroundSum += @heightTbl[y*@xmax+x] end difSurround = ( surroundSum / 8 * ATTENUATION - @heightTbl[y*@xmax+x] ) difCenter = @heightTbl[y*@xmax+x] - @heightPrevTbl[y*@xmax+x] nextHeight = @heightTbl[y*@xmax+x] + difSurround + difCenter if nextHeight > 100 then nextHeight = 100 elsif nextHeight < 0 then nextHeight = 0 end nextHeightTbl[y*@xmax+x] = nextHeight end end # 色情報更新 @heightPrevTbl = @heightTbl.clone @heightTbl = nextHeightTbl.clone end # 関数:描画 def renderRect(tex) heightTbl = @heightTbl.clone # 矩形を並べる 0.step(tex.height()-1, GRID_HEIGHT) do |y| 0.step(tex.width()-1, GRID_WIDTH) do |x| height = ( heightTbl.shift() ).floor color = Color.new( 0, 0, 255 * height / 100 ) tex.render_rect(x, y, GRID_WIDTH, GRID_HEIGHT, color) end end end # 関数:毎時処理 def exec(tex, mouse, mouseLocat) # 色情報を獲得 if mouse.include?( :middle ) then getHeightClear(tex, @heightTbl) getHeightClear(tex, @heightPrevTbl) else getHeightMouse(tex, mouse, mouseLocat) end # 色情報に波の効果を出す if !mouse.include?( :right ) then effectRipple(tex) end # 矩形を色情報を使って描画 renderRect(tex) end end
THE TERMINAL
自分が集中したいときにいくスポットである、THE TERMINALをご紹介します。
カフェとコワーキングスペースの間といったところで、
フリードリンクで、1050円でどんだけいても大丈夫です。
(土日の日中は混むので、通常コースだと最大3時間になります。
ずっといるためのプランとしては,1日コース(2000円)があります。)
ここに来る以前までは、月額性の蒲田の自習室を借りておりましたが、
実際なかなか通えなかったりするのと、
ターミナルは、すごく居心地が良くて集中できるので、
こちらに乗り換えました。
また、最近になって、ターミナルの利用者を対象としたSNSが始まりました。
推している機能としては,オファーを掲示して志望者を募る機能が有ります。
(自分がオファーを掲示するには月額315円の有料会員になる必要が有ります。)
ターミナルは、フリーで活躍している方も、多く利用されているのでは、と思うので、
そういった点で、利用者の層とマッチしていて良いのでは、と思いました。
その他、ターミナルが会場となって行われるトークイベントの動画配信も行っているようです。
(こちらも有料会員限定の機能となります。)
追記:なんだか,ステマ記事みたいになってる。。。
Rubyスクリプトのexe化
以前までは、rubyscript2exe.rbを使っていましたが、
Ruby1.9に対応していなかったので、Exerbを使うことにしました。
しかし、実行してみたものの、
〜/exerb/config.rb:17: Use RbConfig instead of obsolete and deprecated Config.
というメッセージが出て、exeファイルの出力に失敗します。
調べてみた結果、
C:\Ruby193\lib\ruby\site_ruby\1.9.1\exerb\config.rb
の19行目にある
File.join(Config::CONFIG['datadir'], 'exerb'),
を
File.join(RbConfig::CONFIG['datadir'], 'exerb'),
とすることによって、解決いたしました。
2010年買って大正解だったものBEST5
5位:KAOSSILATOR(カオシレーター)
- 出版社/メーカー: KORG(コルグ)
- メディア: 付属品
- クリック: 35回
- この商品を含むブログ (11件) を見る
手軽で楽しい.いじりごたえ十分.
これのおかげで作曲デビューできました.
4位:バットマン・アーカムアサイラム
- 出版社/メーカー: スクウェア・エニックス
- 発売日: 2010/01/14
- メディア: Video Game
- 購入: 3人 クリック: 55回
- この商品を含むブログ (45件) を見る
重厚なアートワーク.爽快なアクション.
良い意味で期待を裏切られました.
3位:ファンケル青汁
- 出版社/メーカー: 株式会社ファンケル
- メディア: ヘルスケア&ケア用品
- この商品を含むブログ (2件) を見る
ファンケルの青汁は,他社に比べて非常に飲みやすい.
これのおかげで青汁を飲む習慣が始められました.
最初だけこれで,現在は
”青汁らしい”味のするケール含有の方を飲んでます.
2位:torne
- 出版社/メーカー: ソニー・コンピュータエンタテインメント
- 発売日: 2010/03/18
- メディア: Video Game
- 購入: 61人 クリック: 5,291回
- この商品を含むブログ (229件) を見る
ワールドカップに合わせて購入.うちの”地デジ化”も込めて.
使い勝手は文句なし.コストパフォーマンス最強ですね.