Skip to content

Instantly share code, notes, and snippets.

@4hg
Created August 26, 2021 21:45
Show Gist options
  • Save 4hg/fcd684eea71cd840fb0ea3f08c2a0631 to your computer and use it in GitHub Desktop.
Save 4hg/fcd684eea71cd840fb0ea3f08c2a0631 to your computer and use it in GitHub Desktop.
Simple Sierpinski triangle using ruby2d.
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