Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
クヌース曲線
require 'oekaki'
require_relative 'turtle'
Width, Height = 600, 350
Oekaki.app width: Width, height: Height, title: "Knuth curve" do
draw do
clear
t = Turtle.new(Width, Height, self)
t.color(0xf0ff, 0xffff, 0xffff)
t.move(250, -100)
t.left(180)
step = 8
drawing = lambda do |depth, a, tn|
if depth.zero?
t.right(45 + tn)
t.forward(step)
t.left(45 + tn)
else
t.right(2 * tn + a)
drawing[depth - 1, 2 * tn, -tn]
t.right(45 - 3 * tn - a)
t.forward(step)
t.left(45 - tn + a)
drawing[depth - 1, 0, -tn]
t.right(a)
end
end
drawing[9, -90, 45]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment