<script src="https://assets.codepen.io/3560077/CanvasAnimater.js"></script>
<canvas id="myCanvas"></canvas>
<script src="./script.js"></script>

// create a CanvasAnimater object that targets a canvas element with id='myCanvas'
let canvasAnimater = new CanvasAnimater('myCanvas');

// define animation settings
let settings_object = {
    width: 300,
    height: 300, 
    center_canvas: true,
    fps: 24,
    loop_animation: true,
    t_start: 0,
    t_end: 2*Math.PI,
    animation_mode: "time",
    animation_time: 60,
}

// get the '2D' rendering canvas context
let ctx = canvasAnimater.context;

// define and set a draw function with a time parameter that draws a black background and a white disk moving in a circle
canvasAnimater.draw = function (t) {
    
    let W = canvasAnimater.width;
    let H = canvasAnimater.height;
    
    // draw a black background
    ctx.fillStyle = 'black';
    ctx.fillRect(0, 0, W, H); 
  
    // define a radius for the circular path the disk follows
    let R = Math.min(W,H)/4;
  
    // draw a white disk that moves in a circle  
    ctx.beginPath();
    ctx.arc(W/2 + R*Math.sin(t), H/2 - R*Math.cos(t), R/4, 0, 2*Math.PI);
    ctx.closePath();
    ctx.fillStyle = 'white';
    ctx.fill();
  
}

// render the animation
canvasAnimater.animate(settings_object);

// print all configured settings to the console
canvasAnimater.printSettings();
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://github.com/smtsjhr/CanvasAnimater.js/blob/6ecb4d5ea3f5d36d3abcdd6c8338d9ccf42638e4/CanvasAnimater.js