Vajon mit csinál ez a program?

ljlkjlkj A program minden sorába a sor végére #-jellel kezdve írd le, hogy szerinted mit csinál az adott sor!


In [1]:
import math   # Ez a sor vajon mit csinál?
import random # ljlkj
from PIL import Image
import matplotlib.pyplot 
import numpy as np 

imgx = 512; imgy = 512
image = Image.new("RGB", (imgx, imgy))
pixels = image.load()

f = random.random() * 20 + 10 
p = random.random() * math.pi 
n = random.randint(10, 20) 
print(f, p, n)

for ky in range(imgy):
    y = float(ky) / (imgy - 1) * 4 * math.pi - 2 * math.pi
    for kx in range(imgx):
        x = float(kx) / (imgx - 1) * 4 * math.pi - 2 * math.pi
        z = 0.0
        for i in range(n):
            r = math.hypot(x, y)
            a = math.atan2(y, x) + i * math.pi * 2.0 / n
            z += math.cos(r * math.sin(a) * f + p)
        c = int(round(255 * z / n))
        pixels[kx, ky] = (c, c, c)


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-46a5e62a9135> in <module>()
      1 import math   # Ez a sor vajon mit csinál?
      2 import random
----> 3 from PIL import Image
      4 import matplotlib.pyplot
      5 import numpy as np

ImportError: No module named 'PIL'

Egy kis meglepetés


In [1]:
%matplotlib inline
matplotlib.pyplot.imshow(np.asarray(image),cmap='PuBu');


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-125b24afad79> in <module>()
      1 get_ipython().magic('matplotlib inline')
----> 2 matplotlib.pyplot.imshow(np.asarray(image),cmap='PuBu');

NameError: name 'matplotlib' is not defined

In [ ]: