Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use List::AllUtils qw(max);
- $/ = '';
- # Read in points and folds
- my @Points = map {[split /,/]} split( /\n/, <> );
- my @Folds = map {[m#([xy])=(\d+)#]} split( /\n/, <> );
- my ($X_SIZE, $Y_SIZE) = (40, 6);
- my $LAYER_SIZE = $X_SIZE * $Y_SIZE;
- my $LAYERS = @Folds;
- # Prepare Space Image Format data
- my @sif = (('2') x ($LAYER_SIZE * $LAYERS), ('0') x $LAYER_SIZE);
- foreach my $pt (@Points) {
- my ($x,$y) = ($pt->[0], $pt->[1]);
- # Find layer that brings point into final image box
- my $layer = 0;
- foreach my $fold (@Folds) {
- last if ($x < $X_SIZE and $y < $Y_SIZE);
- if ($fold->[0] eq 'y') {
- $y = 2 * $fold->[1] - $y if ($y > $fold->[1]);
- } else {
- $x = 2 * $fold->[1] - $x if ($x > $fold->[1]);
- }
- $layer++;
- }
- # Set pixel in SIF file
- $sif[$layer * $LAYER_SIZE + $y * $X_SIZE + $x] = 1;
- }
- print @sif, "\n";
Add Comment
Please, Sign In to add comment