Skip to content
/ spring Public

A simple Python class to crate physics-like spring diagrams and draw them both in Matplotlib figures and PyGame surfaces.

Notifications You must be signed in to change notification settings

ffiza/spring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring

A simple Python class to crate physics-like spring diagrams and draw them both in Matplotlib figures and PyGame surfaces.

Usage

To create a spring, use, for example:

spring = Spring(xy1=(1.0, 1.0),
                xy2=(4.0, 3.0),
                n_loops=5,
                loop_width=0.5,
                base_fraction=0.1)

The preceding code will create a spring with the origin at xy1=(1.0, 1.0) and the tip at xy2=(4.0, 3.0), n_loops=5 loops, each of width loop_width=0.5 and a base fraction (length without loops) of base_fraction=0.1 of the total spring length.

To draw this spring in a Matplotlib axis stored in ax, with color color=blue and line width lw=2.0, use:

spring.draw_mpl(ax=ax, color="blue", lw=2.0)

To draw this spring in a PyGame surface stored in surf, with color color=gold1 and line width lw=2, use:

spring.draw_pyg(surface=surf, color="gold1", lw=2)

Also, check the two examples in the examples directory.

Screenshots

An example image using Matplotlib.

An example image using PyGame.

About

A simple Python class to crate physics-like spring diagrams and draw them both in Matplotlib figures and PyGame surfaces.

Topics

Resources

Stars

Watchers

Forks

Languages