Skip to main content

An extension of Turtle. DON'T CONFUSE IT WITH http://pypi.org/project/pydraw/!

Project description

image

Documentation for the PyDraw 2D Graphical Engine

The PyDraw system constitutes a high-level abstraction layer and computational framework developed upon the Python turtle module. This software architecture facilitates the execution of two-dimensional graphical rendering, kinematic simulations, and geometric analysis by mitigating the complexities associated with low-level buffer management and coordinate system synchronization.

The software is distributed under the terms of the GNU Affero General Public License version 3.0 (AGPL3).

I. Technical Capabilities

  • Execution Environment: The framework transforms the native procedural drawing interface into a persistent execution state suitable for iterative simulation loops. The "PyMaze" implementation serves as a primary demonstration of grid-based pathfinding and real-time state updates.
  • Geometric Primitives: The system provides an extensive library of geometric entities, each possessing internal methods for the calculation of surface area, perimeter, and topological verification.
  • Coordinate Transformations: All entities inherit from a foundational transformation class, enabling precise translation, rotation, and scaling within a Cartesian coordinate system.
  • Kinematic Modeling: The motion subsystem integrates velocity vectors, gravitational acceleration, and frictional coefficients. Automated boundary detection ensures the containment of entities within the defined viewport through the application of reflective collision logic.
  • Rendering Pipeline: The PyPen component provides a unified interface for the rasterization of all supported geometric structures via a centralized rendering method.

II. Specification of Geometric Entities

The instantiation of geometric primitives within the PyDraw environment requires adherence to the following structural definitions. Every entity inherits transformation capabilities from the _Moveable superclass.

from shapes import Vertex, Line, Circle, Triangle, Square, VertexSquare, Ellipse, RegularPolygon, Polygon

# 1. Vertex (A fundamental coordinate point within the 2D manifold)
v1 = Vertex(0, 0)
v2 = Vertex(100, 100)

# 2. Line (A linear segment established between two vertices)
entity_line = Line(start=v1, end=v2)

# 3. Circle (Defined by a central vertex and a scalar radius)
entity_circle = Circle(center=v1, radius=45.5)

# 4. Triangle (A three-sided polygon defined by three vertices)
entity_triangle = Triangle(v1, v2, Vertex(-50, 50))

# 5. Square (A regular quadrilateral instantiated at the origin)
entity_square = Square(side=60).move_to(10, 10)

# 6. VertexSquare (A quadrilateral defined by four distinct vertices)
entity_v_square = VertexSquare(v1, v2, Vertex(50, -50), Vertex(-50, 50))

# 7. Ellipse (Defined by a center and two semi-axes, 'a' and 'b')
entity_ellipse = Ellipse(center=v1, a=80, b=40)

# 8. Regular Polygons (Equilateral and equiangular n-gons)
hexagon = RegularPolygon(sides=6, side_length=30)

# 9. Custom Polygon (An arbitrary n-gon defined by an ordered list of vertices)
custom_poly = Polygon([Vertex(0,0), Vertex(50, 20), Vertex(30, 80)])

III. Kinematic and Motion Subsystems

The Motion class provides a wrapper for the integration of physical properties into geometric entities. This class manages the transition from static rendering to dynamic simulation by overseeing velocity components and environmental constraints.

Implementation Protocol:

  1. Entity Selection: A geometric entity must be initialized.
  2. Kinematic Wrapping: A Motion instance is constructed, incorporating the target entity, the rendering interface, initial velocity components (vx, vy), and the coefficient of friction.
  3. State Iteration: The update() method must be executed within the primary simulation loop.

Kinematic Simulation Example:

from pypen import PyPen, Speed
from shapes import RegularPolygon
from motion import Motion

# Initialization of the rendering interface
engine = PyPen("Kinematic Simulation Environment")
engine.initialise(PenColor="cyan", size=3, speed=Speed.INSTANT, BackgroundColor="black")

# Instantiation of a regular hexagon
hex_shape = RegularPolygon(sides=6, side_length=40)
hex_shape.move_to(0, 0)

# Construction of the kinematic wrapper
# Friction is defined as a scalar multiplier where 1.0 represents an absence of kinetic energy loss.
physics_body = Motion(
shape=hex_shape,
pen=engine,
vx=8.5,
vy=6.0,
friction=1.0
)

# Application of constant acceleration (e.g., simulated gravitational forces)
physics_body.accelerate(ax=0, ay=-0.5)

# Primary simulation loop
while True:
engine.clear()
engine.draw(hex_shape, color="cyan")

\# Execution of the kinematic update  
\# This encompasses translation, boundary verification, and frame rate synchronization.  
physics\_body.update(dt=0.016, bounce=True)    

IV. Comprehensive Demonstration: PyMaze

A full realization of the engine's capabilities is documented in the test.py module. The "PyMaze" application demonstrates the integration of user-input handling, grid-based collision logic, and real-time head-up display (HUD) rendering.

V. Scholarly Attributions and Development Context

The PyDraw framework was conceptualized and implemented to resolve the lack of standardized geometric abstraction in contemporary educational graphics libraries. It is noteworthy that the project was initiated and brought to fruition by an individual at the secondary education level.

While certain algorithmic complexities, such as the Shoelace formula for area calculation, were refined through the utilization of computational linguistics tools, the overarching software architecture, kinematic logic, and design patterns are the result of original scholarly inquiry.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydraw_turtle-1.3.0.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydraw_turtle-1.3.0-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file pydraw_turtle-1.3.0.tar.gz.

File metadata

  • Download URL: pydraw_turtle-1.3.0.tar.gz
  • Upload date:
  • Size: 25.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pydraw_turtle-1.3.0.tar.gz
Algorithm Hash digest
SHA256 bc827fff537c1487129a72c0f932b278ccd23a09c98396cc20741e9d49eb23d4
MD5 c4f0e7e64caf6a98ae0a718dd3732f39
BLAKE2b-256 51329be78f42d08b5dd2fef566385b6d2bf2bfed3f2d12c5f971619a153d3d41

See more details on using hashes here.

File details

Details for the file pydraw_turtle-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: pydraw_turtle-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pydraw_turtle-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 041fdaa3d35977df2c8eb5327921d658007e25802e356cfeb7f043df5ff5ba2f
MD5 373beb32ccd5c744d07850176481e641
BLAKE2b-256 b14d3bf2238caede866a8c2df91aaa4eb124c186cd8930c666a3299d9433d000

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page