Created
February 5, 2018 18:03
-
-
Save obelisk68/f87eb7552f2885277f63c5a84920716e 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, 450 | |
Oekaki.app width: Width, height: Height, title: "Dragon curve" do | |
draw do | |
clear | |
depth = 12 | |
l = 350 | |
t = Turtle.new(Width, Height, self) | |
t.color(0xf0ff, 0xffff, 0xffff) | |
t.move(-l / 2, 50) | |
drawing = lambda do |length, depth| | |
if depth.zero? | |
t.forward(length) | |
else | |
len = length / sqrt(2) | |
po1 = t.pen_po | |
t.forward(length, false) | |
po2, t.pen_po = t.pen_po, po1 | |
t.right(45) | |
drawing[len, depth - 1] | |
t.pen_po = po2 | |
t.right(90) | |
drawing[len, depth - 1] | |
t.pen_po = po2 | |
t.left(135) | |
end | |
end | |
drawing[l, depth] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment