Home > Archive > PerlTk > July 2005 > Tk::Photo use for scan lines
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Tk::Photo use for scan lines
|
|
| elbob@mailinator.com 2005-07-24, 8:45 pm |
| I can't figure out what I am doing wrong here.
My goal was to intercept incoming single scan lines (i.e. y constant, x
changing) and draw the scans as I get them. I set up this simple test,
and the canvas comes out blank. I seem to be missing something...
Note I create a Photo of height 1 to represent a single scan line. Here
is my simple test code:
use Tk;
use Tk::Photo;
use strict;
use warnings;
my $mw = MainWindow->new;
my $canvas = $mw->Canvas(-width => 100, -height => 100)->pack;
my $image = $canvas->Photo(-width => 100, -height => 1);
my @im;
# make a 100 element array of varying colors
map { push(@im, "#ff0000") } 0 .. 9;
map { push(@im, "#f00000") } 0 .. 9;
map { push(@im, "#d00000") } 0 .. 9;
map { push(@im, "#00ff00") } 0 .. 9;
map { push(@im, "#00f000") } 0 .. 9;
map { push(@im, "#00d000") } 0 .. 9;
map { push(@im, "#0000ff") } 0 .. 9;
map { push(@im, "#0000f0") } 0 .. 9;
map { push(@im, "#0000d0") } 0 .. 9;
map { push(@im, "#0000a0") } 0 .. 9;
$image->put(\@im, -to => 0, 0);
for (my $y=0; $y < 100; $y++) {
$canvas->createImage(0, $y, -image => $image, -anchor => 'nw');
}
$mw->update;
MainLoop;
| |
| Jack D 2005-07-24, 8:45 pm |
|
<elbob@mailinator.com> wrote in message
news:1121932136.452728.195090@f14g2000cwb.googlegroups.com...
> I can't figure out what I am doing wrong here.
>
> My goal was to intercept incoming single scan lines (i.e. y constant, x
> changing) and draw the scans as I get them. I set up this simple test,
> and the canvas comes out blank. I seem to be missing something...
>
> Note I create a Photo of height 1 to represent a single scan line. Here
> is my simple test code:
>
> use Tk;
> use Tk::Photo;
> use strict;
> use warnings;
>
> my $mw = MainWindow->new;
> my $canvas = $mw->Canvas(-width => 100, -height => 100)->pack;
> my $image = $canvas->Photo(-width => 100, -height => 1);
> my @im;
>
> # make a 100 element array of varying colors
> map { push(@im, "#ff0000") } 0 .. 9;
> map { push(@im, "#f00000") } 0 .. 9;
> map { push(@im, "#d00000") } 0 .. 9;
> map { push(@im, "#00ff00") } 0 .. 9;
> map { push(@im, "#00f000") } 0 .. 9;
> map { push(@im, "#00d000") } 0 .. 9;
> map { push(@im, "#0000ff") } 0 .. 9;
> map { push(@im, "#0000f0") } 0 .. 9;
> map { push(@im, "#0000d0") } 0 .. 9;
> map { push(@im, "#0000a0") } 0 .. 9;
>
> $image->put(\@im, -to => 0, 0);
# Don't ask why - it just works :-)
$image->put([\@im], -to => 0, 0);
>
> for (my $y=0; $y < 100; $y++) {
> $canvas->createImage(0, $y, -image => $image, -anchor => 'nw');
> }
> $mw->update;
>
> MainLoop;
>
Jack
| |
| elbob@mailinator.com 2005-07-24, 8:45 pm |
| Holy moly! That's one I wouldn't have thought of. The code shown worked
in another application, but the photo was 2D, and I drew everything and
then displayed it. Since I cut and pasted the code, a typo was out of
the question. So this was pretty mysterious. Thanks a bunch! Sheesh.
| |
| Jack D 2005-07-24, 8:45 pm |
|
<elbob@mailinator.com> wrote in message
news:1121944855.122231.133030@g47g2000cwa.googlegroups.com...
> Holy moly! That's one I wouldn't have thought of. The code shown worked
> in another application, but the photo was 2D, and I drew everything and
> then displayed it. Since I cut and pasted the code, a typo was out of
> the question. So this was pretty mysterious. Thanks a bunch! Sheesh.
>
It's definitely weird - Needing a reference to a reference? - It doesn't
make sense to me, and likely is a bug in 804.
Jack
| |
| John W. Krahn 2005-07-24, 8:45 pm |
| elbob@mailinator.com wrote:
> I can't figure out what I am doing wrong here.
>
> My goal was to intercept incoming single scan lines (i.e. y constant, x
> changing) and draw the scans as I get them. I set up this simple test,
> and the canvas comes out blank. I seem to be missing something...
>
> Note I create a Photo of height 1 to represent a single scan line. Here
> is my simple test code:
>
> use Tk;
> use Tk::Photo;
> use strict;
> use warnings;
>
> my $mw = MainWindow->new;
> my $canvas = $mw->Canvas(-width => 100, -height => 100)->pack;
> my $image = $canvas->Photo(-width => 100, -height => 1);
> my @im;
>
> # make a 100 element array of varying colors
> map { push(@im, "#ff0000") } 0 .. 9;
> map { push(@im, "#f00000") } 0 .. 9;
> map { push(@im, "#d00000") } 0 .. 9;
> map { push(@im, "#00ff00") } 0 .. 9;
> map { push(@im, "#00f000") } 0 .. 9;
> map { push(@im, "#00d000") } 0 .. 9;
> map { push(@im, "#0000ff") } 0 .. 9;
> map { push(@im, "#0000f0") } 0 .. 9;
> map { push(@im, "#0000d0") } 0 .. 9;
> map { push(@im, "#0000a0") } 0 .. 9;
Oooh, that is soo ugly I just had to comment!
# make a 100 element array of varying colors
my @im = (
( '#ff0000' ) x 10,
( '#f00000' ) x 10,
( '#d00000' ) x 10,
( '#00ff00' ) x 10,
( '#00f000' ) x 10,
( '#00d000' ) x 10,
( '#0000ff' ) x 10,
( '#0000f0' ) x 10,
( '#0000d0' ) x 10,
( '#0000a0' ) x 10,
);
John
|
|
|
|
|