41

Plotting hearts with Python and C

 5 years ago
source link: https://www.tuicool.com/articles/hit/ENb2I3q
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Heart

This project contains a few programs written in Python and C that plot my heart for my Cutie Pai .

Contents

Python (2014)

The source code in heart.py may be executed with Python 3.4 or any later version of Python interpreter. It depends on the the Matplotlib package.

Setup and Run

Enter these commands to set up a virtual Python environment with this package and run the Python program.

make py-venv
make py-heart

The output is written to a PNG file named heart-2014-02-14.png .

Output

UVrmy2a.png!web

Quadratic and Quartic Curves

To read about the two mathematical functions used in the source code, see this thread on Reddit where I have explained how these functions plot the curves that form the heart.

C (2019)

The source code in heart.c may be compiled with any standard C compiler that supports C89 (ANSI C).

Compile and Run

Enter these commands to compile and run the C program.

make c-heart

The output is written to a text file named heart-2019-02-14.txt .

Output

...............................................................
...............................................................
.................. @@@@@@@ ......... @@@@@@@ ..................
............... @@@@     @@@@ ... @@@@     @@@@ ...............
............. @@@           @@@ @@@           @@@ .............
............ @@@               @               @@@ ............
............ @@@    Cutie Pai,                 @@@ ............
............ @@@                               @@@ ............
............. @@@         I love you!         @@@ .............
............... @@@@                       @@@@ ...............
.................. @@@@     -- Susam    @@@@ ..................
..................... @@@@           @@@@ .....................
........................ @@@@     @@@@ ........................
........................... @@@ @@@ ...........................
.............................. @ ..............................
...............................................................
...............................................................

License

This is free and open source software. You can use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of it, under the terms of the MIT License. See LICENSE.md for details.

This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or implied. See LICENSE.md for details.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK