Pregunta

Necesito hacer tres rayas primero debe ser el 40% de la altura de la forma y 256 píxeles de ancho, el componente rojo aumenta gradualmente de 0-255 y atraviesa la imagen horizontalmente

El segundo es el 20% de la altura de la forma, el mismo ancho (altura 300) es verde sólido

El tercero es el 40% de la altura de la forma y el azul disminuirá de 255-0

Sigo recibiendo errores en el segundo para Loop (Rheight, Rheight) ¡por favor ayuda!

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 hay solución correcta

Otros consejos

Con respecto a su 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.

Esto es porque el range() necesidades de funciones integers como argumentos.

Cuando tu lo hagas rheight = height*0.4, como 0.4 es un número de punto flotante, el intérprete Python/Jython calcula "altura*0.4" como flotante también. Resultando en que "Rheight" sea un flotador.

Arreglar: tienes que explícitamente cast el valor como un entero:

rheight = int(height*0.4)

Una forma sencilla de incrementar sus valores de color en uno y evitar el nivel de Rheight:

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)

Simplemente varíe el color y los valores y parámetros horizontales o verticales según sea necesario. Seguir este tipo de lógica le dará los resultados

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top