Created
February 5, 2018 18:01
-
-
Save obelisk68/b19d2f116a996c6aad705c597e983fb6 to your computer and use it in GitHub Desktop.
ヒルベルト曲線
This file contains 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: "Hilbert curve" do | |
draw do | |
clear | |
depth = 5 | |
l = 500 | |
t = Turtle.new(Width, Height, self) | |
t.color(0xffff, 0x7dff, 0) | |
t.move(-l / 2, l / 2) | |
step = l / (2 ** depth - 1) | |
drawing = lambda do |depth, angle| | |
if depth.zero? | |
return | |
else | |
t.right(angle) | |
drawing[depth - 1, -angle] | |
t.forward(step) | |
t.left(angle) | |
drawing[depth - 1, angle] | |
t.forward(step) | |
drawing[depth - 1, angle] | |
t.left(angle) | |
t.forward(step) | |
drawing[depth - 1, -angle] | |
t.right(angle) | |
end | |
end | |
drawing[depth, 90] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment