mirror of
https://github.com/Xevion/processing-projects.git
synced 2025-12-06 11:16:01 -06:00
stacking equilateral triangles sketch
This commit is contained in:
@@ -17,3 +17,5 @@ All my projects attempting to create vivid or interesting visuals using the Proc
|
|||||||
- **Trippy_Boxes** - Transparent rotating boxes that move throught the HSB color spectrum.
|
- **Trippy_Boxes** - Transparent rotating boxes that move throught 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.
|
- **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.
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
class Triangle:
|
||||||
|
def __init__(self, a, b, c, orient):
|
||||||
|
self.a, self.b, self.c, self.orient = a, b, c, orient
|
||||||
|
|
||||||
|
def render(self, points=False):
|
||||||
|
rotate(radians(self.orient))
|
||||||
|
triangle(self.a.x, self.a.y, self.b.x, self.b.y, self.c.x, self.c.y)
|
||||||
|
if points:
|
||||||
|
self.a.render()
|
||||||
|
self.b.render()
|
||||||
|
self.c.render()
|
||||||
|
|
||||||
|
class Point:
|
||||||
|
def __init__(self, x, y, diameter=5):
|
||||||
|
self.x, self.y, self.diamter = x, y, diameter
|
||||||
|
|
||||||
|
def render(self):
|
||||||
|
ellipse(self.x, self.y, self.diameter, self.diameter)
|
||||||
|
|
||||||
|
def setup():
|
||||||
|
size(500, 500)
|
||||||
|
|
||||||
|
global triangleArray
|
||||||
|
triangleArray = []
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
x = 0
|
||||||
|
def draw():
|
||||||
|
global x, triangleArray
|
||||||
|
for _ in range(1):
|
||||||
|
x += 1
|
||||||
|
i = sin(x / 100.0) * 400
|
||||||
|
if i >= 400:
|
||||||
|
i = 0
|
||||||
|
|
||||||
|
a, b, c = equilateral(Point(0, 0), i)
|
||||||
|
triangleArray.insert(0, Triangle(a, b, c, i))
|
||||||
|
triangleArray = triangleArray[:30]
|
||||||
|
|
||||||
|
background(204)
|
||||||
|
for e,tri in enumerate(triangleArray):
|
||||||
|
# if e == len(triangleArray) - 1:
|
||||||
|
# fill(204)
|
||||||
|
# noStroke()
|
||||||
|
# else:
|
||||||
|
# stroke(0)
|
||||||
|
# fill(255)
|
||||||
|
resetMatrix()
|
||||||
|
translate(width / 2.0, height / 2.0)
|
||||||
|
tri.render()
|
||||||
|
|
||||||
|
def mouseClicked():
|
||||||
|
loop()
|
||||||
2
visuals/StackingEquilateralTriangles/sketch.properties
Normal file
2
visuals/StackingEquilateralTriangles/sketch.properties
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
mode=Python
|
||||||
|
mode.id=jycessing.mode.PythonMode
|
||||||
Reference in New Issue
Block a user