Skip to content

Instantly share code, notes, and snippets.

@obelisk68
Created February 5, 2018 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obelisk68/b19d2f116a996c6aad705c597e983fb6 to your computer and use it in GitHub Desktop.
Save obelisk68/b19d2f116a996c6aad705c597e983fb6 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: "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