Computer generated art with Python

codesharedot - Sep 6 '19 - - Dev Community

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

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)
    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()

Related links:

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player