From 079ffeea8b9e60bea760e9d17952096ac7486463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 29 Oct 2021 02:03:18 +0200 Subject: [PATCH] Image, Pygame --- README.md | 12 ++++++------ index.html | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 50e1b98..e4316ff 100644 --- a/README.md +++ b/README.md @@ -2590,7 +2590,7 @@ Line # Mem usage Increment Line Contents ``` ### Call Graph -#### Generates a PNG image of a call graph with highlighted bottlenecks: +#### Generates a PNG image of the call graph with highlighted bottlenecks: ```python # $ pip3 install pycallgraph2 from pycallgraph2 import output, PyCallGraph @@ -2742,8 +2742,8 @@ from PIL import Image #### Creates a PNG image of a rainbow gradient: ```python WIDTH, HEIGHT = 100, 100 -size = WIDTH * HEIGHT -hues = (255 * i/size for i in range(size)) +n_pixels = WIDTH * HEIGHT +hues = (255 * i/n_pixels for i in range(n_pixels)) img = Image.new('HSV', (WIDTH, HEIGHT)) img.putdata([(int(h), 255, 255) for h in hues]) img.convert('RGB').save('test.png') @@ -3064,13 +3064,13 @@ def stop_on_collision(spd, bounds): y=0 if (D.n in bounds and spd.y < 0) or (D.s in bounds and spd.y > 0) else spd.y) def draw(screen, images, mario, tiles, pressed): - def get_frame_index(): + def get_marios_image_index(): if D.s not in get_boundaries(mario.rect, tiles): return 4 return next(mario.frame_cycle) if {D.w, D.e} & pressed else 6 screen.fill((85, 168, 255)) mario.facing_left = (D.w in pressed) if {D.w, D.e} & pressed else mario.facing_left - screen.blit(images[get_frame_index() + mario.facing_left * 9], mario.rect) + screen.blit(images[get_marios_image_index() + mario.facing_left * 9], mario.rect) for rect in tiles: screen.blit(images[18 if {*rect.topleft} & {0, (SIZE-1)*16} else 19], rect) pg.display.flip() @@ -3387,7 +3387,7 @@ df = df.rename({'date': 'Date', 'Continent_Name': 'Continent'}, axis='columns') line(df, x='Date', y='Total Deaths per Million', color='Continent').show() ``` -#### Confirmed covid cases, Dow Jones, gold, and Bitcoin price: +#### Confirmed covid cases, Dow Jones, Gold, and Bitcoin price: ![Covid Cases](web/covid_cases.png)
diff --git a/index.html b/index.html index ddf7194..ce130e4 100644 --- a/index.html +++ b/index.html @@ -226,7 +226,7 @@ pre.prettyprint {
- +
@@ -2259,7 +2259,7 @@ Line # Mem usage Increment Line Contents 3 38.012 MiB 0.344 MiB a = [*range(10000)] 4 38.477 MiB 0.465 MiB b = {*range(10000)} -

Call Graph

Generates a PNG image of a call graph with highlighted bottlenecks:

# $ pip3 install pycallgraph2
+

Call Graph

Generates a PNG image of the call graph with highlighted bottlenecks:

# $ pip3 install pycallgraph2
 from pycallgraph2 import output, PyCallGraph
 from datetime import datetime
 filename = f'profile-{datetime.now():%Y%m%d%H%M%S}.png'
@@ -2368,8 +2368,8 @@ right = [[0.1, 0.6'RGBA' - 4x8-bit pixels, true color with transparency mask.
 
  • 'HSV' - 3x8-bit pixels, Hue, Saturation, Value color space.
  • Examples

    Creates a PNG image of a rainbow gradient:

    WIDTH, HEIGHT = 100, 100
    -size = WIDTH * HEIGHT
    -hues = (255 * i/size for i in range(size))
    +n_pixels = WIDTH * HEIGHT
    +hues = (255 * i/n_pixels for i in range(n_pixels))
     img = Image.new('HSV', (WIDTH, HEIGHT))
     img.putdata([(int(h), 255, 255) for h in hues])
     img.convert('RGB').save('test.png')
    @@ -2639,13 +2639,13 @@ SIZE, MAX_SPEED = 50, P(0 if (D.n in bounds and spd.y < 0) or (D.s in bounds and spd.y > 0) else spd.y)
     
     def draw(screen, images, mario, tiles, pressed):
    -    def get_frame_index():
    +    def get_marios_image_index():
             if D.s not in get_boundaries(mario.rect, tiles):
                 return 4
             return next(mario.frame_cycle) if {D.w, D.e} & pressed else 6
         screen.fill((85, 168, 255))
         mario.facing_left = (D.w in pressed) if {D.w, D.e} & pressed else mario.facing_left
    -    screen.blit(images[get_frame_index() + mario.facing_left * 9], mario.rect)
    +    screen.blit(images[get_marios_image_index() + mario.facing_left * 9], mario.rect)
         for rect in tiles:
             screen.blit(images[18 if {*rect.topleft} & {0, (SIZE-1)*16} else 19], rect)
         pg.display.flip()
    @@ -2894,7 +2894,7 @@ line(df, x='Date', y=
     
     
     
    -

    Confirmed covid cases, Dow Jones, gold, and Bitcoin price:

    import pandas as pd
    +

    Confirmed covid cases, Dow Jones, Gold, and Bitcoin price:

    import pandas as pd
     import plotly.graph_objects as go
     
     def main():
    @@ -3017,7 +3017,7 @@ $ pyinstaller script.py --add-data '<path>:.'