Skip to content

Instantly share code, notes, and snippets.

@obelisk68
Created February 5, 2018 18:00
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/2cdcecf5b3d8fa5a11498fe6a61e9e5f to your computer and use it in GitHub Desktop.
Save obelisk68/2cdcecf5b3d8fa5a11498fe6a61e9e5f 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: "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