12:01:10 AM
Thursday
Sep 09
Su M Tu W Th F Sa
567891011
12131415161718
19202122232425
262728293012
3456789

Play My Typing Game

View Some of My Artwork

GD & the mathematics of stringed instruments
Have you noticed the frets on a guitar are different sizes and get smaller as you play higher notes? The following outputs as a png image, you can specify how many strings (bass guitar, violin, cello & ukele all have 4 strings) and how many frets to display. I wanted a left and top buffer so I could potentially write information in the future there.

<?

$numstrings = 6;
$numfrets = 22;

$sheight=1250;
$swidth=150;

$xbuffer=50;
$ybuffer=50;

//////////// I wouldn't modify anything below this ////

$png = imagecreatetruecolor($xbuffer+$swidth+1,($sheight+1+$ybuffer));

        // define some colors we might use
    $blk = imagecolorallocate($png, 0, 0, 0);
    $red = imagecolorallocate($png, 255, 0, 0);
        $wht = imagecolorallocate($png, 255,255,255);
        $blue = imagecolorallocate($png, 0, 0, 255);
        $silver = imagecolorallocate($png, 180, 180, 180);


    imagefill($png, 0, 0, $wht);

        imagefilledrectangle($png, $xbuffer, $ybuffer, $swidth+$xbuffer, $sheight+$ybuffer, $blk);

        // edges

        for($i=0;$i<10;$i++)
        {
                if($i==0 || $i==9){ imageline($png, $xbuffer,$ybuffer+$i, $swidth+$xbuffer, $ybuffer+$i, $blk); }
                else { imageline($png, $xbuffer,$ybuffer+$i, $swidth+$xbuffer, $ybuffer+$i, $wht); }

        }
        #imageline($png, 0,$draw, 200, $draw, $blk);

       
        $spot = $sheight+1;
        for($i=1;$i<($numfrets+1);$i++)
        {

                $factor = pow(2.0,1.0/12.0);
                $spot = floor($spot / $factor);
                $draw = $sheight-$spot+$ybuffer;
                if($i==12 || $i == 5 || $i == 7)
                {
                        imageline($png, $xbuffer,$draw, $swidth+$xbuffer, $draw, $red);
                        if($i==12)
                        { // once more
                                imageline($png, $xbuffer,$draw+1, $swidth+$xbuffer, $draw+1, $red);
                        }
                }
                else
                {
                        imageline($png, $xbuffer,$draw, $swidth+$xbuffer, $draw, $silver);
                }
                $last_draw = $draw;
        }

        for($i=0;$i<6;$i++)
        {
                $j=0;
                while($j<(6-$i))
                {
                        if($i==0) { imageline($png, $xbuffer+$j,$ybuffer+1, $xbuffer+$j, $draw, $silver); }
                        #else if($i==5) { imageline($png, $swidth,$ybuffer, $swidth, $draw, $blk); }
                        else { imageline($png, floor($swidth*$i/($numstrings-1))+$j+$xbuffer,$ybuffer+1, floor($swidth*$i/($numstrings-1))+$j+$xbuffer, $draw, $silver); }
                        $j++;
                }
               
        }
       
        $img = imagecreatetruecolor($xbuffer+$swidth+1,$draw);
        imagecopy($img, $png, 0, 0, 0, 0, $xbuffer+$swidth+1, $draw+2);

header('Content-type: image/png');
imagepng($img);
imagedestroy($png);
imagedestroy($img);

?>


and outputs something like



Read Previous:
Using GD to replace colors
Read Next:
How old I am
Table of Contents


Give a listen to my music...
My Best Recordings
How my services and skills can help you:
  • Global (via Email/Skype/AIM(ichat)/Yahoo)
    • Web Development Consulting
    • Custom Web App Development (PHP/MySQL/jQuery/CSS) Cross-Browser & OS
    • Cellphone App Development (Android/MobileWeb)
    • Music Lessons & Education for Beginner Guitar, Piano, Bass, which transfers over to many other instruments I am comfortable playing but not yet at teaching.
    • Music - Soundtrack Composition & Voice Work
  • Local
    • Most all the above, but also:
      • Music Performance (Harp, Voice, Guitar, Piano, Bass, Latin Percussion)
      • Recording Live Music Audio
      • Video Streaming live music and other live events anywhere that can provide wifi
      • Training Video Streaming to your venue's trusted soundperson
Skills:
  • Global (via Email/Skype/AIM(ichat)/Yahoo)
    • Web Development Consulting
    • Custom Web App Development (PHP/MySQL/jQuery/CSS) Cross-Browser & OS
    • Cellphone App Development (Android/MobileWeb)
    • Music Lessons & Education for Beginner Guitar, Piano, Bass, which transfers over to many other instruments I am comfortable playing but not yet at teaching.
    • Music - Soundtrack Composition & Voice Work
  • Local, Most all the above, but also:
    • Music Performance (Harp, Voice, Guitar, Piano, Bass, Latin Percussion)
    • Being your venue's soundman
    • Video Streaming live music and other live events anywhere that can provide wifi
    • Training Video Streaming to your venue's trusted soundperson