1
def change(pic, startX, startY, getHeight, getWidth, endColour): 
  width = getWidth
  height = getHeight 
  picture = makePicture(pic)
  for px in getPixels(picture):
    x = getX(px)
    y = getY(px)
    if (startX <= x <= getHeight) and (startY <= y <= getWidth):
      if (distance(black, getColor(px)) < 95):
        setColor(px, endColour)
  show (picture)
  return (picture)

Here is the code I have so far. What I need it to do is change the middle 1/3 of the black pixels in a photo to red, and the bottom 1/3 of the black pixels to yellow, as well as print on the photo how many black pixels where changed to yellow, and how many were changed to red. I am very new to JES and Jython and programming overall so help with this would be greatly appreciated!

MartyIX
  • 27,828
  • 29
  • 136
  • 207
Lauren
  • 33
  • 4

1 Answers1

0

You should add that you talk about: https://github.com/gatech-csl/jes

I adjusted your code to show you, how you can print some output:

def change(pic, startX, startY, endColour): 
  picture = makePicture(pic)
  width = getWidth
  height = getHeight 
  changedPixels = 0
  for px in getPixels(picture):
    x = getX(px)
    y = getY(px)
    if (startX <= x <= height) and (startY <= y <= width):
      if (distance(black, getColor(px)) < 95):
        changedPixels = changedPixels + 1
        setColor(px, endColour)
  show (picture)
  print "I changed", changedPixels, "pixels"
  return (picture)

My JES console:

======= Loading Program =======
>>> change('demos/image.jpg', 2, 2, makeColor(0,0,0))
I changed 11214 pixels
Picture, filename /home/marty/Downloads/jes-5.020-linux/demos/image.jpg height 234 width 313
>>> 

This should suffice you as an example so you can finish the assignment.

MartyIX
  • 27,828
  • 29
  • 136
  • 207