Guest User

Untitled

a guest
Jan 19th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #Sameer Kumar
  2. #I worked on this assignment alon, using only this semester's course materials.
  3.  
  4. #Function One: Border
  5.  
  6. def border (pic, color, thickness):
  7. left = 0 + thickness
  8. right = getWidth(pic) - thickness
  9. top = 0 + thickness
  10. bottom = getHeight(pic) - thickness
  11. for pixel in getPixels(pic):
  12. if getX(pixel) >= right:
  13. setColor(pixel, color)
  14. if getX(pixel) <= left:
  15. setColor(pixel, color)
  16. if getY(pixel) <= top:
  17. setColor(pixel, color)
  18. if getY(pixel) >= bottom:
  19. setColor(pixel, color)
  20.  
  21. #Function Two: Background
  22. def background(pic, color1, color2, threshold):
  23. half = getWidth(pic) /2
  24. for pixel in getPixels(pic):
  25. if getX(pixel) < half:
  26. if distance(getColor(pixel), green) < threshold:
  27. setColor(pixel, color1)
  28. if getX(pixel) >= half:
  29. if distance(getColor(pixel), green) < threshold:
  30. setColor(pixel, color2)
  31.  
  32. #Function Three: selectivePosterize
  33. def selectivePosterize(pic, color1, color2, color3, color4, threshold):
  34. for pixel in getPixels(pic):
  35. luminance = (getRed(pixel) + getGreen(pixel) + getBlue(pixel))/3
  36. x = luminance
  37. if distance(getColor(pixel), green) > threshold:
  38. if x < 20:
  39. setColor(pixel, color1)
  40. if 20 <= x < 80:
  41. setColor(pixel, color2)
  42. if 80 <= x < 160:
  43. setColor(pixel, color3)
  44. if x >= 160:
  45. setColor(pixel, color4)
  46.  
  47. #Function 4: generatePoster
  48. def generatePoster(pic):
  49. color1 = makeColor(255,0,0)
  50. color2 = makeColor(50,50,50)
  51. color3 = makeColor(224,238,224)
  52. color4 = makeColor(0,0,0)
  53. leftColor = makeColor(25,25,112)
  54. rightColor = makeColor(150,0,0)
  55. selectivePosterize(pic,color4,color3,color2,color1,195)
  56. background(pic,leftColor,rightColor,130)
  57. border(pic, black, 20)
Add Comment
Please, Sign In to add comment