我如何编写使用JES在图像上绘制“白色”网格线的程序,该图像的水平网格线分隔为10个像素,垂直网格线分隔为20个像素?
Yes, surprisingly, addLine(picture, startX, startY, endX, endY)
can only draw black lines !?
So let's do it by hand. Here is a very basic implementation:
def drawGrid(picture, color):
w = getWidth(picture)
h = getHeight(picture)
printNow(str(w) + " x " + str(h))
w_offset = 20 # Vertical lines offset
h_offset = 10 # Horizontal lines offset
# Starting at 1 to avoid drawing on the border
for y in range(1, h):
for x in range(1, w):
# Here is the trick: we draw only
# every offset (% = modulus operator)
if (x % w_offset == 0) or (y % h_offset == 0):
px = getPixel(picture, x, y)
setColor(px, color)
file = pickAFile()
picture = makePicture(file)
# Change the color here
color = makeColor(255, 255, 255) # This is white
drawGrid(picture, color)
show(picture)
Note : this could also have been achieved a lot more efficiently using the function drawLine(), from the script given here .
Output:
....... .........
.......
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.