问题
How can I write a program using JES to draw “White” gridlines on an image where the horizontal gridlines are separated by 10 pixels and the vertical gridlines are separated by 20 pixels?
回答1:
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:
.......
................来源:https://stackoverflow.com/questions/16704548/white-gridlines-over-image-using-jes-python