Skip to content

Instantly share code, notes, and snippets.

@obelisk68
Last active February 5, 2018 18:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save obelisk68/21fa463440756f89d6369c9e7580275d to your computer and use it in GitHub Desktop.
シェルピンスキー曲線
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