From 26f1eb967bd0dc330388c74545b2383ce672e00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Thu, 2 Jun 2022 17:14:08 +0200 Subject: [PATCH] Image, Animation --- README.md | 8 ++++---- index.html | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2e88e09..6c27121 100644 --- a/README.md +++ b/README.md @@ -2742,8 +2742,8 @@ from PIL import Image ```python = .getpixel((x, y)) # Returns a pixel. .putpixel((x, y), ) # Writes a pixel to the image. - = .getdata() # Returns a sequence of pixels. -.putdata() # Writes a sequence of pixels. + = .getdata() # Returns a flattened sequence of pixels. +.putdata() # Writes a flattened sequence of pixels. .paste(, (x, y)) # Writes an image to the image. ``` @@ -2807,11 +2807,11 @@ Animation # $ pip3 install imageio from PIL import Image, ImageDraw import imageio -WIDTH, R = 126, 10 +WIDTH, HEIGHT, R = 126, 126, 10 frames = [] for velocity in range(1, 16): y = sum(range(velocity)) - frame = Image.new('L', (WIDTH, WIDTH)) + frame = Image.new('L', (WIDTH, HEIGHT)) draw = ImageDraw.Draw(frame) draw.ellipse((WIDTH/2-R, y, WIDTH/2+R, y+R*2), fill='white') frames.append(frame) diff --git a/index.html b/index.html index b6c4ca9..97daad6 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -2230,8 +2230,8 @@ right = [[0.1, 0.6
<int/tuple> = <Image>.getpixel((x, y))          # Returns a pixel.
 <Image>.putpixel((x, y), <int/tuple>)           # Writes a pixel to the image.
-<ImagingCore> = <Image>.getdata()               # Returns a sequence of pixels.
-<Image>.putdata(<list/ImagingCore>)             # Writes a sequence of pixels.
+<ImagingCore> = <Image>.getdata()               # Returns a flattened sequence of pixels.
+<Image>.putdata(<list/ImagingCore>)             # Writes a flattened sequence of pixels.
 <Image>.paste(<Image>, (x, y))                  # Writes an image to the image.
 
<2d_array> = np.array(<Image_L>)                # Creates NumPy array from greyscale image.
@@ -2282,11 +2282,11 @@ img.convert('RGB').save(#Animation

Creates a GIF of a bouncing ball:

# $ pip3 install imageio
 from PIL import Image, ImageDraw
 import imageio
-WIDTH, R = 126, 10
+WIDTH, HEIGHT, R = 126, 126, 10
 frames = []
 for velocity in range(1, 16):
     y = sum(range(velocity))
-    frame = Image.new('L', (WIDTH, WIDTH))
+    frame = Image.new('L', (WIDTH, HEIGHT))
     draw  = ImageDraw.Draw(frame)
     draw.ellipse((WIDTH/2-R, y, WIDTH/2+R, y+R*2), fill='white')
     frames.append(frame)
@@ -2896,7 +2896,7 @@ $ pyinstaller script.py --add-data '<path>:.'