Created
February 5, 2018 18:00
-
-
Save obelisk68/2cdcecf5b3d8fa5a11498fe6a61e9e5f 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: "Koch curve" do | |
draw do | |
clear | |
l = 500 | |
t = Turtle.new(Width, Height, self) | |
t.color(0, 65535, 65535) | |
t.move(l / 2, -150) | |
t.dir = Vector[-1, 0] | |
drawing = lambda do |length, depth| | |
if depth.zero? | |
t.forward(length) | |
else | |
drawing[length / 3, depth - 1] | |
t.left(60) | |
drawing[length / 3, depth - 1] | |
t.right(120) | |
drawing[length / 3, depth - 1] | |
t.left(60) | |
drawing[length / 3, depth - 1] | |
end | |
end | |
3.times do | |
drawing[l, 3] | |
t.right(120) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment