Add Chapter 8 python files
This commit is contained in:
parent
2424fa6028
commit
5c38f5ef86
6 changed files with 228 additions and 0 deletions
31
thinkcspy/Chapter-8-Exercises/Python-files/Problem10.py
Normal file
31
thinkcspy/Chapter-8-Exercises/Python-files/Problem10.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# Runestone.Academy thinkcspy course
|
||||
# Chapter 8
|
||||
# Problem 10
|
||||
|
||||
import image
|
||||
|
||||
|
||||
img = image.Image("luther.jpg")
|
||||
win = image.ImageWin(img.getWidth(), img.getHeight())
|
||||
img.draw(win)
|
||||
img.setDelay(0) # setDelay(0) turns off animation
|
||||
|
||||
|
||||
for row in range(img.getHeight()):
|
||||
for col in range(img.getWidth()):
|
||||
p = img.getPixel(col, row)
|
||||
|
||||
R = p.getRed()
|
||||
G = p.getGreen()
|
||||
B = p.getBlue()
|
||||
|
||||
newred = (R * 0.393 + G * 0.769 + B * 0.189)
|
||||
newgreen = (R * 0.349 + G * 0.686 + B * 0.168)
|
||||
newblue = (R * 0.272 + G * 0.534 + B * 0.131)
|
||||
|
||||
newpixel = image.Pixel(newred, newgreen, newblue)
|
||||
|
||||
img.setPixel(col, row, newpixel)
|
||||
|
||||
img.draw(win)
|
||||
win.exitonclick()
|
||||
Loading…
Reference in a new issue