javascript - Trying to limit the drawing of Kinetic polygons based on distance from center of stage -



javascript - Trying to limit the drawing of Kinetic polygons based on distance from center of stage -

i trying draw grid of polygons in circle programmatically. im trying using coordinates on canvas element in pythagorean theorem:

function createtri(x, y) { //this function works correctly without if statement. var tri = new kinetic.rect({ x: x, y: y, width: 11, height: 11, fillred: 17, fillgreen: 17, fillblue: 17, closed: true, shadowcolor: '#5febff', shadowblur: 3, shadowopacity: 0.18 }); if ((math.abs(math.pow(x, 2)) + math.abs(math.pow(y, 2))) < math.pow(radius, 2)) { //this causes squares not drawn. layer.add(tri); }; }

how function should work squares should drawn if coordinates less radius, no triangles drawn @ all.

if take out if statement, rest of code draws squares correctly in grid covering page should.

my finish code population of squares this:

var xt = stage.width() / 2; var yt = stage.height() / 2; var radius = 300; var pax = []; //pushes coordinates 3d array (this works correctly) (var = 0; < stage.height() / 12; i++) { pax[i] = []; (var j = 0; j < stage.width() / 12; j++) { pax[i][j] = []; pax[i][j].push(j * 12 - (stage.width() / 2) + xt, * -12 + (stage.height() / 2) + yt); }; } function createtri(x, y) { //this function works correctly without if statement. var tri = new kinetic.rect({ x: x, y: y, width: 11, height: 11, fillred: 17, fillgreen: 17, fillblue: 17, closed: true, shadowcolor: '#5febff', shadowblur: 3, shadowopacity: 0.18 }); if ((math.abs(math.pow(x, 2)) + math.abs(math.pow(y, 2))) < math.pow(radius, 2)) { //this causes squares not drawn. layer.add(tri); }; } //drawing triangles right grid coordinates (this works properly) (var = 0; < pax.length; i++) { (var j = 0; j < pax[i].length; j++) { createtri(pax[i][j][0], pax[i][j][1]); }; }

everything looks correct, im not sure im going wrong if statement.

javascript kineticjs

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -