#!/usr/local/bin/perl # script for generating American flag graphics # by D. Christian Campbell, Jr. on 2001/09/14 # takes output image width as command-line argument use GD; use POSIX qw( ceil floor ); sub PI () { 4 * atan2 1, 1 } $fly = shift; $hoist = int( $fly / 1.9 ); $flag = new GD::Image( $fly, $hoist ); $red = $flag->colorAllocate( 218, 0, 0 ); $white = $flag->colorAllocate( 255, 255, 255 ); $blue = $flag->colorAllocate( 0, 0, 84 ); ########## # bars for $i ( 1 .. 13 ) { $flag->filledRectangle( 0, ceil ( ( $i - 1 ) / 13 * $hoist ), $fly, floor( $i / 13 * $hoist ), $i % 2 ? $red : $white ); } ########## # union $flag->filledRectangle( 0, 0, floor( 0.76 * $hoist ), floor( 7/13 * $hoist ), $blue ); ########## # stars # first the 6 x 5 array for $r ( 1 .. 5 ) { for $c ( 1 .. 6 ) { $star = new GD::Polygon; # center of this star ( $x, $y ) = ( 0.063 * $hoist * ( $c * 2 - 1 ), 0.054 * $hoist * ( $r * 2 - 1 ) ); for $point ( 0 .. 4 ) { # points on the outer radius $star->addPt( floor( $x + 0.0308 * $hoist * sin ( $point / 5 * 2 * PI ) ), floor( $y - 0.0308 * $hoist * cos ( $point / 5 * 2 * PI ) ) ); # points on the inner radius $star->addPt( floor( $x + 0.3819660113 * 0.0308 * $hoist * sin ( ( $point + 0.5 ) / 5 * 2 * PI ) ), floor( $y - 0.3819660113 * 0.0308 * $hoist * cos ( ( $point + 0.5 ) / 5 * 2 * PI ) ) ); } # draw star $flag->filledPolygon( $star, $white ); } } # then the 5 x 4 array for $r ( 1 .. 4 ) { for $c ( 1 .. 5 ) { $star = new GD::Polygon; # center of this star ( $x, $y ) = ( 0.063 * $hoist * ( $c * 2 ), 0.054 * $hoist * ( $r * 2 ) ); for $point ( 0 .. 4 ) { # points on the outer radius $star->addPt( floor( $x + 0.0308 * $hoist * sin ( $point / 5 * 2 * PI ) ), floor( $y - 0.0308 * $hoist * cos ( $point / 5 * 2 * PI ) ) ); # points on the inner radius $star->addPt( floor( $x + 0.3819660113 * 0.0308 * $hoist * sin ( ( $point + 0.5 ) / 5 * 2 * PI ) ), floor( $y - 0.3819660113 * 0.0308 * $hoist * cos ( ( $point + 0.5 ) / 5 * 2 * PI ) ) ); } # draw star $flag->filledPolygon( $star, $white ); } } print $flag->gif;