Note that there are some explanatory texts on larger screens.

plurals
  1. PODetect mouse click location within canvas
    primarykey
    data
    text
    <p>I'm having a real issue trying to define a function for where I click on empty space. So far I have managed to define where I click on an object - of which there are 10 - but now I need a separate function for when I am not clicking on any of the objects. The general idea can be found at <a href="http://deciballs.co.uk/experience.html" rel="nofollow">http://deciballs.co.uk/experience.html</a>. The objects are the rings. My code is below... Any ideas?</p> <pre><code>var shapeObj = function (context, canvas, settingsBox, radius) { this.ctx = context; this.canvas = canvas; this.sBox = settingsBox; this.frequencies = new Array(220, 440, 1024, 2048); this.cols = new Array(255, 225, 200, 175, 150); this.strokes = new Array(1, 1.5, 2); this.waves = new Array('sine', 'sawtooth', 'triangle', 'square'); this.properties = { dur: Math.random()*0.5, freq: this.frequencies[Math.floor(Math.random() * this.frequencies.length)], radius: radius, stroke: this.strokes[Math.floor(Math.random() * this.strokes.length)], speed: Math.random()*6-3, vol: Math.random()*10, col1: this.cols[Math.floor(Math.random() * this.cols.length)], col2: this.cols[Math.floor(Math.random() * this.cols.length)], col3: this.cols[Math.floor(Math.random() * this.cols.length)], alpha: 0, wave: this.waves[Math.floor(Math.random() * this.waves.length)], delay: 0 } this.x = Math.random()*this.ctx.canvas.width; this.y = Math.random()*this.ctx.canvas.height; this.vx = 0.5; this.vy = 1; this.draw = function () { this.ctx.beginPath(); this.ctx.arc(this.x, this.y, this.properties.radius, 0, Math.PI*2, false); this.ctx.closePath(); this.ctx.stroke(); this.ctx.fill(); } this.clickTest = function (e) { var canvasOffset = this.canvas.offset(); var canvasX = Math.floor(e.pageX-canvasOffset.left); var canvasY = Math.floor(e.pageY-canvasOffset.top); var dX = this.x-canvasX; var dY = this.y-canvasY; var distance = Math.sqrt((dX*dX)+(dY*dY)); if (distance &lt; this.properties.radius) { this.manageClick(); } else { this.properties.alpha = 0; } }; this.manageClick = function () { this.sBox.populate(this.properties, this); var divs = document.getElementsByTagName('section'); for(var i = 0, e = divs[0], n = divs.length; i &lt; n; e = divs[++i]){ e.className='class2'; } this.properties.alpha = 0.5; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload