# 99bottles.gp: # Gnuplot is a well-known, portable command-line driven interactive data and # function plotting utility (http://www.gnuplot.info). So arguably it should # have some graphics output. Here is a script for gnuplot version 4.2 that # outputs the 99-bottles-of-beer-song and also draws some bottles on the # screen... (written by Bastian Maerkisch) # Define a maximum number of bottles in case we do not want so many beers... if (!exists("max")) max = 99 # Create and initialize the (remaining) bottles counter if (!exists("bottles")) bottles = max # Initialize the plot settings if (bottles == max) \ unset border;\ unset tics ;\ set lmargin 1;\ set rmargin 1;\ unset key; \ set parametric; \ set xrange [-1:29.5]; \ set yrange [-11:29]; \ set samples 561; \ set style line 1 linetype 1 lc rgb "#008800" lw 0; \ set style line 2 linetype 1 lc rgb "brown" lw 3; \ set style line 3 linetype 1 lc rgb "#008800" lw 5; # Define a string valued function to create the "bottle(s)" string # Note that there is no name conflict with the bottles variable. bottles(b) = " bottle" . "s"[0:(b != 1)] . " " # Function which returns the number b or the string "no more" iff b=0. # The case of the first letter can be switched by the parameter c # (c==1 means capital, c==0 lower case) number(b, c) = (b > 0) ? sprintf("%d", b) : "nN"[c+1:c+1] . "o more" # We use a ternary operator to decide what to do next -- Get more beer! ;-) action(b) = (b != 0) ? \ "Take one down and pass it around" : \ "Go to the store and buy some more" # Calculate the number of bottles after "taking one down" bmm(b) = (b + max) % (max + 1) # Function to return a complete verse verse(b) = number(b, 1) . bottles(b) . "of beer on the wall, " . \ number(b, 0) . bottles(b) . "of beer.\n" .\ action(b) . ", " .\ number(bmm(b), 0) . bottles(b - 1) .\ "of beer on the wall." # Parametric function definition of one half of a bottle halfabottle_x(t) = (t < 1) ? t : ((t<4) ? 1 :