Upcoming SlideShare
×

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

942
-1

Published on

Published in: Technology
2 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total Views
942
On Slideshare
0
From Embeds
0
Number of Embeds
34
Actions
Shares
0
0
0
Likes
2
Embeds 0
No embeds

No notes for slide

### 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
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