Skip to content

Instantly share code, notes, and snippets.

@obelisk68
Last active February 6, 2018 03:46
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/f8aecd77c058be0907eb098c3e7fc6b5 to your computer and use it in GitHub Desktop.
Save obelisk68/f8aecd77c058be0907eb098c3e7fc6b5 to your computer and use it in GitHub Desktop.
格子曲線
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