3 개의 간단한 줄무늬 jes 드로우 줄무늬를 그릴 필요가 있습니다

StackOverflow https://stackoverflow.com/questions/19825812

  •  05-07-2022
  •  | 
  •  

문제

먼저 3 개의 줄무늬를 만들어야합니다. 먼저 모양 높이의 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 부동 소수점 번호이며, 파이썬/Jython 통역사는 "높이*0.4"도 플로트로 계산합니다. "Rheight"가 플로트가됩니다.

고치다: 당신은 명시 적으로해야합니다 cast 정수로서의 가치 :

rheight = int(height*0.4)

색상 값을 하나씩 증가시키고 리이트 레벨을 피하는 간단한 방법 :

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