DEV Community

codesharedot
codesharedot

Posted on

2

Computer generated art with Python

A computer can be used to generate art. Earliest attempts can be seen in old screensavers or demos. The most modern form of art generation uses AI/Machine Learning/Deep Learning.

Create Art with Python

Even with basic Python knowledge you can computer generate art. For instance, we can make the computer generate random numbers and use that random data to form a picture of bubbles.

Computer Art

The Code

The modules numpy and matplotlib will be used

#!/usr/bin/python3
import numpy as np
import matplotlib.pyplot as plt
Enter fullscreen mode Exit fullscreen mode

Then a main function

if __name__ =="__main__":
Enter fullscreen mode Exit fullscreen mode

where random data is created (x,y). Random colors are also created.

    N = 100
    x = np.zeros(N)
    y = np.zeros(N)
    for i in range(N):
        x[i] = np.random.rand()
        y[i] = np.random.rand()
    colors = np.random.rand(N)
Enter fullscreen mode Exit fullscreen mode

Then we plot the picture

    area = (30 * np.random.rand(N))**2  
    ax = plt.subplot(111)
    ax.scatter(x, y, s=area, c=colors, alpha=0.6)
    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.spines['bottom'].set_visible(False)
    ax.spines['left'].set_visible(False)
    plt.axis('off')
    plt.show()
Enter fullscreen mode Exit fullscreen mode

Related links:

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay