alfiovinci / TangentArt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TangentArt

A simple Python program which creates artistic pictures. It is originally inspired by this Tweet.

Requirements

Tested on Python 3.9.7 (previous versions should work as fine).
Additional libraries needed: numpy, matplotlib.

How to use

Run the .py script using a terminal by specifying the following parameters: the desired boundaries of the independent variable; the desired function to plot using the notation accepted by the numpy library; the number of points where the function and the tangents are evaluated.
Each parameter must be enclosed by quotation marks. As an example, to represent a sine and its tangents in the interval from -20 and +20 using 500 points, one must run:
python3 tangentart.py '-20' '20' 'np.sin(x)' '500'.
A figure will pop-up showing the generated picture. The chosen function is represented as a red soline line, whereas the tangents are shown as thin black lines.
Note that: 1) the independent variable is always called x; 2) the function is defined using the rules set by the numpy library.

Output examples

A few examples are embedded in the following.

Example 1: python3 tangentart.py '-20' '20' 'np.sin(x)' '500'
Picture of a sine plotted in the interval -20 < x < +20 and evaluated in 500 points. Screenshot_20220314_202826

Example 2: python3 tangentart.py '-20' '20' 'x*np.sin(x)' '500'
Picture of the function x*sin(x) plotted in the interval -20 < x < +20 and evaluated in 500 points. Screenshot_20220314_203129

Example 3: python3 tangentart.py '-20' '20' 'x*np.tan(x)' '500'
Picture of tan(x) plotted in the interval -20 < x < +20 and evaluated in 500 points. Screenshot_20220314_203314

About


Languages

Language:Python 100.0%