Last active
February 6, 2018 03:46
-
-
Save obelisk68/f8aecd77c058be0907eb098c3e7fc6b5 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 = 400, 400 | |
Oekaki.app width: Width, height: Height, title: "Grate curve" do | |
draw do | |
clear(color(0xffff, 0x7dff, 0)) | |
t = Turtle.new(Width, Height, self) | |
t.color(0, 0, 0) | |
t.move(-160, 150) | |
two = lambda do |a, c, w| | |
return if c <= 1 | |
t.right(a) | |
t.forward(1) | |
t.right(a) | |
t.forward(w) | |
t.left(a) | |
t.forward(1) if c > 1 | |
t.left(a) | |
t.forward(w) | |
two[a, c - 2, w] | |
end | |
square = lambda do |a, h, w| | |
t.forward(w) | |
two[a, h - 1, w] | |
end | |
grate = lambda do |n, a, w, h| | |
if n.zero? | |
square[a, h, w] | |
else | |
t.right(a) | |
grate[n - 1, -a, h / 4, w] | |
t.forward(h / 8) | |
grate[n - 1, a, h / 4, w] | |
t.forward(h / 8) | |
grate[n - 1, -a, h / 4, w] | |
t.left(a) | |
end | |
end | |
grate[4, 90, 320, 320] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment