Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Details

Privacy

Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

Template

Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:

Screenshot

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO

HTML

              
                
    <h1>Module for drawing shapes!</h1>
    <canvas id="myCanvas" width="800" height="600" ></canvas>
    <script src="script-drawingShapes.js"></script>
              
            
!

CSS

              
                        #myCanvas {
            border: 1px solid #000;
            margin: auto;
        }
              
            
!

JS

              
                var canvas, ctx, canvasWidth, canvasHeight, ballForMuving, lineLeft, lineRight, lineCenter;

    canvas = document.getElementById("myCanvas");
    ctx = canvas.getContext("2d");
    canvasWidth = canvas.width;
    canvasHeight = canvas.height;


var Shape = (function () {
// Class Parent
    var Shapes = (function () {

        function Shapes(x, y) {
            this.x = x;
            this.y = y;
        }
        return Shapes;
    }());

    var Rect = (function () {

        function Rect(x, y, width, height) {
            Shapes.call(this, x, y);
            this._width = width;
            this._height = height;
        }

        Rect.prototype = new Shapes();
        Rect.prototype.drowShapes = function () {
            ctx.beginPath();
            ctx.rect(this.x, this.y, this._width, this._height);
            ctx.fill();
        };

        return Rect;
    }());

    var Circle = (function () {


        function Circle(x, y, r) {
            Shapes.call(this, x, y);
            this._r = r;
            this.sideLeft = x - r;
            this.sideRight = x + r;
            this.sideTop = y - r;
            this.sideBottum = y + r;
        }

        Circle.prototype = new Shapes();

        Circle.prototype.drowShapes = function () {
            ctx.beginPath();
            ctx.arc(this.x, this.y, this._r, 0, 2 * Math.PI);
            ctx.stroke();
        };

        Circle.prototype.sideCircle = (function(){
            var x, y, r;
            x = this.x;
            y = this.y;
            r = this._r;

            var side = {
                left: x - r,
                right: x + r,
                top: y - r,
                bottum: y + r
            }
            return side

        })();

        return Circle;
    }());

    var Line = (function () {

        function Line(x, y, x2, y2) {

            Shapes.call(this, x, y);
            this.x2 = x2;
            this.y2 = y2;
        }

        Line.prototype = new Shapes();
        Line.prototype.drowShapes = function () {
            ctx.beginPath();
            ctx.moveTo(this.x, this.y);
            ctx.lineTo(this.x2, this.y2);
            ctx.stroke();
        };

        return Line;
    }());

    return {
        rectangle: Rect,
        circle: Circle,
        line: Line
    }
}());

function getSideOfBox(box){

    var sideBoxLeft, sideBoxTop, sideBoxRight, sideBoxBottum;

    sideBoxLeft = 0;
    sideBoxTop = 0;
    sideBoxRight = box.width;
    sideBoxBottum = box.height;

    return{
        sideTop: sideBoxTop,
        sideLeft: sideBoxLeft,
        sideRight: sideBoxRight,
        sideBottum: sideBoxBottum
    }
}
var box = getSideOfBox(canvas);

    ballForMuving = new Shape.circle( 50, 100, 50);
    lineLeft = new Shape.line(box.sideLeft, 450, box.sideLeft + 200, 450);
    lineRight = new Shape.line(box.sideRight - 200, 450, box.sideRight, 450);
    lineCenter = new Shape.line(box.sideRight / 2, box.sideBottum / 2, box.sideRight, 450);





function muveRight(circle, boxForGetSide) {
    var box = getSideOfBox(boxForGetSide);
    box.sideTop += circle._r;
    box.sideLeft += circle._r;
    box.sideRight += -circle._r;
    box.sideBottum += -circle._r;

    // Left
    if (circle.x === box.sideLeft) {
        circle.y += -5;
    }

    // Bottum
    if (circle.y === box.sideBottum) {
        circle.x += -5;
    }

    // Top
    if (circle.y === box.sideTop ) {
        circle.x += 5;
    }

    // Right
    if (circle.x === box.sideRight) {
        circle.y += 5;
    }

    lineCenter.x2 = circle.x;
    lineCenter.y2 = circle.y;

};

function muveLeft(circle, boxForGetSide){

    var box = getSideOfBox(boxForGetSide);
    box.sideTop += circle._r;
    box.sideLeft += circle._r;
    box.sideRight += -circle._r;
    box.sideBottum += -circle._r;

    // Left
    if (circle.x === box.sideLeft) {
        circle.y += 5;
    }

    // Top
    if (circle.y === box.sideTop ) {
        circle.x += -5;
    }

    // Right
    if (circle.x === box.sideRight) {
        circle.y += -5;
    }

    // Bottum
    if (circle.y === box.sideBottum) {
        circle.x += 5;
    }

    lineCenter.x2 = circle.x;
    lineCenter.y2 = circle.y;
};

function animation(circle, boxForGetSide) {
    var box = getSideOfBox(boxForGetSide);
    var key ={
        left: "left",
        right: "right"
    }

    var positionBal = key.left;
    function frame() {
        ctx.clearRect(0, 0, canvasWidth, canvasHeight);

        if(positionBal === key.right){
            muveLeft(ballForMuving, canvas);

        }else if(positionBal === key.left){
            muveRight(ballForMuving, canvas);
        };

        if (ballForMuving.sideCircle.right === box.sideRight && ballForMuving.sideCircle.bottum === lineLeft.y){
            positionBal = key.right;
        }

        //Ball in side right
        if(ballForMuving.sideCircle.left === box.sideLeft && ballForMuving.sideCircle.bottum === lineRight.y ){
            positionBal = key.left;
        }

        circle.drowShapes();
        lineLeft.drowShapes();
        lineRight.drowShapes();
        lineCenter.drowShapes();

        requestAnimationFrame(frame);
    }
    frame();
}
animation(ballForMuving, canvas);
              
            
!
999px
What did the HTML say to the CSS? I like your style.

Console