I wanted to make a basic header image for my website, normally I would just use python/PIL but I made the rash decision to jump out of my comfort zone and went for Perl/OpenGL. Very simple but I'm proud of it.

BEGIN{ unshift(@INC,"../blib"); } # in case OpenGL is built but not i +nstalled BEGIN{ unshift(@INC,"../blib/arch"); } # 5.002 gamma needs this BEGIN{ unshift(@INC,"../blib/lib"); } # 5.002 gamma needs this use OpenGL; use warnings; glpOpenWindow; glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-3,3,-3,3,-3,3); glColor3f(1,0,0); sub rect{ if(defined($_[5])){$green =$_[5]}else{$green =0;} glColor3f(($i/(180*$loops)/2,$green,abs(100-($i/360))/2)); if(defined($_[4])){$rot =int($_[4]);$rot*= 0.017453;}else{$rot =0;} my@topleft=($_[0],$_[1]);my@bottomright=($_[2],$_[3]); glBegin(GL_POLYGON); @offset=(cos($rot)/2.5,sin($rot)/2.5); glVertex2f($topleft[0]-$offset[0],$topleft[1]+$offset[1]); glVertex2f($topleft[0]-$offset[0],$bottomright[1]+$offset[1]); glVertex2f($bottomright[0]+$offset[0],$bottomright[1]-$offset[1]); glVertex2f($bottomright[0]+$offset[0],$topleft[1]-$offset[1]); glEnd(); glpFlush(); } $loops=6;$radius=2.5; for ($i=0;$i<180*$loops;$i++){ $radius =$radius/1.00061;$yoff=cos($i/157); rect(-1*$radius,-1*$yoff*1.5,1*$radius,1*$yoff*1.5,$i);} rect(-2.5,-1,2.5,1,0,.2); rect(-2.47,-.97,2.47,.97,0,0); rect(-2.4,-.94,2.43,.943,0,.2); glpMainLoop;

if I 'use strict' it returns for every variable, global symbol $x requires an explicit package name. Am I doing something wrong?

Replies are listed 'Best First'.
Re: A Small Perl Graphical Header
by jdporter (Paladin) on Mar 20, 2012 at 04:57 UTC

    Obviously you need to declare your variables (using my).

    I think you could stand to improve your code formatting. try this on:

    use strict; use warnings; glpOpenWindow; glClearColor(0,0,0,1); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-3,3,-3,3,-3,3); glColor3f(1,0,0); my $loops = 6; my $radius = 2.5; sub rect($$$$$$) { my( $ulx, $uly, $lrx, $lry, $rot, $green ) = @_; glColor3f( $rot/(180*$loops)/2, $green, abs(100-($rot/360))/2 ); # the following must come after the preceding. $rot = defined($rot) ? int($rot) * 0.017453 : 0; my $ofsx = cos($rot)/2.5; my $ofsy = sin($rot)/2.5; glBegin(GL_POLYGON); glVertex2f( $ulx-$ofsx, $uly+$ofsy ); glVertex2f( $ulx-$ofsx, $lry+$ofsy ); glVertex2f( $lrx+$ofsx, $lry-$ofsy ); glVertex2f( $lrx+$ofsx, $uly-$ofsy ); glEnd(); glpFlush(); } for ( my $i = 0; $i<180*$loops; $i++ ) { $radius /= 1.00061; my $yoff = cos($i/157); rect( -1*$radius, -1*$yoff*1.5, 1*$radius, 1*$yoff*1.5, $i, 0 ); } rect( -2.5 , -1 , 2.5 , 1 , 0, 0.2 ); rect( -2.47, -0.97, 2.47, 0.97 , 0, 0 ); rect( -2.4 , -0.94, 2.43, 0.943, 0, 0.2 ); glpMainLoop;
    I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.