Skip to content

Instantly share code, notes, and snippets.

@obelisk68
obelisk68 / sierpinski_gasket.rb
Created January 18, 2018 09:02
シェルピンスキーのギャスケット
require 'oekaki'
Width, Height = 500, 450
Oekaki.app width: Width, height: Height, title: "Sierpinski gasket" do
draw do
clear
x1, y1 = Width / 2, Height - Width * 0.5 * Math.sqrt(3)
x2, y2 = 0, Height
@obelisk68
obelisk68 / gosu_chipmunk_sample2.rb
Created January 14, 2018 17:49
Gosu + Chipmunk
require 'gosu'
require 'rmagick'
require 'chipmunk'
Width, Height = 600, 600
Wall_h = 20
class MyWindow < Gosu::Window
def initialize
super Width, Height, false
@obelisk68
obelisk68 / bucket_problem1.rb
Last active December 1, 2017 04:09
2つのバケツ
#http://obelisk.hatenablog.com/entry/2017/12/01/041951
#B1リットル: 空(0), 入れる(1), B1→B2に移す(2)
#B2リットル: 空(3), 入れる(4), B2→B1に移す(5)
B1, B2 = 8, 5
TO = 1
def move(mass, f, t)
if (a = mass - t) >= f
t += f
@obelisk68
obelisk68 / q31_1.rb
Last active November 22, 2017 01:43
数学パズル
Square = 6
is_used = Array.new(Square + 1) {Array.new(Square + 1) {[false, false]}}
count = 0
route = lambda do |x, y, is_first_time|
if x == Square and y == Square
if is_first_time
route.call(0, 0, false)
else
count += 1
@obelisk68
obelisk68 / 日本郵便追跡サービス_8043095.js
Created October 18, 2017 16:14
コンピュータ・ウィルスをダウンロード・感染させる(と思われる)js ファイル
function rxuG()
{
var KkNoAR = "YkuOKC7i{\"GUy%x";
return KkNoAR;
}
@obelisk68
obelisk68 / poh2.rb
Last active October 18, 2017 03:31
paiza オンラインハッカソン vol.2 の解説アルゴリズムで
height, width = gets.split.map(&:to_i)
window = []
height.times {window << gets.chomp.chars.map(&:to_i)}
num = gets.to_i
wgtsize = []
num.times {wgtsize << gets.split.map(&:to_i)}
height.times do |h|
(width - 1).times {|w| window[h][w + 1] += window[h][w]}
end
@obelisk68
obelisk68 / oekaki_sample14.rb
Last active September 8, 2017 08:47
移動する内接円
require 'oekaki'
Width, Height = 400, 300
CircumcircleR = 0.8
def incircle(a, b, c)
l, m, n = (b - a).norm, (c - b).norm, (a - c).norm
q = l + m + n
po = a * (m / q) + b * (n / q) + c * (l / q)
@obelisk68
obelisk68 / miniopengl_sample6.rb
Last active September 6, 2017 05:12
OpenGL で正多面体を回転させる
require './miniopengl'
require 'parallel'
filenames = []
1.upto(5) {|i| filenames << "./polyhedrons_obj/r" + ("%02d" % i) + ".obj"}
data = []
filenames.each do |fn|
open(fn, "r") do |io|
ar = [[], []]
@obelisk68
obelisk68 / oekaki_sample12.rb
Last active August 30, 2017 05:53
円が降ってくる(スクリーンセーバーもどき)
require 'oekaki'
Width, Height = if ARGV.size == 2
ARGV.map(&:to_i)
else
[1000, 700]
end
Max_r, Min_r = 40, 10
ColorMax = 65535
@obelisk68
obelisk68 / bad_code.c
Last active August 24, 2017 12:44
関数内で宣言した配列変数をreturnしてはいけない
#include <stdio.h>
char *keyboard_linein() {
char buf[1000];
fgets(buf, 1000, stdin);
printf("%s\n", buf);
return buf;
}