si , sono funzioni che ho fatto io e c'è in un f.js che ho fatto io .. nel frattempo che mi hai scritto ho trovato questo esempio.. ma non riesco ad capire dove è il meccanismo che seleziona l'oggetto.
codice:
<!-- This Script is from www.html5freecode.com, Coded by: Kerixa Inc--><br>
<canvas id="myCanvas" width="400" height="230" onclick="DefinePaths(event)"></canvas>
<script>
var cnv = document.getElementById('myCanvas')
var ctx = cnv.getContext('2d')
var deg = Math.PI/180
DefinePaths(null)
function DefinePaths(event){
ctx.beginPath()
ctx.moveTo(10, 70)
ctx.bezierCurveTo (60, 70, 60, 0, 110, 70)
if (event!=null){
if (IsInPath(event)) SelStyle()
else DifStyle()
}else DifStyle()
ctx.closePath()
ctx.fill()
ctx.stroke()
ctx.beginPath()
ctx.moveTo(200, 20)
ctx.lineTo(250, 20)
ctx.quadraticCurveTo(280, 20, 280, 40)
ctx.lineTo(280, 80)
ctx.quadraticCurveTo(260, 80, 250, 100)
ctx.lineTo(200, 100)
ctx.quadraticCurveTo(190, 80, 170, 80)
ctx.lineTo(170, 40)
ctx.quadraticCurveTo(170, 20, 200, 20)
if (event!=null){
if (IsInPath(event)) SelStyle()
else DifStyle()
}else DifStyle()
ctx.closePath()
ctx.fill()
ctx.stroke()
ctx.beginPath()
ctx.moveTo(10, 130)
ctx.lineTo(10, 200)
ctx.lineTo(100, 200)
if (event!=null){
if (IsInPath(event)) SelStyle()
else DifStyle()
}else DifStyle()
ctx.closePath()
ctx.fill()
ctx.stroke()
ctx.beginPath()
ctx.moveTo(220, 130)
ctx.lineTo(170, 180)
ctx.lineTo(220, 230)
ctx.lineTo(270, 180)
if (event!=null){
if (IsInPath(event)) SelStyle()
else DifStyle()
}else DifStyle()
ctx.closePath()
ctx.fill()
ctx.stroke()
}
function IsInPath(event) {
var bb, x, y
bb = cnv.getBoundingClientRect()
x = (event.clientX-bb.left) * (cnv.width/bb.width)
y = (event.clientY-bb.top) * (cnv.height/bb.height)
return ctx.isPointInPath(x,y)
}
function SelStyle(){
ctx.lineWidth= 2
ctx.strokeStyle= "brown"
ctx.fillStyle= "cyan"
}
function DifStyle(){
ctx.lineWidth= 2
ctx.fillStyle= "gray"
ctx.strokeStyle= "darkblue"
}
</script>
grazie ti ringrazio se provi questo ultimo codice.
buona giornata.