White gridlines over image using JES (python)

淺唱寂寞╮ 提交于 2019-12-13 17:28:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!