HTML 5 canvas music symbols examples |
Symbol and code | |
Original 1/2 note stem down image
|
Canvas rendered 1/2 note stem down
|
Download file
Line 2 : "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Line 3 : <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> Line 4 : <head> Line 5 : <title>Mobilefish.com - 1/2 note stem down HTML 5 canvas example</title> Line 6 : Line 7 : <!-- Line 8 : Music symbol 1/2 note stem down v. 1.0 Line 9 : Author: Robert Lie Line 10 : www.mobilefish.com Line 11 : Line 12 : This file is public domain. You can use it for any purpose without restriction. Line 13 : I do not guarantee that it is correct, so use it at your own risk. Line 14 : If you use it for something interesting, I'd appreciate hearing about it. Line 15 : If you find any bugs or make any improvements, I'd appreciate hearing about those too. Line 16 : It would also be nice if my name and URL were left in the comments. But none of that is required. Line 17 : Line 18 : Requires: File excanvas.compiled.js Line 19 : HTML5 Canvas for Internet Explorer Line 20 : See: http://code.google.com/p/explorercanvas/ Line 21 : --> Line 22 : Line 23 : <!--[if IE]> Line 24 : <script type="text/javascript" src="scripts/excanvas.compiled.js"></script> Line 25 : <![endif]--> Line 26 : <script type="text/javascript"> Line 27 : Line 28 : Line 29 : function drawShape(){ Line 30 : var canvas = document.getElementById('cssxCoordinates'); Line 31 : if (canvas.getContext){ Line 32 : var ctx = canvas.getContext('2d'); Line 33 : Line 34 : var x = 11; Line 35 : var y = 75; Line 36 : Line 37 : drawNote2(ctx,x,y); Line 38 : Line 39 : } else { Line 40 : alert('You need Firefox 1.5+, Google Chrome 8.0+, Internet Explorer 8.0+ or Safari 4.0+ to see the example.'); Line 41 : } Line 42 : } Line 43 : Line 44 : function drawNote2(ctx,x,y){ Line 45 : drawNoteHeadOpen(ctx,x,y); Line 46 : drawNoteStem(ctx,x,y); Line 47 : } Line 48 : Line 49 : function drawNoteHeadOpen(ctx,x,y){ Line 50 : Line 51 : var x_offset_head = 12; Line 52 : var y_center_head = 74; Line 53 : Line 54 : var x_corner = x - x_offset_head; Line 55 : var y_corner = y - y_center_head; Line 56 : Line 57 : ctx.save(); Line 58 : Line 59 : ctx.translate(x_corner,y_corner); Line 60 : Line 61 : ctx.beginPath(); Line 62 : ctx.moveTo(13,86); Line 63 : ctx.quadraticCurveTo(13,118,42,126); Line 64 : ctx.quadraticCurveTo(67,129,101,108); Line 65 : ctx.quadraticCurveTo(136,85,142,57); Line 66 : ctx.quadraticCurveTo(142,28,112,19); Line 67 : ctx.quadraticCurveTo(88,16,54,36); Line 68 : ctx.quadraticCurveTo(19,59,13,86); Line 69 : ctx.fill(); Line 70 : Line 71 : ctx.fillStyle = "white"; Line 72 : ctx.beginPath(); Line 73 : ctx.moveTo(20,97); Line 74 : ctx.quadraticCurveTo(23,110,34,116); Line 75 : ctx.quadraticCurveTo(51,115,73,100); Line 76 : ctx.quadraticCurveTo(90,91,108,78); Line 77 : ctx.quadraticCurveTo(132,60,135,47); Line 78 : ctx.quadraticCurveTo(133,34,121,30); Line 79 : ctx.quadraticCurveTo(104,31,83,44); Line 80 : ctx.quadraticCurveTo(65,54,50,66); Line 81 : ctx.quadraticCurveTo(26,84,20,97); Line 82 : ctx.fill(); Line 83 : Line 84 : ctx.restore(); Line 85 : } Line 86 : Line 87 : function drawNoteStem(ctx,x,y){ Line 88 : Line 89 : var stem_height = 338; Line 90 : var x_delta_stem = 12; Line 91 : Line 92 : var y_delta_stem = 36; Line 93 : Line 94 : var x_offset_stem = 138; Line 95 : var y_offset_stem = 360; Line 96 : Line 97 : var x_corner = x + x_delta_stem - x_offset_stem; Line 98 : var y_corner = y + y_delta_stem + stem_height - y_offset_stem; Line 99 : Line 100 : ctx.save(); Line 101 : Line 102 : ctx.translate(x_corner,y_corner); Line 103 : Line 104 : ctx.fillStyle = "black"; Line 105 : ctx.beginPath(); Line 106 : ctx.moveTo(127,4); Line 107 : ctx.lineTo(135,4); Line 108 : ctx.lineTo(135,342); Line 109 : ctx.lineTo(127,342); Line 110 : ctx.fill(); Line 111 : Line 112 : ctx.restore(); Line 113 : } Line 114 : Line 115 : </script> Line 116 : </head> Line 117 : <body onload="drawShape();"> Line 118 : <h1>1/2 note stem down</h1> Line 119 : <canvas id="cssxCoordinates" width="150" height="435"></canvas> Line 120 : </body> Line 121 : </html> |