Skip to content

Instantly share code, notes, and snippets.

@arafatkamaal
Created September 27, 2013 11:24
Show Gist options
  • Save arafatkamaal/6727183 to your computer and use it in GitHub Desktop.
Save arafatkamaal/6727183 to your computer and use it in GitHub Desktop.
Display a pixel on 10x10 grid
use strict;
use warnings;
use Data::Dumper;
my $gridx = 100;
my $gridy = 100;
my $radius = 10;
my $angle = 14;
my $y_axis_intercept =
my $pixel = '.';
my @main_grid;
my $g = init_pixels( 10 , 10 , \@main_grid );
$g = place_pixel_on_grid( 2 , 2 , 10 , 10 , $pixel , $g );
draw_pixels_on_screen( $g , 10 , 10 );
sub place_pixel_on_grid{
my ( $xvalue, $yvalue , $x_axis_limit , $y_axis_limit , $pixel , $grid_values ) = @_;
my @grid = @$grid_values;
my $x = 0;
my $y = 0;
for( $x = $x_axis_limit ; $x >= 0 ; $x-- ){
for( $y = $y_axis_limit ; $y >= 0 ; $y-- ){
$grid[$x][$y] = " " unless $grid[$x][$y] eq $pixel;
}
}
$grid[$xvalue][$yvalue] = $pixel;
return \@grid;
}
sub draw_pixels_on_screen{
my ( $grid_values , $x_axis_limit , $y_axis_limit ) = @_;
my @grid = @$grid_values;
my $x = 0;
my $y = 0;
for( $x = $x_axis_limit ; $x >= 0 ; $x-- ){
for( $y = 0 ; $y <= $y_axis_limit ; $y++ ){
print $grid[$x][$y];
}
print "\n";
}
}
sub init_pixels{
my ( $x_axis_limit , $y_axis_limit , $grid_values ) = @_;
my @grid = @$grid_values;
my $x = 0;
my $y = 0;
for( $x = $x_axis_limit ; $x >= 0 ; $x-- ){
for( $y = $y_axis_limit ; $y >= 0 ; $y-- ){
$grid[$x][$y] = " ";
}
}
return \@grid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment