<br><br><div class="gmail_quote">On Thu, Jul 23, 2009 at 7:09 AM, Muhammad Ali <span dir="ltr">&lt;<a href="mailto:ali.jan@gmail.com">ali.jan@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Hi,<br><br>I have some x and y co-ordinates ranging from (-100, 100) for each x and y. Something like this:<br><br>                   100<br>                     |<br>                     |<br>                     |<br>                     |<br>


-100------------------------------100<br>                     |<br>                     |<br>                     |<br>                     |<br>                  -100<br><br> I would like to plot them on a pygame surface.<br>


I have found that pygame surface is (0, 0) at top right to (width, height) at the bottom right corner, like this:<br><br>(0,0)                      (width, 0)<br>------------------------------------<br>|                                   |<br>


|                                   |<br>|                                   |<br>|                                   |<br>|                                   |<br>|                                   |<br>
|                                   |<br>------------------------------------<br>(0,height)                (width, height)<br>
<br><br>I need a way to map any value from my range to this surface so I could do stuff like this:<br>pygame.draw.circle(screen, color, (x, y), size<br><br>Also my range could vary from -5, 5 or -500 to 500 so I need something generic...<br>


<br>It looks like a simple problem but I can&#39;t seem to be able to figure it out.</blockquote><div><br>Well, first off you&#39;ll need to know what your window size is. I presume you&#39;re defining the size and you&#39;re defining a 1:1 ratio (400x400, or 600x600 or some such)? If so, then all you need to do is scale your x, y down and then offset your imaginary grid to the middle. I don&#39;t know any of the pygame methods, but here&#39;s what it might look like:<br>

<br>def draw_pixel(x, y):<br>    w = screen.get_width()<br>    h = screen.get_height() <br></div></div>    screen.draw_pixel(w/2+x, h/2+y)<br><br>That should give you what you need. It starts right in the middle of the screen (w/2, h/2) then will add your values of x and y. If you have a screen of 400x400, and x, y of -20, 20 you&#39;ll have<br>

200 + (-20) = 180 and 200 + 20 = 220.<br><br>HTH,<br>Wayne<br>