Hello all I am very very new to programming & Python. My problem is I cannot figure out how to create a line consisting of random colored pixels. I know how to create a white or red line but how to make the colors random is beyond me. This is my white line..Im pretty sure I have to import random somewhere but not too sure??

from cImage import *
myImWin = ImageWin("Line Image" ,300,300)
lineImage = EmptyImage(300,300)
PILPixel = Pixel(255,255,255)
for i in range(300):
    lineImage.setPixel(i,i,whitePixel)
lineImage.draw(myImWin)

Any assistance would be greatly appreciated.

I have not used the graphics package cImage, but you can use the built-in random package.

To call a random number between 1 and 255 just use the code below.

from random import randint

print randint(1,255)
from random import randint

color = (randint(0, 255), randint(0, 255), randint(0, 255))
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.