diff --git a/visuals/README.md b/visuals/README.md index 7addb26..9bab85d 100644 --- a/visuals/README.md +++ b/visuals/README.md @@ -16,4 +16,6 @@ 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. -- **Rotating_HSB_Squares** - Slowly builds a mandela-like structure out of squares that slowly change color through the HSB color spectrum. \ No newline at end of file +- **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. \ No newline at end of file diff --git a/visuals/StackingEquilateralTriangles/StackingEquilateralTriangles.pyde b/visuals/StackingEquilateralTriangles/StackingEquilateralTriangles.pyde new file mode 100644 index 0000000..be7719a --- /dev/null +++ b/visuals/StackingEquilateralTriangles/StackingEquilateralTriangles.pyde @@ -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() diff --git a/visuals/StackingEquilateralTriangles/sketch.properties b/visuals/StackingEquilateralTriangles/sketch.properties new file mode 100644 index 0000000..2456b0a --- /dev/null +++ b/visuals/StackingEquilateralTriangles/sketch.properties @@ -0,0 +1,2 @@ +mode=Python +mode.id=jycessing.mode.PythonMode