ドットインストールでTwitterBot

ドットインストールとは、プログラミング学習サイトです。
無料であることと、動画でのレッスンが魅力です。

http://dotinstall.com/


個人的に、こちらのサイトに嵌まっていて、
専門外の知識の学習に役立てています。

私のプロフィールページです。
http://dotinstall.com/users/shom5xg


今回、こちらのサイトのガイダンスに従って、TwitterBotを作りました。
恥ずかしながら、PHPもcronも初めてでしたが、楽しく制作できました。

StarRubyで波紋生成シミュレーション

D

実行ファイル: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をご紹介します。

http://theterminal.jp/


カフェとコワーキングスペースの間といったところで、
フリードリンクで、1050円でどんだけいても大丈夫です。
(土日の日中は混むので、通常コースだと最大3時間になります。
 ずっといるためのプランとしては,1日コース(2000円)があります。)

ここに来る以前までは、月額性の蒲田の自習室を借りておりましたが、
実際なかなか通えなかったりするのと、
ターミナルは、すごく居心地が良くて集中できるので、
こちらに乗り換えました。


また、最近になって、ターミナルの利用者を対象としたSNSが始まりました。

http://sns.theterminal.jp/

推している機能としては,オファーを掲示して志望者を募る機能が有ります。
(自分がオファーを掲示するには月額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'),

とすることによって、解決いたしました。


追記:ExerbRuby1.9に対応しておりませんでした。涙
追記2:Ocraを用いることで解決しました。

GGJ2011に参加した感想

率直な感想として,非常に有意義で面白かった.

時系列に沿って,感想を記録したい.

ちなみに,僕は社会人ゲームプログラマで,

GGJ2011は,大学が会場で,学生が主催するイベントである.

続きを読む

Angelエンジンのサンプルプロジェクトのビルドを通すまで

Angel 2D

Angelエンジンは,プロトタイプ開発をターゲットとした2Dゲームエンジン
です.
言語はC++を対象とし,簡単な物理・AIライブラリも備えています.


詳細な仕様については,リンク先を確認頂くとして,
このエントリでは,
サンプルプロジェクトのビルドを通すまでに
つまづく点があったので,それを備忘録として記します.

続きを読む

2010年買って大正解だったものBEST5

5位:KAOSSILATORカオシレーター

KORG KAOSSILATOR PK

KORG KAOSSILATOR PK

手軽で楽しい.いじりごたえ十分.
これのおかげで作曲デビューできました.

4位:バットマンアーカムアサイラム

バットマン アーカム・アサイラム - Xbox360

バットマン アーカム・アサイラム - Xbox360

重厚なアートワーク.爽快なアクション.
良い意味で期待を裏切られました.

3位:ファンケル青汁

ファンケルの青汁は,他社に比べて非常に飲みやすい.
これのおかげで青汁を飲む習慣が始められました.
最初だけこれで,現在は
”青汁らしい”味のするケール含有の方を飲んでます.

2位:torne

torne (トルネ) (CECH-ZD1J)

torne (トルネ) (CECH-ZD1J)

ワールドカップに合わせて購入.うちの”地デジ化”も込めて.
使い勝手は文句なし.コストパフォーマンス最強ですね.

1位:MacbookAir13インチ

買ったばかりですし,初Macですが,すでに愛着たっぷりです.
軽いし,SSD速いし,大好きです.