1

JES を使用して、水平のグリッド線が 10 ピクセル、垂直のグリッド線が 20 ピクセル離れている画像に「白い」グリッド線を描画するプログラムを作成するにはどうすればよいですか?

4

1 に答える 1

0

そう、意外とaddLine(picture, startX, startY, endX, endY)黒い線しか引けない!?

それでは手でやってみましょう。以下は非常に基本的な実装です。

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)

注 : これは、ここで指定されたスクリプトの関数 drawLine() を使用して、より効率的に達成することもできました。


出力:


…………………… ここに画像の説明を入力_ ここに画像の説明を入力_


于 2013-06-25T23:43:48.960 に答える