تحتاج إلى رسم 3 المشارب بسيطة خيسوس رسم خطوط

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

  •  05-07-2022
  •  | 
  •  

سؤال

ولست بحاجة لجعل ثلاثة خطوط أول واحد يجب أن يكون 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 مترجم يحسب "height*0.4" كما تطفو كذلك.مما أدى إلى "rheight" يجري تعويم.

Fix: عليك صراحة 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