Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                <canvas id="canvas" width="640" height="1080" class="canvas" aria-label="나의 점수"></canvas>
              
            
!

CSS

              
                html, body {
  margin: 0;
  font-size: 20px;
}

.canvas {
  width: 320px;
  height: 540px;
}
              
            
!

JS

              
                const canvasWidth = 640;
const canvasHeight = 1080;
const gaugeHeight = 900;
const topPadding = canvasHeight - gaugeHeight;
const percentage = 75; // Example percentage
const duration = 1000; // Example duration
const delay = 1000; // Example delay

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

function drawBackground() {
  const gradient = context.createLinearGradient(0, 0, 0, canvasHeight);
  gradient.addColorStop(0, "#B2D9FF");
  gradient.addColorStop(1, "#E5F6FF");
  context.fillStyle = gradient;
  context.fillRect(0, 0, canvasWidth, canvasHeight);
}

function drawChartBg() {
  context.fillStyle = "#ECF3F6";
  context.beginPath();
  context.moveTo(0, canvasHeight);
  context.lineTo(0, topPadding);
  context.lineTo(canvasWidth, canvasHeight);
  context.closePath();
  context.fill();
}

function drawChartBgShadow() {
  context.fillStyle = "rgba(0, 0, 0, 0.1)";
  context.beginPath();
  context.moveTo(0, canvasHeight);
  context.lineTo(0, topPadding);
  context.lineTo(400, canvasHeight);
  context.closePath();
  context.fill();
}

function drawChart() {
  const startTime = performance.now();
  const targetRatio = percentage / 100;

  function animate(time) {
    const elapsedTime = time - startTime;
    const progress = Math.min(elapsedTime / duration, 1);
    const currentRatio = 1 - progress * targetRatio;

    const gradient = context.createLinearGradient(0, 0, 0, canvasHeight);
    gradient.addColorStop(0, "#3377EE");
    gradient.addColorStop(1, "#22CCCC");

    context.fillStyle = gradient;
    context.beginPath();
    context.moveTo(0, canvasHeight);
    context.lineTo(0, gaugeHeight * currentRatio + topPadding);
    context.lineTo(
      canvasWidth * currentRatio,
      gaugeHeight * currentRatio + topPadding
    );
    context.lineTo(canvasWidth, canvasHeight);
    context.closePath();
    context.fill();

    context.fillStyle = "rgba(0, 0, 0, 0.1)";
    context.beginPath();
    context.moveTo(0, canvasHeight);
    context.lineTo(0, gaugeHeight * currentRatio + topPadding);
    context.lineTo(400 * currentRatio, gaugeHeight * currentRatio + topPadding);
    context.lineTo(400, canvasHeight);
    context.closePath();
    context.fill();

    if (progress < 1) {
      requestAnimationFrame(animate);
    } else {
      drawTooltip();
    }
  }

  requestAnimationFrame(animate);
}

function drawTooltip() {
  const currentRatio = 1 - percentage / 100;
  const currentTop = gaugeHeight * currentRatio + topPadding;
  const radius = 160;
  const top = Math.max(radius, Math.min(currentTop, canvasHeight - radius));
  const left = canvasWidth - radius - 8;

  context.fillStyle = "#FF5500";
  context.beginPath();
  context.arc(left, top, radius, 0, 2 * Math.PI);
  context.fill();
  context.closePath();

  context.beginPath();
  context.strokeStyle = "#FF5500";
  context.lineWidth = 1;
  context.moveTo(left - radius / 2, currentTop);
  context.lineTo(canvasWidth * currentRatio, currentTop);
  context.stroke();
  context.closePath();

  context.beginPath();
  context.arc(left, top, radius + 1, 0, 2 * Math.PI);
  context.strokeStyle = "#FFFFFF";
  context.lineWidth = 1;
  context.stroke();
  context.closePath();

  const centerY = top + radius / 2;
  context.font = "500 2rem NotoSansKR";
  context.textAlign = "center";
  context.textBaseline = "middle";
  context.fillStyle = "#FFFFFF";
  context.fillText("나의 점수", left, centerY - 180);
  context.font = "700 6.4rem NotoSansKR";
  context.fillText(`${percentage}`, left, centerY - 80);
  context.font = "700 3.2rem NotoSansKR";
  context.fillText(`/ 100`, left, centerY + 20);
}

setTimeout(() => {
  drawBackground();
  drawChartBg();
  drawChartBgShadow();
  drawChart();
}, delay);

              
            
!
999px

Console