JavaScript初心者です。
以下のコードが、Uncaught SyntaxError: Unexpected end of input をはいて動きません。(最終行の animate(); です)
色々試したのですが、原因が分からなくなりハマっています。初歩的な質問で申し訳ないのですが、どこに問題があるのかご指摘いただけないでしょうか。
以下にコードを載せます。
一応全コードを載せますが、おそらく問題がある個所は最後の数行だと思われます。
canvas 上で複数の円を動かして、カーソルが近い円を大きくするアニメーションを実装しようとしています。
javascript
1const canvas = document.querySelector("canvas"); 2const mouse = { 3 x : undefined, 4 y : undefined, 5}; 6const number = 30 7canvas.width = window.innerWidth; 8canvas.height = window.innerHeight; 9 10const c = canvas.getContext("2d"); 11const r = 8; 12 13function cirlce(x, y, radius, dx_veloOFx, dy_veloOFy) { 14 this.x = x; 15 this.y = y; 16 this.r = radius; 17 this.dx = dx_veloOFx; 18 this.dy = dy_veloOFy; 19 20 this.draw = function(){ 21 c.beginPath(); 22 c.arc(this.x, this.y, r, 0, Math.PI*2, false); 23 c.fill(); 24 }; 25 26 this.motion = function(){ 27 if (this.x + this.r >= innerWidth || this.x - this.r <= 0){ 28 this.dx = -this.dx; }; 29 if (this.y + this.r >= innerHeight || this.y - this.r <= 0){ 30 this.dy = -this.dy; }; 31 this.x += this.dx; 32 this.y += this.dy; 33 }; 34 35 this.judge = function(){ 36 if( (this.x - mouse.x)^2 + (this.y - mouse.y)^2 <= 1000){ 37 this.r = 40; 38 }; 39 if( (this.x - mouse.x)^2 + (this.y - mouse.y)^2 > 1000){ 40 this.r = 8; 41 }; 42}; 43 44function animate() { 45 requestAnimationFrame(animate); 46 c.clearRect(0, 0, innerWidth, innerHeight); 47 48 for(let i = 0; i<number; i++){ 49 cirArray[i].draw(); 50 cirArray[i].motion(); 51 cirArray[i].judge(); 52 }; 53}; 54 55const cirArray = []; 56 57for (let i = 0; i< number; i++){ 58 let x = Math.random()*innerWidth, 59 y = Math.random()*innerHeight, 60 dx = (Math.random()-0.5)*8, 61 dy = (Math.random()-0.5)*8, 62 63 hako = new cirlce(x, y, r, dx, dy); 64 cirArray.push(hako); 65}; 66 67window.addEevntLisnter('mousemove', 68 function(event){ 69 mouse.x = event.x; 70 mouse.y = event.y; 71 }) 72 73animate();
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/04/04 10:57