Created
August 26, 2021 21:45
-
-
Save 4hg/fcd684eea71cd840fb0ea3f08c2a0631 to your computer and use it in GitHub Desktop.
Simple Sierpinski triangle using ruby2d.
This file contains hidden or 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 'ruby2d' | |
set title: "Sierpinski Triangle", background: "white" | |
vertices = [[Window.width / 2, 50, "blue"], [Window.width / 2 - 150, 350, "green"], [Window.width / 2 + 150, 350, "red"]] | |
point = [250, 200] | |
update do | |
v = vertices.sample | |
point = [0.5 * (point[0] + v[0]), 0.5 * (point[1] + v[1])] | |
Triangle.new( | |
x1: point[0], y1: point[1] - 3, | |
x2: point[0] - 3, y2: point[1] + 3, | |
x3: point[0] + 3, y3: point[1] + 3, | |
color: v[2] | |
) | |
end | |
show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment