Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Asymptote

Date:12/06/10
Author:Johannes Schöön
URL:n/a
Comments:0
Info:http://asymptote.sourceforge.net
Score: (3.00 in 2 votes)
// An Asymptote script for generating the lyrics of the song "99
// bottles of beer". For instant gratification, feed it to Asymptote
// with the command:
//
//   asy -V beer.asy
//
// If you have no postscript viewer, you may want to try:
//
//   asy -V -tex pdflatex beer.asy
//
// instead.
//
// copyright 2010 Johannes Schöön
//
// (Despite all efforts, it still contains one goto statement.)

string int2verse(int n){
  // Converts the current number of beers on the wall into a string
  // containing the corresponding verse in the lyrics.

  if ((n <= 99) && (n > 2)) {
    return format("%i bottles of beer on the wall, ", n) +
      format("%i bottles of beer.\\", n) +
      "Take one down and pass it around, " +
      format("%i bottles of beer on the wall.", n - 1);

  } else if (n == 2) {
    return "2 bottles of beer on the wall, 2 bottles of beer.\\" +
      "Take one down and pass it around, one bottle of beer on the wall.";

  } else if (n == 1) {
    return "1 bottle of beer on the wall, 1 bottle of beer.\\" +
      "Take one down and pass it around, " +
      "no more bottles of beer on the wall.";

  } else if (n == 0) {
    return "No more bottles of beer on the wall, " +
      "no more bottles of beer.\\" +
      "Go to the store and buy some more, " +
      "99 bottles of beer on the wall.";

  } else {
    abort(format("Illegal input value given to int2verse: %i.", n));
    return "";
  };
};

// The following will display all but the final verse as a spiral...
int maxverse = 99;
for (int n = maxverse; n > 0; --n){
  real r = 100 + 700 * (0.2 + n/maxverse)**1.2;
  real a = 6 * 360 * (maxverse - n)/r;
  label(rotate(a) * minipage("\raggedright \tiny " + int2verse(n), 3cm),
        r * dir(a));
};

// ...with the last verse in the centre.
label(minipage("\raggedright \large " + int2verse(0), 8cm), (0,0), red);

Download Source | Write Comment

Alternative Versions

Comments

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: