Your SlideShare is downloading. ×
Python & Perl          PIL & PyGame Basics By Example   Dot Circles, Texts, Tile Ornaments, Image Grayscaling &           ...
Outline   ●   Comments on Final Project Proposals   ●   PIL Examples          –   Drawing dot circles          –   Drawing...
PIL Exampleswww.youtube.com/vkedco       www.vkedco.blogspot.com
Exercise: Dot Circle    Write a PIL program that creates an RGB image of    a given background and size, draws a circle on...
Exercise: Dot Circlewww.youtube.com/vkedco   www.vkedco.blogspot.com
Exercise: Dot Circle                def make_dot_circle_image(img_fp, img_size=100, radius=30,                            ...
Exercise: Drawn Text    Write a PIL program that creates an RGB image of    a given background and size, draws a text on i...
Exercise: Drawn Text                         source code is herewww.youtube.com/vkedco                www.vkedco.blogspot....
Exercise: Run-Length Tile Ornaments    Write a PIL program that uses run-length coding    to create RGB images with tile o...
Run-Length Encoding   ●   Run-Length        Encoding   is   a   form    of       data       compression   ●   It is applic...
Exercise: Run-Length Tile Ornamentswww.youtube.com/vkedco   www.vkedco.blogspot.com
Exercise: Run-Length Tile Ornamentswww.youtube.com/vkedco   www.vkedco.blogspot.com
Exercise: Run-Length Tile Ornamentswww.youtube.com/vkedco   www.vkedco.blogspot.com
Exercise: Luminosity & Binarization    Write a PIL program that converts RGB images to    grayscale and binarizes them.   ...
Exercise: Luminosity & Binarization          RGB            Grayscale               Binarywww.youtube.com/vkedco          ...
PyGame Exampleswww.youtube.com/vkedco    www.vkedco.blogspot.com
Exercise: Random Circles    Write a PyGame program that draws circles of    random colors by capturing events inside (e.g....
Exercise: Random Circles                     source code is herewww.youtube.com/vkedco            www.vkedco.blogspot.com
Reading & References  ●   www.python.org  ●   http://en.wikipedia.org/wiki/Duck_typing  ●   http://www.pythonware.comwww.y...
Upcoming SlideShare
Loading in...5
×

Python & Perl: PIL & PyGame by Example: Dot Circles, Texts, Tile Ornaments, Image Grayscaling & Binarization, Random Circles

897

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
897
On Slideshare
0
From Embeds
0
Number of Embeds
33
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Python & Perl: PIL & PyGame by Example: Dot Circles, Texts, Tile Ornaments, Image Grayscaling & Binarization, Random Circles"

  1. 1. Python & Perl PIL & PyGame Basics By Example Dot Circles, Texts, Tile Ornaments, Image Grayscaling & Binarization, Random Circles Vladimir Kulyukinwww.youtube.com/vkedco www.vkedco.blogspot.com
  2. 2. Outline ● Comments on Final Project Proposals ● PIL Examples – Drawing dot circles – Drawing text – Generating tile ornaments – RGB to Grayscale to Binary ● PyGame Examples – Drawing Random Circleswww.youtube.com/vkedco www.vkedco.blogspot.com
  3. 3. PIL Exampleswww.youtube.com/vkedco www.vkedco.blogspot.com
  4. 4. Exercise: Dot Circle Write a PIL program that creates an RGB image of a given background and size, draws a circle on it of a given color, and saves it in a file.www.youtube.com/vkedco www.vkedco.blogspot.com
  5. 5. Exercise: Dot Circlewww.youtube.com/vkedco www.vkedco.blogspot.com
  6. 6. Exercise: Dot Circle def make_dot_circle_image(img_fp, img_size=100, radius=30, img_background=white, dot_color=(0, 0, 255)): img = Image.new(RGB, (img_size, img_size), img_background) center_x = center_y = img_size / 2 # make sure circle can fit in image if radius > (img_size/2 - 1): radius = img_size/2 - 1 # draw 360 dots for angle in range(361): theta = radians(angle) x = center_x + radius * cos(theta) y = center_y + radius * sin(theta) img.putpixel((int(x), int(y)), dot_color) # save img object into image_fp and delete img.save(img_fp) del img source code is herewww.youtube.com/vkedco www.vkedco.blogspot.com
  7. 7. Exercise: Drawn Text Write a PIL program that creates an RGB image of a given background and size, draws a text on it and saves the image into a file.www.youtube.com/vkedco www.vkedco.blogspot.com
  8. 8. Exercise: Drawn Text source code is herewww.youtube.com/vkedco www.vkedco.blogspot.com
  9. 9. Exercise: Run-Length Tile Ornaments Write a PIL program that uses run-length coding to create RGB images with tile ornaments. source code is herewww.youtube.com/vkedco www.vkedco.blogspot.com
  10. 10. Run-Length Encoding ● Run-Length Encoding is a form of data compression ● It is applicable whenever data contains sequences (aka runs) of the same value which can be encoded in terms of the value and the number of times that value occurs in a run ● Example: 000000000111111100000 can be represented is (0, 9), (1, 7), (0, 5)www.youtube.com/vkedco www.vkedco.blogspot.com
  11. 11. Exercise: Run-Length Tile Ornamentswww.youtube.com/vkedco www.vkedco.blogspot.com
  12. 12. Exercise: Run-Length Tile Ornamentswww.youtube.com/vkedco www.vkedco.blogspot.com
  13. 13. Exercise: Run-Length Tile Ornamentswww.youtube.com/vkedco www.vkedco.blogspot.com
  14. 14. Exercise: Luminosity & Binarization Write a PIL program that converts RGB images to grayscale and binarizes them. source code is herewww.youtube.com/vkedco www.vkedco.blogspot.com
  15. 15. Exercise: Luminosity & Binarization RGB Grayscale Binarywww.youtube.com/vkedco www.vkedco.blogspot.com
  16. 16. PyGame Exampleswww.youtube.com/vkedco www.vkedco.blogspot.com
  17. 17. Exercise: Random Circles Write a PyGame program that draws circles of random colors by capturing events inside (e.g., mouse moves).www.youtube.com/vkedco www.vkedco.blogspot.com
  18. 18. Exercise: Random Circles source code is herewww.youtube.com/vkedco www.vkedco.blogspot.com
  19. 19. Reading & References ● www.python.org ● http://en.wikipedia.org/wiki/Duck_typing ● http://www.pythonware.comwww.youtube.com/vkedco www.vkedco.blogspot.com

×