<commit_before>(function() {
    window.addEventListener("load", function(event) {
       new Canvas();
    });
    
    var Canvas = function() {
        var ctx;
        var ship;
        var canvas = document.getElementById("canvas");
        ctx = canvas.getContext("2d");
        ctx.fillStyle = "white";
        ctx.strokeStyle = "white";
        ctx.lineWidth = 3;
        ctx.translate(canvas.width/2, canvas.height/2);
        ship = new Ship(ctx);
        /*
            TODO: Move the ship to x=0, y=0 
        */
        ship.position.x = 0;
        ship.position.y = 0;
        
        /*
            TODO: Point the spacehip to the right
        */
        ship.direction = 90;
        
        var loop = function() {
            ctx.save();
            // ctx.clearRect(0, 0, canvas.width, canvas.height);
            // FIX: The canvas is not cleared correctly.
            ctx.clearRect(-canvas.width/2, -canvas.height/2, canvas.width, canvas.height);
            ship.render();
            ctx.restore();
            window.requestAnimationFrame(loop);
        };
        window.requestAnimationFrame(loop);
        
        var animate = function() {
            /*
                TODO: Change the ships position here, so that flies to the right.
            */
            ship.position.x++;
            /*
                TODO: Make it start over from the left side, once it exits the canvas.
            */
            if(ship.position.x > canvas.width/2) {
                ship.position.x = -canvas.width/2
            }
            /*
                TODO: The canvas is not cleared correctly. Fix the bug.
                FIX: ctx.clearRect in loop is modified. See above.
            */
        };
        window.setInterval(animate, 1);
   };
   
   var Ship = function(ctx) {
     return {
       position: {
           x: 500,
           y: 500
       },
       direction: 0,
       render: function() {
         ctx.save();
         ctx.translate(this.position.x, this.position.y);
         ctx.rotate(2*Math.PI*this.direction/360);
         ctx.beginPath();
         ctx.moveTo(0, -20);
         ctx.lineTo(10, 20);
         ctx.moveTo(0, -20);
         ctx.lineTo(-10, 20);
         /*
            TODO: Finish drawing the spaceship
         */
         ctx.closePath();
         ctx.stroke();
         ctx.restore();
       }<commit_msg>Finished assignment and solution for lesson 1<commit_after>(function() {
    window.addEventListener("load", function(event) {
       new Canvas();
    });
    
    var Canvas = function() {
        var ctx;
        var ship;
        var canvas = document.getElementById("canvas");
        ctx = canvas.getContext("2d");
        ctx.fillStyle = "white";
        ctx.strokeStyle = "white";
        ctx.lineWidth = 3;
        ctx.translate(canvas.width/2, canvas.height/2);
        ship = new Ship(ctx);
        /*
            TODO: Move the ship to x=0, y=0
            FIX: Set the position.x, and position.y properties to 0
        */
        ship.position.x = 0;
        ship.position.y = 0;
        
        /*
            TODO: Point the spacehip to the right
            FIX: Set the direction to 90 degrees
        */
        ship.direction = 90;
        
        var loop = function() {
            ctx.save();
            // ctx.clearRect(0, 0, canvas.width, canvas.height);
            // FIX: The canvas is not cleared correctly.
            ctx.clearRect(-canvas.width/2, -canvas.height/2, canvas.width, canvas.height);
            ship.render();
            ctx.restore();
            window.requestAnimationFrame(loop);
        };
        window.requestAnimationFrame(loop);
        
        var animate = function() {
            /*
                TODO: Change the ships position here, so that flies to the right.
                FIX: Increased the ships position.x value
            */
            ship.position.x++;
            /*
                TODO: Make it start over from the left side, once it exits the canvas.
                FIX: If the ships position.x value is more than half the width of the canvas, set it to negative half width of the canvas.
            */
            if(ship.position.x > canvas.width/2) {
                ship.position.x = -canvas.width/2
            }
            /*
                TODO: The canvas is not cleared correctly. Fix the bug.
                FIX: ctx.clearRect in loop is modified. See above.
            */
        };
        window.setInterval(animate, 1);
   };
   
   var Ship = function(ctx) {
     return {
       position: {
           x: 500,
           y: 500
       },
       direction: 0,
       render: function() {
         ctx.save();
         ctx.translate(this.position.x, this.position.y);
         ctx.rotate(2*Math.PI*this.direction/360);
         ctx.beginPath();
         ctx.moveTo(0, -20);
         ctx.lineTo(10, 20);
         ctx.moveTo(0, -20);
         ctx.lineTo(-10, 20);
         /*
            TODO: Finish drawing the spaceship
            FIX: Make a line across on the bottom.
         */
         ctx.lineTo(10, 20);
         ctx.closePath();
         ctx.stroke();
         ctx.restore();
       }
{'fraction_non_alphanumeric': 0.11564494295107329, 'fraction_numerical': 0.017791529684780507, 'mean_word_length': 1.3681318681318682, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5363371', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1404, 'n_words': 380}