Skip to content

Instantly share code, notes, and snippets.

View myokoym's full-sized avatar
💭
hi

Masafumi Yokoyama myokoym

💭
hi
View GitHub Profile
@myokoym
myokoym / game-of-life.rb
Last active August 29, 2015 14:00
A Conway's Game of Life. Using Gosu (http://www.libgosu.org/) and Ruby (https://www.ruby-lang.org/).
require "gosu/zen"
include Gosu::Zen
# patch
module Gosu
module Zen
def init(&body)
ZenWindow.send(:define_method, :init, &body)
end
end
@myokoym
myokoym / create-pieces.rb
Last active August 29, 2015 14:00
将棋駒生成スクリプト
# -*- coding: utf-8 -*-
require "shogi_koma"
PIECES = [
["歩兵", "FU"],
["香車", "KY"],
["桂馬", "KE"],
["銀将", "GI"],
["金将", "KI"],
require "gosu"
module CatchHats
module ZOrder
Background, Object, Text = *0..2
end
class Player
attr_reader :x, :y
@myokoym
myokoym / firehats.rb
Last active August 29, 2015 14:01
A shooting game. Using Gosu (http://www.libgosu.org/) and Ruby (https://www.ruby-lang.org/).
begin
require "gosu"
rescue LoadError
$stderr.puts(<<-END_OF_MESSAGE)
LoadError: #{$!.message}. Please try `gem install gosu`.
If you are using Linux, please see https://github.com/jlnr/gosu/wiki/Getting-Started-on-Linux
END_OF_MESSAGE
exit(false)
end
@myokoym
myokoym / homography_params.rb
Last active August 29, 2015 14:01
Rubyで射影変換(ホモグラフィ)のパラメーターを求めてみた。8元一次連立方程式を行列(Ruby標準添付のMatrixライブラリ)を使って解くやり方。
require "matrix"
# 変換前後の座標から射影変換のパラメーターを求める
# x11-x14: 変換前のX座標(左上から時計回り)
# y11-y14: 変換前のY座標
# x21-x24: 変換後のX座標
# y21-y24: 変換後のY座標
def homography_params(x11, y11, x12, y12,
x13, y13, x14, y14,
x21, y21, x22, y22,
@myokoym
myokoym / cairo-graph.rb
Last active August 29, 2015 14:01
This script automatically generates a graph. Using rcairo ( http://rcairo.github.io/ ).
require "cairo"
module Cairo
class Context
def show_graph(graph)
graph.draw(self)
end
end
class Graph
require "test-unit"
class RegexpTest < Test::Unit::TestCase
def setup
@regexp = /\bCairo(?:::[A-Z][\w\d_]+)*(?:[#.][\[_@\w\d]*(?:[=?!_*+\-\]]|\b)|\b)/
end
def test_front
line = "Cairo::Contextはrcairoで描画するときに使用する主要なオブジェ\n"
assert_equal(["Cairo::Context"], line.gsub(@regexp).to_a)
@myokoym
myokoym / hidoka.rab
Created May 29, 2014 02:39
ひどか(仮)
= ひどか(仮)
= ひどかとは
* 「ひ」とり
* 「ど」くしょ(読書)
* 「か」い(会)
= 読書とは
@myokoym
myokoym / bowl.rb
Last active August 29, 2015 14:02
I'm trying to draw a bowl by rcairo.
require "cairo"
def draw_bowl(context, width, height)
context.save do
context.set_source_color(:black)
context.scale(width, height)
context.line_width = 0.01
fill_inner(context)
fill_outer(context)
@myokoym
myokoym / rice.rb
Last active August 29, 2015 14:02
require "cairo"
# http://www.dafont.com/ubuntu-title.font
FONT = "Ubuntu-Title"
# http://www.dafont.com/fifa-welcome.font
#FONT = "FIFA Welcome"
def draw(context, width, height, text)
context.save do
context.set_source_color(:black)