Python 需要画3条简单的条纹JES画条纹

Python 需要画3条简单的条纹JES画条纹,python,jes,Python,Jes,我需要做三条条纹 第一个需要是形状高度的40%,256像素宽 红色分量从0-255逐渐增加,并水平穿过图像 第二个是形状高度的20%,相同宽度(高度300) 它是纯绿色的 第三个是形状高度的40%,蓝色将从255-0减少 我在第二个for循环中不断出错(rheight,rheight) 请帮忙 def drawLines(): height = int(input("Enter Height: ")) width = 256 picture = makeEmptyPicture(wi

我需要做三条条纹 第一个需要是形状高度的40%,256像素宽 红色分量从0-255逐渐增加,并水平穿过图像

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

第三个是形状高度的40%,蓝色将从255-0减少

我在第二个for循环中不断出错(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()
函数需要
整数作为参数

当您执行
rheight=height*0.4
时,由于
0.4
是一个浮点数,python/jython解释器也会将“height*0.4”计算为一个浮点数。导致“rheight”成为浮点

修复:您必须显式地
将值转换为整数:

rheight = int(height*0.4)

将颜色值增加1并避免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)
只需根据需要更改颜色、水平或垂直值和参数。遵循这种逻辑将得到结果