我需要首先制作三个条纹,是形状高度的40%,宽256像素,红色成分逐渐从0-255增加并水平穿越图像

第二个是形状高度的20%,相同的宽度(高度300)是固体绿色

第三是形状高度的40%,蓝色将从255-0降低

我在第二个循环(Rheight,Rheight)的第二次遇到错误!

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)                   

没有正确的解决方案

其他提示

关于您的错误:

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.

这是因为 range() 功能需求 integers 作为参数。

当你这样做的时候 rheight = height*0.4, , 作为 0.4 是浮点数,python/jython解释器也将“高度*0.4”计算为浮点。导致“ Rheight”是浮标。

使固定: 你必须明确 cast 作为整数的价值:

rheight = int(height*0.4)

一种简单的方法,将您的颜色值提高一个,并避免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)

只需根据需要改变颜色,水平或垂直值和参数。遵循这种类型的逻辑将为您带来结果

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top