Draw random points on an image

What i wish to do is fairly simple .In a frame load an image and on that draw points chosen randomly.Also i wish to add zoom capabilities and scrolling capabilities to it.Any suggestions and i wish to plot the random point every timer cycle.

nipun batra wrote:

What i wish to do is fairly simple .In a frame load an image and on that
draw points chosen randomly.

I"d put the image in a wx.Bitmap that is stored in memory. on each timer
fire, you create a wx.MemoryDC, select the bitmap into it, then draw
your point with DC.DrawPoint. Then you call self.Refresh()
self.Update(), and have your PaintDC set to blit the bitmap to the
Window. See:

http://wiki.wxpython.org/DoubleBufferedDrawing

for more info.

Also i wish to add zoom capabilities and
scrolling capabilities to it.

To zoom, you need a wx.Image (or use PIL) to re-scale the bitmap. But
you can't draw directly to a wx.Image, so you need to have the image,
convert to a bitmap, draw to it, then make another wx.Image out of it --
not as bad as it sounds!

You might try wx.lib.floatcanvas -- it's really made primarily for
vector graphics, but you can use a ScaledBitmap object to do what you
want. (if the image is big, and you want to zoom in close, use
ScaledBitmap2 -- it's less tested, but more memory efficient.

Since you got me thinking, I've enclosed a FloatCanvas implementation,
and a test image (picture of my very cute daughter!)

I've also added this demo to the FloatCanvas SVN:

http://svn.wxwidgets.org/svn/wx/wxPython/3rdParty/FloatCanvas/

-Chris

ScaledBitmap2Demo.py (2.59 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Thanks a lot Chris.I had to make minor modifications in your code to make it suit me perfectly to my needs.I have uploaded my code as well where instead of random points i will be plotting current GPS after reading from serial port.And i will be using maps,grids to my use.This was about as much GIS i had needed where i would be plotting current GPS,marking waypoints etc.By the way Chris your daughter is very cute.I didnt want to spoil that image even for a small duration so i picked up an image from Open Street Maps.Hope one is allowed to use these images.I will now take the coordinates of upper left and bottom right point of the map/grid in both actual and frame coordinates and using a simple conversion formula i will be able to mark current GPS with ease.Is there any better or simpler way out,which does not consume a lot of time.Here in my program i have used random values as input to plotting function,afterwards i will read and plot exact readings from a GPS device.
Again Thanks a lot Chris

Chris+Nipun.py (2.16 KB)

nipun batra wrote:

I have uploaded my code as well where instead of random points i will be plotting current GPS after reading from serial port.

If your base image (map) is always the same, then this should work fine.

> By the way Chris your daughter is very cute.I

didn't want to spoil that image even for a small duration

And to think I was perfectly happy to draw black plots all over her face...what does that say about me as a father :wink:

an image from Open Street Maps. Hope one is allowed to use these images.

OSM is Open, I don't think there are any restrictions on using their images.

Is there any better or simpler way out,which does not consume a lot of time.

If you have to do a lot of points, use numpy.

If you are using a standard projection, and particularly if you might want to use more than one, check out PyProj.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Thanks Chris,
Well now i have been trying to merge this application which you helped me create with others.Have not found success yet.So how can i make an application handling some data which i send to multiple panels one of which is the program you helped me make

If your "programs" are all run in the same python process, than pubsub
should work. Otherwise, you'll have to mess with interprocess
communication. Some solutions to the latter involve writing to a file
and having the programs monitor said file for changes or using a
database. I'm sure there are others too (like queues or pipes perhaps,
but I haven't messed with those much).

···

On Oct 3, 1:51 am, nipun batra <nipunredde...@gmail.com> wrote:

Thanks Chris,
Well now i have been trying to merge this application which you helped me
create with others.Have not found success yet.So how can i make an
application handling some data which i send to multiple panels one of which
is the program you helped me make

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org