Hi, I have this problem where I have to make a function that takes one parameter and draws two vertical lines, one is a red line from (50,0) to (50,300) and one made up of randomly colored pixels(150,50)to (150,250).
I didn't define my function yet but for some reason my random part isn't working.
I cannot figure out whats wrong. It says "Float object has no attribute int".
I tried to put rand also but didn't work. Do I need to convert something?
This is my code:

from cImage import*
import random
RandomColor = random.random()


myImWin = ImageWin("Line Image", 300, 300)
lineImage = EmptyImage(300,300)
redPixel = Pixel(255,0,0)
randomRed = Pixel(RandomColor.int(0,255))
for i in range(300):
    for x in range(250):
        lineImage.setPixel(50,i,redPixel)
        randomRed.setPixel(150,x,randomRed)
lineImage.draw(myImWin)
randomRed.save("lineImage.gif")

Try ...

# cImage.py from:
# www.cs.luther.edu/~pythonworks/PythonContext/cImage.py

from cImage import*
import random

#RandomColor = random.random()

myImWin = ImageWin("Line Image", 300, 300)
lineImage = EmptyImage(300,300)
redPixel = Pixel(255,0,0)
# random.randint(0,255) picks an integer between 0 and 255
randomRed = Pixel(random.randint(0,255),0,0)
for i in range(300):
    for x in range(250):
        lineImage.setPixel(50,i,redPixel)
        lineImage.setPixel(150,x,randomRed)
lineImage.draw(myImWin)
lineImage.save("lineImage.gif")

# needed to wait
myImWin.exitOnClick()

Okay thanks.
Oh no, now I am getting an error saying,'Pixel' object has no attribute 'setPixel' on line 17, btw I am using python 3.2. My cImage is already imported.
setPixel supposed to put those new coordinates right?

Never mind I got it. And at the end of the program it says 'ImageWin' object has no attribute 'exitonClick'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.