recommend a graphics library for plotting by the pixel?

A

Adam Funk

I'd like to create a window with a "pause" button and a large plotting
area, in which I'd like to draw a polygon, detect the pixel
coördinates of a mouse click, and then start setting the colors of
pixels by (x,y) coördinates. (This is just for my own amusement, to
play with some formulas for generating fractals using random numbers.)

There seems to be a large number of different python GUI libraries,
and I wonder if someone can recommend the easiests one to learn for
this purpose? (The only python graphics library I've used is PyGame,
which I don't think is the way to go here.)
 
I

Ian Kelly

I'd like to create a window with a "pause" button and a large plotting
area, in which I'd like to draw a polygon, detect the pixel
coördinates of a mouse click, and then start setting the colors of
pixels by (x,y) coördinates.  (This is just for my own amusement, to
play with some formulas for generating fractals using random numbers.)

There seems to be a large number of different python GUI libraries,
and I wonder if someone can recommend the easiests one to learn for
this purpose?  (The only python graphics library I've used is PyGame,
which I don't think is the way to go here.)

You could use wxPython. You'll need to create a custom control and
have it paint itself by blitting from a wx.Bitmap, which you'll draw
on by using a wx.MemoryDC and then refreshing the control.

I would probably just use pygame myself. I guess you're avoiding it
because of the requirement for a button, but there are GUI libraries
available for it, or if all you need are a couple of buttons you could
easily roll your own.

Stay away from the Tkinter Canvas widget. It does vector graphics,
and it will be inefficient if you try to use it as a raster.

Cheers,
Ian
 
A

Adam Funk

If this is strictly for 2D pixel graphics, I recommend using PyGame
(aka SDL). Why do you not think it's the way to go? It was built for
this type of thing.

I only know PyGame because we did an exercise in recreating the old
breakout game and messing around with it at a local Python group.

I was under the mistaken impression from that exercise that you have
to maintain a set of all the objects on the screen and redraw them all
every time through the loop that ends with pygame.display.flip() ---
*but* I now see that the loop starts with these:

clock.tick(tick_rate)
screen.fill((0,0,0))
# comes from screen = pygame.display.set_mode((screen_width,screen_height))
# before the loop

and that I was then deleting hit bricks, calculating the new positions
of the balls, and then redrawing everything that was left on the
secondary screen because things were moving around and disappearing.

I guess if I don't clear the screen at the beginning of the loop but
just blit pixels onto it, when I call display.flip(), it will add the
new blittings to what was already there? If that's true, this will be
much easier than I thought.

The only buttons I have in mind are "pause", "step", "go", and "quit",
and I can just as easily do those with keypresses.
 
W

Westley Martínez

I only know PyGame because we did an exercise in recreating the old
breakout game and messing around with it at a local Python group.

I was under the mistaken impression from that exercise that you have
to maintain a set of all the objects on the screen and redraw them all
every time through the loop that ends with pygame.display.flip() ---
*but* I now see that the loop starts with these:

clock.tick(tick_rate)
screen.fill((0,0,0))
# comes from screen = pygame.display.set_mode((screen_width,screen_height))
# before the loop

and that I was then deleting hit bricks, calculating the new positions
of the balls, and then redrawing everything that was left on the
secondary screen because things were moving around and disappearing.

I guess if I don't clear the screen at the beginning of the loop but
just blit pixels onto it, when I call display.flip(), it will add the
new blittings to what was already there? If that's true, this will be
much easier than I thought.

The only buttons I have in mind are "pause", "step", "go", and "quit",
and I can just as easily do those with keypresses.

Yep. Blitting is replacing the old colors with new colors. It doesn't
replace colors unless you tell it to.
 
A

Adam Funk

You could use wxPython. You'll need to create a custom control and
have it paint itself by blitting from a wx.Bitmap, which you'll draw
on by using a wx.MemoryDC and then refreshing the control.

I would probably just use pygame myself. I guess you're avoiding it
because of the requirement for a button, but there are GUI libraries
available for it, or if all you need are a couple of buttons you could
easily roll your own.

Excellent suggestion. I got it to work, but using keypresses (pause,
step, quit) instead of buttons, and a mouse event for letting the user
pick the start point on the screen.
 
A

Adam Funk

Yep. Blitting is replacing the old colors with new colors. It doesn't
replace colors unless you tell it to.

My mistake was in sample code, running with it, & not looking at it
too closely. ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top