-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathShape.py
More file actions
91 lines (73 loc) · 3.02 KB
/
Shape.py
File metadata and controls
91 lines (73 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
File: Shape.py
Authors:
- Amey Thakur (https://github.com/Amey-Thakur)
- Mega Satish (https://github.com/msatmod)
Repository: https://github.com/Amey-Thakur/PYTHON-SHORTS
Release Date: January 9, 2022
License: MIT License
Description:
This module implements a geometric spiral generator utilizing turtle graphics.
It demonstrates the recursive application of rotational symmetry and
iterative coordinate transformations to produce complex polygonal spirals
within Euclidean space.
Complexity Analysis:
- Time Complexity: O(n), where n is the number of iterations (segments drawn).
- Space Complexity: O(1) auxiliary space beyond the graphics buffer.
Logic:
1. Initialize the graphics environment with a high-contrast background.
2. Define a transformation set (colors, line widths) for iterative variation.
3. Execute a loop of n iterations, where each step:
a. Updates the stroke color based on modular indexing.
b. Increments the pen size linearly to create structural depth.
c. Translates the turtle forward by an increasing distance i.
d. Rotates the turtle by a fixed angle (59 degrees) to create a spiral drift.
4. Print the final geometric parameters to the terminal for verification.
"""
import turtle
from typing import List
class GeometricSpiralService:
"""
A service class for generating geometric spirals via turtle graphics.
"""
def __init__(self, iterations: int = 200, angle: int = 59):
self.iterations = iterations
self.angle = angle
self.colors: List[str] = ["purple", "red", "orange", "blue", "green"]
def draw_sequence(self) -> None:
"""
Executes the iterative drawing sequence.
"""
# Graphics Setup
screen = turtle.Screen()
screen.bgcolor("black")
t = turtle.Turtle()
t.speed(0) # Maximum rendering speed
print(f"--- Geometric Spiral Parameters ---")
print(f"Total Iterations: {self.iterations}")
print(f"Rotation Angle: {self.angle} degrees")
print(f"Palette Size: {len(self.colors)} indices")
print("\nInitiating Graphics Engine...")
for i in range(self.iterations):
# Modular color selection for spectrum cycling
t.color(self.colors[i % len(self.colors)])
# Linear pen transformation
t.pensize(i / 10 + 1)
# Iterative translation and rotation
t.forward(i)
t.left(self.angle)
print("Sequence Completion: Resource Deallocation Pending...")
# screen.exitonclick() # Commented for automated logging/headless runs
def main():
"""
Demonstrates the scholarly Geometric Spiral implementation.
"""
service = GeometricSpiralService()
try:
service.draw_sequence()
except turtle.Terminator:
print("Graphics Engine Terminated: Process Exit.")
except Exception as e:
print(f"Execution Failure: {e}")
if __name__ == "__main__":
main()