mirror of
https://github.com/Xevion/processing-projects.git
synced 2025-12-06 03:16:04 -06:00
Sierpinski Triangle sketch
This commit is contained in:
@@ -18,4 +18,6 @@ All my projects attempting to create vivid or interesting visuals using the Proc
|
|||||||
|
|
||||||
- **Rotating_HSB_Squares** - Slowly builds a mandela-like structure out of squares that slowly change color through the HSB color spectrum.
|
- **Rotating_HSB_Squares** - Slowly builds a mandela-like structure out of squares that slowly change color through the HSB color spectrum.
|
||||||
|
|
||||||
- **StackingEquilateralTriangles** - Another interesting rotating triangle sketch.
|
- **StackingEquilateralTriangles** - Another interesting rotating triangle sketch.
|
||||||
|
|
||||||
|
- **Sierpinski_Triangle** - Builds the Sierpinski Triangle
|
||||||
55
visuals/Sierpinski_Triangle/Sierpinski_Triangle.pyde
Normal file
55
visuals/Sierpinski_Triangle/Sierpinski_Triangle.pyde
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
class Point:
|
||||||
|
def __init__(self, x, y, sdraw=False):
|
||||||
|
self.x, self.y = x, y
|
||||||
|
|
||||||
|
def s(self):
|
||||||
|
ellipse(self.x, self.y, 5, 5)
|
||||||
|
|
||||||
|
def mid(self, other):
|
||||||
|
return Point((self.x + other.x) / 2, (self.y + other.y) / 2)
|
||||||
|
|
||||||
|
def siepinski(i, a, b, c):
|
||||||
|
if i <= 0:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
triangle(a.x, a.y, b.x, b.y, c.x, c.y)
|
||||||
|
x = a.mid(b)
|
||||||
|
y = b.mid(c)
|
||||||
|
z = c.mid(a)
|
||||||
|
siepinski(i - 1, a, x, z)
|
||||||
|
siepinski(i - 1, x, b, y)
|
||||||
|
siepinski(i - 1, z, y, c)
|
||||||
|
# siepinski(i - 1, x, y, z)
|
||||||
|
|
||||||
|
def setup():
|
||||||
|
size(1000, 1000)
|
||||||
|
noLoop()
|
||||||
|
|
||||||
|
def equilateral(center, side):
|
||||||
|
|
||||||
|
altitude = side * (sqrt(3) / 2.0)
|
||||||
|
AM = (2.0/3.0) * altitude
|
||||||
|
BF = (1.0 / 2.0) * side
|
||||||
|
FM = (1.0 / 3.0) * altitude
|
||||||
|
|
||||||
|
a = Point(center.x, center.y + AM)
|
||||||
|
b = Point(center.x - BF, center.y - FM)
|
||||||
|
c = Point(center.x + BF, center.y - FM)
|
||||||
|
|
||||||
|
return a, b, c
|
||||||
|
|
||||||
|
i = 1
|
||||||
|
def draw():
|
||||||
|
|
||||||
|
global i
|
||||||
|
a, b, c = equilateral(Point(0, 0), 750)
|
||||||
|
translate(width/2, height/2)
|
||||||
|
siepinski(i, a, b, c)
|
||||||
|
|
||||||
|
time.sleep(1)
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
def mouseClicked():
|
||||||
|
loop()
|
||||||
2
visuals/Sierpinski_Triangle/sketch.properties
Normal file
2
visuals/Sierpinski_Triangle/sketch.properties
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
mode=Python
|
||||||
|
mode.id=jycessing.mode.PythonMode
|
||||||
Reference in New Issue
Block a user