title: Drawing Diagonal Lines Across a Picture
body: <p>I am trying to draw parallel lines diagonally from the top right corner to the bottom left corner of a picture. I want it to look like this (lovely paint pic)</p>
  
  <p><img src="https://i.stack.imgur.com/2o5js.png" alt="diag paint pic"></p>
  
  <pre><code>def diagTopLBottomR():
    pic=makePicture(pickAFile())
    w=getWidth(pic)
    h=getHeight(pic)
    x1=0
    y1=0
    x2=0
    y2=0
    i=0
    while i&lt;11:
      x1=10*i
      y2=10*i
      i+=1
      for y in range (y1,y2):
        x = (y-y1)*(x2-x1)/(y2-y1) +x1
        px=getPixel(pic,x,y)
        color=makeColor(0,0,0)
        setColor(px, color)
    x3=0
    y3=h
    x4=w
    y4=0
    j=0
    while j&lt;10:
      x3=10*j
      y4=10*j
      j+=1
      for y in range (y3,y4):
        x = (y-y3)*(x4-x3)/(y4-y3) +x3
        px=getPixel(pic,x,y)
        color=makeColor(0,0,0)
        setColor(px, color)
  
    return(pic)
  </code></pre>
  
  <p><strong>You'll note</strong> that the x3 will either be max value, causing an outof range exception, or the y range will start with a higher value ie (y3>y4) and doesn't work in reverse, or when I decrement it. It's like a paradox.</p>
  
  <p>The first loop is working, no matter what I try I cannot get the second loop to work. This is what I'm ending up with.</p>
  
  <p><img src="https://i.stack.imgur.com/BjagA.png" alt="diag lines"></p>
  
  <p>Any ideas? Thanks.</p>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <p>I have played around with the ranges, and either get no result for the second loop, as shown above of an out of range exception.</p>
  
  <p>I have tried:</p>
  
  <pre><code>  x3=0
    y3=h
    x4=w
    y4=0
    j=0
    while j&lt;10:
      x3=10*j
      y4=10*j
      j+=1
      for x in range (x3,x4):
        y = (x-x3)*(y4-y3)/(x4-x3) +y3
  </code></pre>
  
  <hr>
  
  <p><em>Stole Unicorns <a href="https://meta.stackexchange.com/questions/37328/my-godits-full-of-unicorns">from here</a>.</em></p>