Making objects in Jquery move at an angle of 55 degrees
Hello guys, I'm new to Jquery. I want my object (mySquare) to move at an angle of 55 degrees, but I can't seem to solve it. Any help would be much appreciated. Thank you.
- $(document).ready(function() {
- //Accessing DOM
-
- var canvas = $("#myCanvas");
- var context = canvas.get(0).getContext("2d");
- canvas.attr("width", $(window).get(0).innerWidth);
- canvas.attr("height", $(window).get(0).innerHeight);
- context.fillRect(0,0, canvas.width(), canvas.height());
- var playAnim = true;
- var startBut = $("#startAnimation");
- var stopBut = $("#stopAnimation");
- startBut.hide();
- startBut.click(function(){
- $(this).hide();
- stopBut.show();
- playAnim = true;
- animate();
- });
- stopBut.click(function(){
- $(this).hide();
- startBut.show();
- playAnim = false;
- });
- //pseudo shape class
- var Shape = function(x, y, width, height){
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- }
- var x=0;
- var vx = 20;
- var vy = 10;
- var ax = 0.05;
- var ay = 0.05;
- var mySquare = new Shape(20, 20, 10,10);
- var anglex = 0;
- var angley = 0.1;
- function animate(){
- var canvasWidth = canvas.width();
- var canvasheight = canvas.height();
- context.clearRect(0,0, canvasWidth,canvasheight);
- //anglex += 1;
- //angley += 1;
- vx = Math.cos(55 * Math.PI/180);
- vy = Math.sin(55 * Math.PI/180);
- vx += ax;
- vy += ay;
-
- mySquare.x+=vx;
- mySquare.y+=vy;
- context.fillRect(mySquare.x, mySquare.y, mySquare.width, mySquare.height);
-
- if(playAnim){
- setTimeout(animate,33);
- }
- }
- animate();
- });