3つのシンプルなストライプを描く必要がありますJes Draw Stripes

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

  •  05-07-2022
  •  | 
  •  

質問

最初に3つのストライプを作る必要があります。最初のストライプは形状の高さの40%、幅256ピクセルである必要があります。赤いコンポーネントは0〜255から徐々に増加し、画像を水平方向にトラバースします

2番目は形状の高さの20%、同じ幅(高さ300)です。

3番目は形状の高さの40%であり、青は255-0から減少します

ループ(Rheight、Rheight)の2番目のエラーを保ち続けてください!!

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)

色の値を1つずつ増加させ、ハイツレベルを回避する簡単な方法:

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