in reply to OpenGL L-System Fractal Generator

If you remove unused code and variables and use more idiomatic perl you get something like:

#!/usr/bin/perl use strict; use warnings; use SDL::App; use SDL::OpenGL; $| = 1; my %conf = ( title => 'Game', width => 1200, height => 900, fovy => 125, ); my $sdl_app = SDL::App->new( -title => $conf{ title }, -width => $conf{ width }, -height => $conf{ height }, -gl => 1, ); SDL::ShowCursor( 0 ); my %rule = ( n => 'nlnrrnln', l => 'lnrnrnlln', L => 'LnnRnnL', r => 'rnllnrrn', R => 'RnnLnnR', ); my %rule2 = ( n => 0, l => 60, L => 120, r => -60, R => -120, F => 0, ); for ( 1 .. 4 ) { glClear( GL_COLOR_BUFFER_BIT ); glMatrixMode( GL_PROJECTION ); glLoadIdentity; my $aspect = $conf{ width } / $conf{ height }; gluPerspective( $conf{ fovy }, $aspect, 1, 1000 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity; # Move the viewpoint so we can see the origin glTranslate( 0, -2, -10 ); my @pos = ( 0, 0, 0 ); my $rot; for my $char ( split //, iterate( 'nLnLnL', 4, %rule ) ) { $rot += .01745 * $rule2{ $char }; my ( $x, $y ) = $char eq 'n' ? ( cos( $rot ), sin( $rot ) ) : +( 0, 0 ); @pos = ( $pos[ 0 ] + $x, $pos[ 1 ] + $y, 0 ); for my $step ( 0 .. 9 ) { draw_cube( [ $pos[ 0 ] - ( $x / 10 * $step ), $pos[ 1 ] - +( $y / 10 * $step ), $pos[ 2 ] ], .03, ( .2, .2, .2 ) ); } } print '.'; sleep 1; $sdl_app->sync; } print "\nDone.\n" sub iterate { my ( $inp, $iterations ) = @_; my %rules = @_; for ( 1 .. $iterations ) { $inp .= join '', @rules{ split //, $inp }; } return $inp; } my @indices = qw( 4 5 6 7 1 2 6 5 0 1 5 4 0 3 2 1 0 4 7 3 2 3 7 6 ); sub draw_cube { # A simple cube my ( $x, $y, $z ) = @{ $_[ 0 ] }; my $s = $_[ 1 ]; glColor( @_[ 0, 1, 2 ] ); glBegin( GL_QUADS ); my @vertices = ( [ -$s + $x, -$s + $y, -$s + $z ], [ $s + $x, -$s + $y, -$s + $z ], [ $s + $x, $s + $y, -$s + $z ], [ -$s + $x, $s + $y, -$s + $z ], [ -$s + $x, -$s + $y, $s + $z ], [ $s + $x, -$s + $y, $s + $z ], [ $s + $x, $s + $y, $s + $z ], [ -$s + $x, $s + $y, $s + $z ], ); for my $face ( 0 .. 5 ) { for my $vertex ( 0 .. 3 ) { glVertex( @{ $vertices[ $indices[ 4 * $face + $vertex ] ] +} ); } } glEnd(); }