Some things just a little bit off.
#!/usr/bin/perl
# http://perlmonks.org/?node_id=1212198
use warnings;
use strict;
use Tk;
my $top = new MainWindow;
my $canv;
# offset use to decide the square around a given point
my $offset = 4;
my $num_of_points = 4;
my @points; # ([x1,y1],[x2,y2]...)
my @tk_points; # (tk-canvas,..)
$top->Label(-text => "How many points?")->pack(-side => 'left');
$top->Entry(-width => 3,-borderwidth => 4, -textvariable => \$num_of_p
+oints)->pack(-side => 'left');
$top->Button( -padx=> 5,
-text => "draw",
-borderwidth => 4,
-command => sub{&draw($num_of_points)})->pack(-side => 'left')
+;
$top->Button( -padx=> 5,
-text => "clear",
-borderwidth => 4,
-command => sub{@points = ();
map{ $canv->delete($_) }@tk_points;
})->pack(-side => 'left');
# new toplevel for the circle
$canv=$top->Toplevel(-title=>'Points in a cirlce')->Canvas(-background
+=>'gray',
-width => 610,
-height => 610)->pack;
# the big cirlce
my $circle = $canv->createOval(10,10,600,600,
-fill => 'red',
-outline => 'yellow',
-width => 5,
-tags =>['circle'],
-stipple => 'gray12',
);
# draw the center at 305 305
fat_dot(305,305);
MainLoop;
sub fat_dot {
# center of the new fat dot
my ($x,$y) = @_;
# canvas and top left and bottom right coords of the
# rectangle where the cirlce will be draw
my ($x1,$y1,$x2,$y2) = ($x-$offset,$y-$offset,$x+$offset,$y+$offset)
+;
my $dot = $canv->createOval($x1,$y1,$x2,$y2,-fill => 'black');
return $dot;
}
sub draw{
my $num = shift;
print "received $num as num of points\n";
# sin and cos they think in rad not in degrees!!
my $ang = 3.141592653589793238462643383279 * 2 / $num;
print "angle: $ang radiants\n";
my $cur = 0;
for (1..$num){
my $x = 305 + int(295*sin($cur));
my $y = 5 + 300 - int (295*cos($cur));
print "at $cur radiants point at: $x $y\n";
my $dot = fat_dot($x,$y);
$cur+=$ang;
push @points,[$x,$y];
push @tk_points,$dot;
}
}