Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Canvas Animation Kit Experiment... ...how to clear the canvas?

I can make a obj to use the canvas to draw like this:

MyObj.myDiv = new Canvas($("effectDiv"), Setting.width,  Setting.height);

Then, I use this to draw a rectangle on the canvas:

    var c =  new Rectangle(80, 80,
        {
            fill: [220, 40, 90]
        }
    );
    var move = new Timeline;
    move.addKeyframe(0,
        {
            x: 0,
            y: 0
        }
    );
    c.addTimeline(move);
    MyObj.myDiv.append(c);

But after I draw the rectangle, I want clear the canvas, but I don't know which method and how to do this... ...

O...one more thing: it is the CAKE's web site: Link

like image 368
DNB5brims Avatar asked Dec 22 '22 09:12

DNB5brims


2 Answers

Clearing the canvas:

canvas.clear = true; // makes the canvas clear itself on every frame
canvas.fill = somecolor; // fills the canvas with some color on every frame
// with canvas.clear = false and low-opacity fill, fancy motion blur effect

Removing the rectangle from the canvas:
rectangle.removeSelf();
or
canvas.removeChild(rectangle);
like image 137
DNB5brims Avatar answered Jan 30 '23 12:01

DNB5brims


You can try this method:

MyObj.myDiv.clearRect(0, 0, canvas.width, canvas.height);

Which effectively colours the entire canvas in the background colour.

like image 34
Vincent Ramdhanie Avatar answered Jan 30 '23 12:01

Vincent Ramdhanie