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)
这是我到目前为止的代码。我需要做的是将照片中黑色像素的中间 1/3 更改为红色,将黑色像素的底部 1/3 更改为黄色,并在照片上打印有多少黑色像素更改为黄色,有多少更改为红色。我对 JES 和 Jython 以及整体编程非常陌生,因此非常感谢这方面的帮助!
你应该补充一下你谈论的: https://github.com/gatech-csl/jes
我调整了您的代码以向您展示如何打印一些输出:
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)
我的 JES 控制台:
======= 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
>>>
这应该足以作为示例,以便您可以完成作业。