0

I'm only a couple weeks into my IT degree and I'm trying to write a small program in Python, I've tried searching for a solution but my knowledge of terminology and concepts is probably limiting my results. Saying that, I'm trying to find out if it is possible to assign a value to a pixel in a random range, then get the x,y of that value and manipulate it. For example

import random
pic=makeEmptyPicture(500,500)
w=random.randint(0,getWidth(pic))
h=random.randint(0,getHeight(pic))
a=getPixel(pic,w,h)
for x in range(getX(a),getX(a+5),1): #this is where I'm stuck.
    for y in range(getY(a),getY(a+5),1): #I need to get the x,y of "a"
        #Do something                    #and manipulate it.

Thanks in advance.

  • This doesn't make sense - the coordinates of the pixel you retrieved are of course the `w`, `h` parameters you passed to `getPixel()`. – jasonharper Jul 11 '17 at 02:08
  • I was trying to use w , h to generate a 2nd random coordinate for another value to use later on in the program. I should have provided more information sorry. I've found the error in this section. I needed to take the +5 out of the brackets. Thanks for your input. – Aston00 Jul 11 '17 at 02:25

1 Answers1

0

The variables w and h are the (x, y) coordinates.

To manipulate that pixel, I would need to learn about your "picture" object.

First, see what kind of object makeEmptyPicture returns. Then look at that object to see if it had any useful functions.

pic = makeEmptyPicture(500, 500)
print("type: ", type(pic))
for var in dir(pic):
    print(var)

If this isn't enough information, use Python's built-in "help" command.

pic = makeEmptyPicture(500, 500)
help(pic)

These might give you some good leads. If you're still stuck, post the results, and I'll help you.

ddg
  • 1,090
  • 1
  • 6
  • 17