Re: [Tutor] plotting pixels

2010-09-25 Thread pierre dagenais

On 10-09-18 07:39 PM, ALAN GAULD wrote:
 It appears that the Tk canvas widget does not support simply 
plotting a pixel.


Correct, and I agree it seems odd, but in practice drawing either 
lines or

ovals of one-pixel do the equivalent job - albeit a little more slowly.

 The primitive obviously exists in the underlying code,

It probably exists in the native graphics toolkit (Xlib or Win32 or Aqua)
but it doesn't exist at the Tk level which is why Tkinter can't expose it.

FWIW wxPython does provide a DrawPoint() method as part of its
DeviceContext class.

Digging a little deeper it seems the idiomatic way to do this in Python
is to use PIL the Python Imaging Library to create a GIF or bitmap
image and then insert that into Tkinters cancvas as an image object.

The Pil ImageDraw class has a point() ethod

I've never tried this but it is described in Grayson's (now out of 
print?)

book on Tkinter where he uses it to draw a Mandelbrot
The book may be available online these days...

Nowdownloadall.com seems to have it although I've no idea
of the legality of it!

HTH,

Alan G.

Here's a link, just don't download everything. It would be excessively 
large.


http://isohunt.com/download/212380933/%22Python+and+Tkinter+Programming%22.torrent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] plotting pixels

2010-09-19 Thread Lie Ryan
On 09/19/10 09:39, ALAN GAULD wrote:
 It appears that the Tk canvas widget does not support simply plotting
 a pixel. 
 
 Correct, and I agree it seems odd, but in practice drawing either lines or
 ovals of one-pixel do the equivalent job - albeit a little more slowly.

More slowly and takes huge amount of memory. A single Tk canvas object
takes at least 14 words (= 114 bytes in 64-bit OS = 56 bytes in 32-bit
OS) + the amount of data is needed to store the `kind of object`. That's
much larger than the ideal 3 bytes per pixel (or 4 bytes with alpha).

Tkinter's Canvas intentionally doesn't provide create_pixel() because
unlike most other Canvas implementations, Tkinter's Canvas holds a
stateful canvas objects instead of a simple drawing surface. Providing a
create_pixel() will be too tempting for abuse, which would make the
canvas unbearably slow and memory consuming. In short, Canvas is not
designed for pixel drawing.

 Digging a little deeper it seems the idiomatic way to do this in Python
 is to use PIL the Python Imaging Library to create a GIF or bitmap
 image and then insert that into Tkinters cancvas as an image object.
 
 The Pil ImageDraw class has a point() ethod

If you need to plot pixels, do use pygame, PIL, or at least the
PhotoImage trick.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] plotting pixels

2010-09-19 Thread Steven D'Aprano
Hello Ken,

On Sun, 19 Sep 2010 04:18:06 am Ken Oliver wrote:
 HEAD
 STYLEbody{font-size:10pt;font-family:arial,sans-serif;background-co
lor:#ff;color:black;}p{margin:0px;}/STYLE
 META name=GENERATOR content=MSHTML 8.00.6001.18939/HEAD
 BODYBRBRBR
 BLOCKQUOTE style=BORDER-LEFT: #ff 2px solid; PADDING-LEFT: 5px;
[lots more HTML junk]


Ken, this is what I see when I read your emails. Could you please find 
the setting in your email client to send plain text as well as HTML (or 
what is wrongly called rich text by some email clients) and turn it 
on? Unfortunately I've never used EarthLink Zoo Mail 1.0, so I can't 
tell you how.

Not only is HTML-only posting considered rude by millions of people, but 
it's also counter-productive. Pure HTML is one of the stronger 
indications of Spam email, almost as strong as mentioning that word 
that starts with V and sounds like Niagara Falls, and so chances are 
good that some of your emails are being flagged as spam by anti-spam 
checks.


-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] plotting pixels

2010-09-19 Thread Bill Allen
On Sun, Sep 19, 2010 at 2:40 AM, Lie Ryan lie.1...@gmail.com wrote:


 More slowly and takes huge amount of memory. A single Tk canvas object
 takes at least 14 words (= 114 bytes in 64-bit OS = 56 bytes in 32-bit
 OS) + the amount of data is needed to store the `kind of object`. That's
 much larger than the ideal 3 bytes per pixel (or 4 bytes with alpha).

 Tkinter's Canvas intentionally doesn't provide create_pixel() because
 unlike most other Canvas implementations, Tkinter's Canvas holds a
 stateful canvas objects instead of a simple drawing surface. Providing a
 create_pixel() will be too tempting for abuse, which would make the
 canvas unbearably slow and memory consuming. In short, Canvas is not
 designed for pixel drawing.

  Digging a little deeper it seems the idiomatic way to do this in Python
  is to use PIL the Python Imaging Library to create a GIF or bitmap
  image and then insert that into Tkinters cancvas as an image object.
 
  The Pil ImageDraw class has a point() ethod

 If you need to plot pixels, do use pygame, PIL, or at least the
 PhotoImage trick.

 Thanks for the feedback!   That does make a lot a sense as to why a
pixel_plot() type function would not be directly implemented in Canvas.  As
this is still largely a learning exercise for me, I may try more than one
approach.  I think first I will try the PhotoImage approach, which might be
the most efficient method.  However, I will definitely give Pygame a try.  I
have seen several programs that were written in Pygame and I am really
impressed!  It is obviously designed to task.

-Bill
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] plotting pixels

2010-09-18 Thread Bill Allen
On Fri, Sep 17, 2010 at 3:38 AM, Alan Gauld alan.ga...@btinternet.comwrote:


 For plotting pixels I would not use turtle graphics.
 That would be a fairly complicated option I'd have thought.
 A simple canvas would be easier.

 Alan G.


Oh, I see!  I did not realize that Tk had a canvas widget.  That is nice.  I
will have to play with that and see if I can get everything done in the code
I am working with.  What I am doing is just trying to do a simple Mandelbrot
set plot.  It is another bit of coding that I do when learning a new
language to get a handle on some of the graphics capabilities, and I am to
that point.

-Bill
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] plotting pixels

2010-09-18 Thread Bill Allen
On Sat, Sep 18, 2010 at 10:44 AM, Bill Allen walle...@gmail.com wrote:



 On Fri, Sep 17, 2010 at 3:38 AM, Alan Gauld alan.ga...@btinternet.comwrote:


 For plotting pixels I would not use turtle graphics.
 That would be a fairly complicated option I'd have thought.
 A simple canvas would be easier.

 Alan G.


 Oh, I see!  I did not realize that Tk had a canvas widget.  That is nice.
 I will have to play with that and see if I can get everything done in the
 code I am working with.  What I am doing is just trying to do a simple
 Mandelbrot set plot.  It is another bit of coding that I do when learning a
 new language to get a handle on some of the graphics capabilities, and I am
 to that point.

 -Bill

 It appears that the Tk canvas widget does not support simply plotting a
pixel.  However, I can plot a line only one pixel long.   I wonder why they
do not simply provide the pixel plot primitive?  I have seen very many
graphics packages that do this and I have always wondered why.  The
primitive obviously exists in the underlying code, because that is what
everything else is built upon.  Does Tk actually have a something like a
create_pixel method in the canvas widget that I have missed?

-Bill
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] plotting pixels

2010-09-18 Thread Ken Oliver


-Original Message- From: Bill Allen <walle...@gmail.com>Sent: Sep 18, 2010 11:45 AM To: Alan Gauld <alan.ga...@btinternet.com>Cc: tutor@python.org Subject: Re: [Tutor] plotting pixels 
On Sat, Sep 18, 2010 at 10:44 AM, Bill Allen walle...@gmail.com wrote:


On Fri, Sep 17, 2010 at 3:38 AM, Alan Gauld alan.ga...@btinternet.com wrote:
For plotting pixels I would not use turtle graphics.That would be a fairly complicated option I'd have thought.A simple canvas would be easier.Alan G. 


Oh, I see! I did not realize that Tk had a canvas widget. That is nice. I will have to play with that and see if I can get everything done in the code I am working with. What I am doing is just trying to do a simple Mandelbrot set plot. It is another bit of coding that I do when learning a new language to get a handle on some of the graphics capabilities, and I am to that point. -Bill
It appears that the Tk canvas widget does not support simply plotting a pixel. However, I can plot a line only one pixel long. I wonder why they do not simply provide the pixel plot primitive? I have seen very many graphics packages that do this and I have always wondered why. The primitive obviously exists in the underlying code, because that is what everything else is built upon. Does Tk actually have a something like a create_pixel method in the canvas widget that I have missed?-Bill
Is it naive of me to ask, "Couldn't one write his own plotpixel( ) function using the line() function?"

 .
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] plotting pixels

2010-09-18 Thread Lie Ryan
  It appears that the Tk canvas widget does not support simply
 plotting a pixel.  However, I can plot a line only one pixel long.  
 I wonder why they do not simply provide the pixel plot primitive?  I
 have seen very many graphics packages that do this and I have always
 wondered why.  The primitive obviously exists in the underlying
 code, because that is what everything else is built upon.  Does Tk
 actually have a something like a create_pixel method in the canvas
 widget that I have missed?

You don't want that.

Tkinter's Canvas is a Smart Canvas, each lines and shapes corresponds to
a Tcl/Tk object. If you want to plot a 800*600 image pixel-per-pixel in
Tkinter's Canvas, then Tkinter would have to create 48 Tcl Objects.

If you want to draw pixels and lines directly, Tkinter Canvas isn't
suitable for that. Try using a different Canvas, one that uses a
Stateless Canvas.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] plotting pixels

2010-09-18 Thread Bill Allen
On Sat, Sep 18, 2010 at 1:18 PM, Ken Oliver ksterl...@mindspring.comwrote:



 On Fri, Sep 17, 2010 at 3:38 AM, Alan Gauld alan.ga...@btinternet.comwrote:


 For plotting pixels I would not use turtle graphics.
 That would be a fairly complicated option I'd have thought.
 A simple canvas would be easier.

 Alan G.


 Oh, I see!  I did not realize that Tk had a canvas widget.  That is nice.
 I will have to play with that and see if I can get everything done in the
 code I am working with.  What I am doing is just trying to do a simple
 Mandelbrot set plot.  It is another bit of coding that I do when learning a
 new language to get a handle on some of the graphics capabilities, and I am
 to that point.

 -Bill

  It appears that the Tk canvas widget does not support simply plotting a
 pixel.  However, I can plot a line only one pixel long.   I wonder why they
 do not simply provide the pixel plot primitive?  I have seen very many
 graphics packages that do this and I have always wondered why.  The
 primitive obviously exists in the underlying code, because that is what
 everything else is built upon.  Does Tk actually have a something like a
 create_pixel method in the canvas widget that I have missed?

 -Bill

 Is it naive of me to ask, Couldn't one write his own plotpixel( ) function
 using the line() function?

  .

 No, not naive at all.  Indeed I could, but that is not the issue in my
mind.  My point is that it seems strange to me that any graphics package
would not make the most basic of the routines, ploting a single pixel,
available.   I think I actually see a way of doing it with the bitmap class,
but that is not the point.  While I could do exactly as you have said, I
would rather either write my own low-level code to accomplish that or use a
package that does provide it than to wrap up a higher end function, such as
drawing a line or rectangle, into even more code in order to do less.   For
the particular use that I am going to put this to, a package such as pygame
which does provide the ability to plot pixels directly will be more
suitable.

-Bill
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] plotting pixels

2010-09-18 Thread ALAN GAULD
 It appears that the Tk canvas widget does not support simply plotting a  
pixel.  


Correct, and I agree it seems odd, but in practice drawing either lines or 
ovals of one-pixel do the equivalent job - albeit a little more slowly.

 The  primitive obviously exists in the underlying code, 

It probably exists in the native graphics toolkit (Xlib or Win32 or Aqua) 
but it doesn't exist at the Tk level which is why Tkinter can't expose it.

FWIW wxPython does provide a DrawPoint() method as part of its 
DeviceContext class.

Digging a little deeper it seems the idiomatic way to do this in Python 
is to use PIL the Python Imaging Library to create a GIF or bitmap 
image and then insert that into Tkinters cancvas as an image object.

The Pil ImageDraw class has a point() ethod

I've never tried this but it is described in Grayson's (now out of print?) 
book on Tkinter where he uses it to draw a Mandelbrot
The book may be available online these days...

Nowdownloadall.com seems to have it although I've no idea 
of the legality of it!

HTH,

Alan G.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] plotting pixels

2010-09-18 Thread Bill Allen

 Digging a little deeper it seems the idiomatic way to do this in Python
 is to use PIL the Python Imaging Library to create a GIF or bitmap
 image and then insert that into Tkinters cancvas as an image object.

 The Pil ImageDraw class has a point() ethod

 I've never tried this but it is described in Grayson's (now out of print?)
 book on Tkinter where he uses it to draw a Mandelbrot
 The book may be available online these days...

 Nowdownloadall.com seems to have it although I've no idea
 of the legality of it!

 HTH,

 Alan G.

Yes, to create a gif or a bmp from the iteration results and then to display
that at the end of the run is by far the most efficient way of producing
Mandelbrot and related sets.  I have actually done it that way before.   I
just have always had a strange preference to see the set as it is being
produced, which is far from efficient.  Kind of a very elaborate progress
bar!  Anyway, I have no real complaints about the Tk canvas methods.  It has
always just been a pet peeve of mine when something as basic and simple as
plotting a pixel is missing.  My complaint on this goes way back to the
ancient days when I had to figure out how to write a plot_pixel primitive in
x86 assembler and then build a graphics library of my own so I could have
pixel based graphics on my old monochrome IBM XT clone that had a Hercules
graphics card in it.  Those were the days!  Mandelbrot sets in 4 shades of
amber-monochrome!;-)   I will check out that book you referenced.   I
appreciate everybody's feedback on this.

-Bill
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] plotting pixels

2010-09-18 Thread Bill Allen
On Sat, Sep 18, 2010 at 9:26 PM, Bill Allen walle...@gmail.com wrote:



 Digging a little deeper it seems the idiomatic way to do this in Python
 is to use PIL the Python Imaging Library to create a GIF or bitmap
 image and then insert that into Tkinters cancvas as an image object.

 The Pil ImageDraw class has a point() ethod

 I've never tried this but it is described in Grayson's (now out of print?)

 book on Tkinter where he uses it to draw a Mandelbrot
 The book may be available online these days...

 Nowdownloadall.com seems to have it although I've no idea
 of the legality of it!

 HTH,

 Alan G.

 Yes, to create a gif or a bmp from the iteration results and then to
 display that at the end of the run is by far the most efficient way of
 producing Mandelbrot and related sets.  I have actually done it that way
 before.   I just have always had a strange preference to see the set as it
 is being produced, which is far from efficient.  Kind of a very elaborate
 progress bar!  Anyway, I have no real complaints about the Tk canvas
 methods.  It has always just been a pet peeve of mine when something as
 basic and simple as plotting a pixel is missing.  My complaint on this goes
 way back to the ancient days when I had to figure out how to write a
 plot_pixel primitive in x86 assembler and then build a graphics library of
 my own so I could have pixel based graphics on my old monochrome IBM XT
 clone that had a Hercules graphics card in it.  Those were the days!
 Mandelbrot sets in 4 shades of amber-monochrome!;-)   I will check out
 that book you referenced.   I appreciate everybody's feedback on this.

 -Bill


 I found this code on the web.  It creates a 100x100 tk.photoimage  and
fills it with a radom colored pixels then displays it.  It seems to me that
I should be able to adapt this to what I am trying to acomplish.  The only
difference in the way I am filling the tk.photoimage object.  I ran this
under Python 3.1.2 with success.  I believe the '#%02x%02x%02x' is the
format for an image.   It is a color photoimage, but I am presuming that if
written directly out to a file this would not actually produce a valid, bmp,
gif, pgn, etc.  Correct?   This does seem to be a reasonable solution that
is a pure Tk solution.  Also it works in Python 3x, whereas the PIL library
has not yet been released for 3x.   I have not mentioned it before, but
using Python 3x only is also one of my requirement, though self-imposed.
Can anyone help me better understand this part of the code below?
self.i.put('#%02x%02x%02x' % tuple(color),(row,col))

import tkinter, random
class App:
def __init__(self, t):
self.i = tkinter.PhotoImage(width=100,height=100)
colors = [[random.randint(0,255) for i in range(0,3)] for j in
range(0,1)]
row = 0; col = 0
for color in colors:
self.i.put('#%02x%02x%02x' % tuple(color),(row,col))
col += 1
if col == 100:
row +=1; col = 0
c = tkinter.Canvas(t, width=100, height=100); c.pack()
c.create_image(0, 0, image = self.i, anchor=tkinter.NW)

t = tkinter.Tk()
a = App(t)
t.mainloop()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] plotting pixels

2010-09-17 Thread Alan Gauld


Bill Allen walle...@gmail.com wrote

Is there a simple way to plot pixels in Python, without resorting to 
turtle

graphics?


James already mentioned matplotlib but you can just draw on a canvas.
It depends on what you are trying to do.

For plotting pixels I would not use turtle graphics.
That would be a fairly complicated option I'd have thought.
A simple canvas would be easier.

Alan G. 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] plotting pixels

2010-09-16 Thread Bill Allen
Is there a simple way to plot pixels in Python, without resorting to turtle
graphics?


--Bill
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] plotting pixels

2010-09-16 Thread James Mills
On Fri, Sep 17, 2010 at 12:13 PM, Bill Allen walle...@gmail.com wrote:
 Is there a simple way to plot pixels in Python, without resorting to turtle
 graphics?

Give matplotlib a go.

Alternatively you may want to try pygame or pyglet.

cheers
James

-- 
-- James Mills
--
-- Problems are solved by method
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] plotting pixels

2010-09-16 Thread Bill Allen
On Thu, Sep 16, 2010 at 9:21 PM, James Mills
prolo...@shortcircuit.net.auwrote:

 On Fri, Sep 17, 2010 at 12:13 PM, Bill Allen walle...@gmail.com wrote:
  Is there a simple way to plot pixels in Python, without resorting to
 turtle
  graphics?

 Give matplotlib a go.

 Alternatively you may want to try pygame or pyglet.

 cheers
 James

 --
 -- James Mills
 --

Thanks!  I'll give those a try.

--Bill
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor