Grazie,
non avevo letto attentamente le regole ed infatti non capivo perché il codice non veniva mostrato correttamente.
codice:
<!DOCTYPE>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script>
function f_star(){
var j=document.getElementById("id_star"), cj=j.getContext("2d");
// disegno stella oppure inserire immagine in canvas
with(cj){
fillStyle="#FF0";
strokeStyle="#F00";
lineWidth=1; beginPath();
moveTo(52,5); lineTo(67,34); lineTo(100,39); lineTo(79,64); lineTo(83,97);
lineTo(52,84); lineTo(22,98); lineTo(25,66); lineTo(1,39); lineTo(35,35);
closePath(); stroke(); fill();
}
}
function f_click(e){
if(f_over(e)) alert("click su Stella");
}
function f_mouseover(e){
var j=e.target||e.srcElement;
j.style.cursor=f_over(e)?"pointer":"default";
}
function f_over(e){
var j=e.target||e.srcElement, cj=j.getContext("2d"),
P=getMouseXY(e), x=P.x-parseInt(j.style.left), y=P.y-parseInt(j.style.top),
c = cj.getImageData(x,y,1,1).data;
if(c[0]+c[1]+c[2]) return true;
return false;
}
function getMouseXY(e) {
return { x:(e.pageX ? e.pageX : e.clientX+document.body.scrollLeft-document.body.clientLeft),
y:(e.pageY ? e.pageY : e.clientY+document.body.scrollTop-document.body.clientTop) };
}
</script>
</head>
<body onload='f_star()'>
<canvas id='id_star' style='position:absolute;left:300px;top:100px;' width='120' height='120' onclick='f_click(event)' onmousemove='f_mouseover(event)'></canvas>
</body>
</html>