Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

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


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

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.


                <canvas id="canvas"></canvas>




                const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");

canvas.width = window.innerWidth * devicePixelRatio;
canvas.height = window.innerHeight * devicePixelRatio;

const canvasW = canvas.width;
const canvasH = canvas.height;
const myNumber = 200; //推移させたい数値の最大値(絶対値)
const division = 1000; //Date.nowをそのまま使うと周期が早すぎるので、希望の数値で割る
const digit = 3; //表示したい小数点以降の桁数
const startTime = / division; //アニメーション開始時間
let elapsedTime = 0; //アニメーション開始時間からの経過時間を格納
let x = 300;//x座標の初期値を設定(移動させたい範囲の中央)
function move() {
  elapsedTime = / division - startTime; //開始時間-関数内で現在時間を引けば経過時間が得られる
  const period = Math.sin(elapsedTime).toFixed(digit) * myNumber;//-200 〜 +200の間を推移
  ctx.clearRect(0, 0, canvasW, canvasH);
  ctx.fillStyle = "blue";
  ctx.fillRect(x + period, 100, 200, 50);//