You're doing the math for "2*Math.PI*i/p.sides" twice. Divisions are slow (30~50 times slower than addition and multiplication). Do the math once and store it in a variable and reference the two variables in your Math.cos and Math.sin calls.