Question

I need to make three stripes first one needs to be 40% of the shape height and 256 pixels wide the red component gradually increases from 0-255 and traverse the image horizontally

the second is 20% of the shape height, same width (height 300) it is solid green

third is 40% of the shape height and the blue will decrease from 255-0

I keep getting errors on the second for loop (rheight,rheight) Please help!!

def drawLines():
  height = int(input("Enter Height: "))
  width = 256
  picture = makeEmptyPicture(width,height)
  rheight = height*0.4

  redValue = 0
  for y in range(0,height):
    for x in range(0,width):
      pixel = getPixel(picture, x, y)
      color = makeColor(redValue,0,0)
      setColor(pixel, color)
    redValue = redValue + 50
  explore(picture)


  for y in range(rheight,rheight):    
    for x in range(0, width):         
       pixel = getPixel(picture, x, y)
       color = makeColor(0, 0, 0)      # Change the current pixel to black
       setColor(pixel, color)
  explore(picture)                   

No correct solution

OTHER TIPS

Regarding your error:

The error was: 1st arg can't be coerced to int
Inappropriate argument type.
An attempt was made to call a function with a parameter of an invalid type. 
This means that you did something such as trying to pass a string to a method 
that is expecting an integer.

This is because the range() function needs integers as arguments.

When you do rheight = height*0.4, as 0.4 is a floating point number, the python/jython interpreter computes "height*0.4" as a float as well. Resulting in "rheight" being a float.

Fix: you have to explicitly cast the value as being an integer:

rheight = int(height*0.4)

A simple way to increment your color values by one, and to avoid the rheight level:

def d():
  file = pickAFile()
  pic = makePicture(file)
  w= getWidth(pic)
  h= getHeight(pic)
  show (pic)
  newPic = makeEmptyPicture(w,h)
  for y in range (0 ,h-1):  
    for x in range(0,w-1):
      pixel = getPixel(pic, x, y)
      newPixel = getPixel(newPic,x, y)
      if(y == h*0.4):
        #the red value will increase incrementally by one as the x value increases
        color = makeColor(x,0,0)
      else:
        color = getColor(pixel)
      setColor(newPixel, color)
  writePictureTo(newPic, r"D:\temp.jpg")
  explore(newPic)

Just vary color and horizontal or vertical values and parameters as needed. Following this type of logic will get you the results

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top