需要绘制3条简单的条纹JES画条纹

时间:2013-11-07 00:37:25

标签: 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(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)                   

2 个答案:

答案 0 :(得分:0)

关于你的错误:

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解释器也会将“height * 0.4”计算为浮点数。导致“流氓”成为浮动。

修复:您必须将值显式cast为整数:

rheight = int(height*0.4)

答案 1 :(得分:0)

一种简单的方法,可以将颜色值增加一个,并避免流变程度:

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)

根据需要改变颜色和水平或垂直值和参数。遵循这种类型的逻辑将得到结果