Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Tk Optical Illusion

by zentara (Archbishop)
on Dec 13, 2005 at 16:22 UTC ( #516342=snippet: print w/ replies, xml ) Need Help??

Description: Just a little Tk script to demonstrate the "persistence-of-image" problem in eyes. It's safer than looking at the sun. :-) Just stare at the cross-hairs, you should see a pink orb, where there is none.

UPDATE: I fixed a logic error which caused it to skip at 7 o'clock.

#!/usr/bin/perl
use warnings;
use strict;
use Tk;

# stare at the cross-hairs, a pink orb 
# should appear rotating, where there is none 

my $mw = MainWindow->new();

# first create a canvas widget 
my $canvas = $mw->Canvas(width => 600, height => 600,
                -bg => 'gray',
                )->pack();


my %pos;
my $angle = 0;
my $radius = 200;
my $pos;
my $hidden = 0;

foreach my $pos(0..11){

my $x = 300 + sin($angle)*$radius;
my $y = 300 + cos($angle)*$radius;
my $x1 = $x - 40;
my $y1=  $y - 40;

$pos{$pos} = $canvas->createOval($x,$y,$x1,$y1,
                      -fill => 'green',
                      -outline=>'green',
                      -tags => [$pos],
                     # -stipple => 'gray75', 
                      );
$angle += .5236; # (pi / 180) * 30 
}

$canvas->createLine(260,280,300,280,
            -width=>5, -fill=>'black');
$canvas->createLine(280,260,,280,300,
            -width=>5, -fill=>'black');


my $ebutton = $mw->Button(-text => 'Exit',
                  -command => 'Tk::exit')->pack();

$pos = 0;
my $timer = $mw->repeat(100,sub{
      $canvas->itemconfigure($pos{$hidden} , -state => 'normal');
      $canvas->itemconfigure($pos{$pos}, -state => 'hidden');
            $hidden = $pos;
            $pos++;
            if($pos == 12){ $pos=0 };
       });

MainLoop();

Comment on Tk Optical Illusion
Download Code
Re: Tk Optical Illusion
by Celada (Monk) on Dec 13, 2005 at 17:04 UTC

    I don't see a pink orb, but I do feel a little weird after watching it for a minute or two. I think maybe the monestary is too bright for the effect to work here. Maybe the orb will reveal itself to me later today when I least expect it? Also I have an LCD now. I will pray again later before a CRT altar and see if I get a new effect.

      Well what is supposed to happen, is the green circles dissapear 1 at a time, in a counter clockwise fashion. Where there is no green circle, your eye should see a pink circle. See if you can see it here.

      Maybe the lcd screen dosn't change pixels fast enough for it to work?


      I'm not really a human, but I play one on earth. flash japh

        Lcd monitors (standalone or those of notebooks) currently in use are fast enough. This was not the case with the lcd displays of laptops ten years ago. (I think this is why they're now called TFT instead of LCD.)

        I've followed the link you gave and I've seen the illusion. It's very wierd how the pink dots disappear and sometimes reappear when you stare on the middle cross. I have a tft monitor btw.

        Sorry, I misunderstood you! I see the pink orb going around the circle just fine. I thought I was supposed to see a pink orb in the middle (on the crosshairs), the explanation ostensibly being that my eyes glance at the pink orb around the circumference when I see movement there and the persistence of vision is supposed to show me the orb in the middle when I go back to starting at it.

        Apparently the illusion of the pink orb going around was so strong for me that I never stopped to think that was the illusion!

        No wonder I thought I had missed where the creation of the circulating pink orb occured when I scanned the code! I feel a little silly now... (Oh and maybe still a bit weird from staring at the pattern!)

        I see it on LCD without problem. It's 'Neovo F-417'

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://516342]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2014-09-21 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (165 votes), past polls