HTML 5 canvas music symbols examples |
Symbol and code | |
Original 1/2 note stem up image
|
Canvas rendered 1/2 note stem up
|
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 up HTML 5 canvas example</title> Line 6 : Line 7 : <!-- Line 8 : Music symbol 1/2 note stem up 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 = 363; 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 : ctx.restore(); Line 84 : } Line 85 : Line 86 : function drawNoteStem(ctx,x,y){ Line 87 : Line 88 : var x_delta_stem = 133; Line 89 : var y_delta_stem = 36; Line 90 : Line 91 : var x_offset_stem = 138; Line 92 : var y_offset_stem = 327; Line 93 : Line 94 : var x_corner = x + x_delta_stem - x_offset_stem; Line 95 : var y_corner = y - y_delta_stem - y_offset_stem; Line 96 : Line 97 : ctx.save(); Line 98 : Line 99 : ctx.translate(x_corner,y_corner); Line 100 : Line 101 : ctx.fillStyle = "black"; Line 102 : ctx.beginPath(); Line 103 : ctx.moveTo(127,4); Line 104 : ctx.lineTo(135,4); Line 105 : ctx.lineTo(135,342); Line 106 : ctx.lineTo(127,342); Line 107 : ctx.fill(); Line 108 : Line 109 : ctx.restore(); Line 110 : } Line 111 : Line 112 : </script> Line 113 : </head> Line 114 : <body onload="drawShape();"> Line 115 : <h1>1/2 note stem up</h1> Line 116 : <canvas id="cssxCoordinates" width="150" height="435"></canvas> Line 117 : </body> Line 118 : </html> |