Last active
February 5, 2018 18:10
-
-
Save obelisk68/21fa463440756f89d6369c9e7580275d to your computer and use it in GitHub Desktop.
シェルピンスキー曲線
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'oekaki' | |
require_relative 'turtle' | |
Width, Height = 600, 600 | |
Oekaki.app width: Width, height: Height, title: "Sierpinski curve" do | |
draw do | |
clear | |
depth = 5 | |
l = 550 | |
num = 2 ** (depth - 1) | |
t = Turtle.new(Width, Height, self) | |
t.color(0xffff, 0, 0xffff) | |
step = l / ((2 * sqrt(2) + 1) * num + num - 1) | |
t.move(-l / 2 + step / sqrt(2), l / 2) | |
drawing = lambda do |depth, angle = 45| | |
if depth.zero? | |
t.forward(step) | |
else | |
t.right(angle) | |
drawing[depth - 1, -angle] | |
t.left(angle) | |
t.forward(step) | |
t.left(angle) | |
drawing[depth - 1, -angle] | |
t.right(angle) | |
end | |
end | |
4.times do | |
drawing[2 * depth - 1] | |
t.right(45) | |
t.forward(step) | |
t.right(45) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment