[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Generating Music Paper with MacPerl/GD



I had the need to draw a page of music manuscript paper.
The resulting GIF file can be printed. Eventually I will
be making a music notation system using Macperl/GD....it
will first generate a sheet of music, then read a list
of note names/durations, then draw them using a set of
music symbols loaded from another set of GIFS.

Charles


!perl -w
#
# Music Paper drawing
# Written by Charles Cave  12/Sep/1999   charles@mpx.com.au
#
# Music paper consists of multiple sets of five lines
# with left and right margins
#
# All dimensions in pixels  (1 inch approx equal 72 pixels)

# $g  The gap between each of the five lines
# $tm Top margin
# $bm Bottom margin
# $lm Left Margin
# $rm Right Margin
# $w  Width of the paper/image
# $h  Height of the paper/image

#<-----------------------$w---------------------->
#                       $tm
#  $lm -----------------------------------  $rm
#      -----------------$g----------------
#      -----------------------------------
#      -----------------------------------
#      -----------------------------------
#                      $gap                     |
#                                                $h
#      -----------------------------------        |
#      -----------------------------------
#      -----------------------------------
#      -----------------------------------
#      -----------------------------------
#                       $bm

use GD;

# A4 paper (approx dimensions)
$w = 600;
$h = 840;

$tm = 72;
$bm = 60;
$lm = 24;
$rm = 24;
$g = 6;
$gap = 32;

$im = new GD::Image($w, $h);

# set colours
$white = $im->colorAllocate(255,255,255);
$black = $im->colorAllocate(0,0,0);

$n  = int(($h - $bm - $tm) / ((4*$g) + $gap));
print "These dimensions will print $n staves\n";

$y = $tm;

while ($n--) {
  for $lines (1,2,3,4,5) {
    $im->line($lm,$y,$w-$rm,$y,$black);
    $y += $g;
  }
  $y += $gap;
}

open (OUT,">music_paper.gif") || die "couldnt create image file\n";
print OUT $im->gif;
close(OUT);
print "Finished!\n";

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org