Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added line and circle

  • Loading branch information...
commit 84f52e210beaa66009aaf7f6b271a117de68cae9 1 parent 05a3222
@kthakore kthakore authored
Showing with 22 additions and 5 deletions.
  1. +6 −0 code_listings/drawing.pl
  2. +16 −5 src/02-drawing.pod
View
6 code_listings/drawing.pl
@@ -5,8 +5,14 @@
use SDLx::App;
my $app = SDLx::App->new(width => 400, height => 400, title => 'Pong - A clone');
+$app->draw_line( [200,20], [20,200], [255, 255, 0, 255] );
+
$app->draw_rect([ 10, 20, 40 , 40], [255,255,255,255]);
+$app->draw_circle([100,100], 20, [255,0,0,255]);
+
+$app->draw_circle_filled( [100,100], 19, [0,0,255,255] );
+
$app->update();
sleep(2);
View
21 src/02-drawing.pod
@@ -54,7 +54,7 @@ The values of the numbers range from 0-255 for 32 bit depth in RGBA format.
The bits of the surface are set when the surface or app is made.
- my $app = SDLx::App->new( ... depth => 32 );
+ my $app = SDLx::App->new( depth => 32 );
Other options are 24,16 and 8. 32 is the default bit depth.
@@ -64,25 +64,36 @@ Other options are 24,16 and 8. 32 is the default bit depth.
Drawing X<Primitives> are usually simples shapes that can be used for creating graphics dynamically.
+=head2 Lines
+
+ $app->draw_line( [200,20], [20,200], [255, 255, 0, 255] );
+
+This will draw a yellow line from positions C< (200,20) > to C< (20,200) >.
+
=head2 Rectangles
Rectangles are a common building blocks for games. In SDL rectangles are the most cost effective of the primitives to draw.
=for programlisting
- $app->draw_rect( [10,20, 40, 40 ], [255, 255, 255] );
+ $app->draw_rect( [10,20, 40, 40 ], [255, 255, 255,255] );
=for programlisting
-The above will add a white square onto the screen.
+The above will add a white square of size C<40x40> onto the screen at the position C<(10,20)>.
=head2 Circles
-Circles are pretty groovy. We use SDL_gfx library for this.
+Circles are drawn similarly either filled or unfilled.
+
+ $app->draw_circle( [100,100], 20, [255,0,0,255] );
+ $app->draw_circle_filled( [100,100], 19, [0,0,255,255] );
+
+Now we will have a filled circle, colored blue and unfilled circle, colored as red.
=head2 GFX
-SDL_gfx also provides these other neat drawing functions.
+For more complex drawing functions have a look at C<SDL::GFX::Primitives>.
=head1 Multiple Surfaces
Please sign in to comment.
Something went wrong with that request. Please try again.