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的新手以及整体编程所以非常感谢你的帮助!
答案 0 :(得分:0)
您应该补充一下: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
>>>
这应该足以让你作为一个例子,所以你可以完成作业。