Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Formatting output for multi-page print

by Limbic~Region (Chancellor)
on Mar 30, 2003 at 00:02 UTC ( #246662=perlquestion: print w/ replies, xml ) Need Help??
Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:

All:
I have had an idea since my sophmore year in highschool that I have never been able to get very far with. The idea is to graphically see similarities in numbers. The idea is to create a square spiral outward where you either print the number if the number has a given property or leave it empty if it doesn't. You can do this on transparencies so that you can overlap different properties to see similarities.

For instance even numbers where A=10, B=11, C=12:

789A
612B
543C

will yield

 x x
x x 
 x x

You can do this for all sorts of properties (prime, even, odd, square, triangular number, etc). My problem is figuring out how to be able to go very high with my numbers. I want to be able for the program to be able to figure out how many rectangular pieces of paper/transparencies are needed to have a square centered in it and what to print on each page so that they can be taped together after.

I only have very poorly written QBasic code that shows how I created the spiral back then and I don't have the first clue as to how to convert QBasic's locate to Perl or how to be able to spread the output correctly onto multiple pages.

Any ideas would be greatly appreciated.

Cheers - L~R

Comment on Formatting output for multi-page print
Re: Formatting output for multi-page print
by Limbic~Region (Chancellor) on Mar 30, 2003 at 00:21 UTC
    All,
    After I posted this, a few people in the CB didn't understand what I meant and you can't modify a root SOPW node, so this is for clarification.

    I used A,B,C in my example because the numbers 10, 11, and 12 don't fit in the same space as a single digit number.

    Basically, just take a piece of graph paper and write down all the numbers (1 per square) in an outward spiral as described.

    Then with a pencil and blot out all the ones that meet a given criteria.

    Now imagine starting with a bunch of pieces of graph paper already taped together. That is what I am trying to achieve.
    The effect as bart mentioned in the CB is tiling or making a mosaic.

    Hope that helps clarify things - L~R

    Update: It appears that what I had independently come up in my Sophmore year of high school had partially been thought of before me: article 1 & article 2
    Thanks to Enlil for finding them. It seems that no one has been able to find the pattern for primes using this method, but no one has proved that they are not there either. I am in hopes that superimposing different "qualities" will turn up what I am looking for.

Re: Formatting output for multi-page print
by bart (Canon) on Mar 30, 2003 at 02:49 UTC
    Intro: The following post might not make many sense to the innocent bypasser. It is the conclusion of a lengthy discussion on approaches with Limbic~Region on the ChatterBox, and it describes in a code example how I would attack this. Instead of printing to the screen, or a page, I'd build a bitmap graphic out of it, save it to a file, and look at it / postprocess using graphic viewer programs. Anyway, Limbic~Region seems to be very happy with the result, as it is completely different from what he used to do, 10 or so years ago.

    OK, I think I've got something... I think this function will properly calculate Euclidian coordinates for each number you feed it. At least, it calculates the correct coordinates for the first 16 values, and it completely covers the test area, with no holes: if I make each calculated point black for my whole integer range, I get a completely black area, with no spots.

    sub position { my($i) = @_; my $e = int sqrt (--$i); my $r = $i - $e*$e; if($e & 1) { # $e is odd if($r <= $e) { $x = ($e+1)/2; $y = ($e-1)/2 - $r; } else { $x = ($e+1)/2 - ($r-$e); $y = -($e+1)/2; } } else { # $e is even if($r <= $e) { $x = -$e/2; $y = -$e/2 + $r; } else { $x = -$e/2 + ($r-$e); $y = $e/2; } } return ($x, $y); }
    Update: Well, it should produce Euclidian coordinates now. My y's were upside down. Habit from work... :-)

    Now, my idea was to combine this with GD, so you can place a pixel for each number you want marked. For example, this will mark all numbers divisible by 16. It is largely an adaption of the synopsis for GD.

    You need, of course, to combine this with the above sub.

    my $edge = 100; use GD; # create a new image my $im = new GD::Image($edge+2, $edge+2); my $white = $im->colorAllocate(255,255,255); my $red = $im->colorAllocate(255,0,0); # make the background transparent white $im->transparent($white); # This is mine :-) # plot the points my $edge_squared = $edge * $edge; for (my $i = 1; $i <= $edge_squared; $i++) { if($i % 16 == 0) { my($x, $y) = position($i); $im->setPixel($edge/2+$x, $edge/2-$y, $red); } } # Save the image file open PNG, ">result.png" or die "Can't write to file: $!"; # make sure we are writing to a binary stream binmode PNG; # Convert the image to PNG and save it print PNG $im->png;

    If eventually you still need to cut it up to print, you could use one of the graphics modules to split this image up into subimages.

    Update: added introduction

Re: Formatting output for multi-page print
by ambrus (Abbot) on Jan 29, 2009 at 23:12 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://246662]
Approved by bart
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (15)
As of 2014-07-24 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (160 votes), past polls