DEV Community 👩‍💻👨‍💻


Posted on

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

import numpy as np
import matplotlib.pyplot as plt

Then a main function

if __name__ =="__main__":

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)

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)

Related links:

Top comments (0)

We want your help! Become a Tag Moderator.
Check out this survey and help us moderate our community by becoming a tag moderator here at DEV.