#!/usr/bin/perl use strict; use warnings; use CGI (); my $q = CGI->new; # use CGI::Carp 'fatalsToBrowser'; my %circle; my $prev_data; # Read the previous circles my @prev_circles; { my @x_vals = $q->param('x'); my @y_vals = $q->param('y'); my @r_vals = $q->param('r'); for(my $i = 0; $i < @r_vals; $i++) { foreach ($r_vals[$i], $x_vals[$i], $y_vals[$i]) {die "All values must be positive integers!\n" if /[^\d\.]/} push(@prev_circles, { r => $r_vals[$i], x => $x_vals[$i], y => $y_vals[$i], }); } } # 'Draw' the circle in the hash. foreach my $circle (@prev_circles) { my $rmax = $circle->{'r'}; my $center_x = $circle->{'x'}; my $center_y = $circle->{'y'}; $prev_data .= qq~\n~; my %curpass; for my $radius (0 .. $rmax) { for my $i (0 .. $radius ** 2) { # Rounded values my $x_val = int($radius * cos($i) + $center_x + 0.5); my $y_val = int($radius * sin($i) + $center_y + 0.5); $circle{$x_val} ||= {}; $curpass{$x_val} ||= {}; $circle{$x_val}{$y_val} ||= 0; $curpass{$x_val}{$y_val} ||= 0; unless($curpass{$x_val}{$y_val}) { $circle{$x_val}{$y_val}++; $curpass{$x_val}{$y_val}++; } } } } my $output = q~
~; } $output .= " |