HTML5 canvas Arc Tutorial
To create an arc shape with Konva
, we can instantiate a Konva.Arc()
object.
For full list of properties and methods, see the Arc API Reference.
- Vanilla
- React
- Vue
- Svelte
import Konva from 'konva'; const stage = new Konva.Stage({ container: 'container', width: window.innerWidth, height: window.innerHeight }); const layer = new Konva.Layer(); stage.add(layer); const arc = new Konva.Arc({ x: stage.width() / 2, y: stage.height() / 2, innerRadius: 40, outerRadius: 70, angle: 60, fill: 'yellow', stroke: 'black', strokeWidth: 4 }); layer.add(arc);
import { Stage, Layer, Arc } from 'react-konva'; const App = () => { return ( <Stage width={window.innerWidth} height={window.innerHeight}> <Layer> <Arc x={window.innerWidth / 2} y={window.innerHeight / 2} innerRadius={40} outerRadius={70} angle={60} fill="yellow" stroke="black" strokeWidth={4} /> </Layer> </Stage> ); }; export default App;
<template> <v-stage :config="stageSize"> <v-layer> <v-arc :config="arcConfig" /> </v-layer> </v-stage> </template> <script setup> const stageSize = { width: window.innerWidth, height: window.innerHeight }; const arcConfig = { x: window.innerWidth / 2, y: window.innerHeight / 2, innerRadius: 40, outerRadius: 70, angle: 60, fill: 'yellow', stroke: 'black', strokeWidth: 4 }; </script>
<script> import { Stage, Layer, Rect } from 'svelte-konva'; </script> <Stage config={{ width: 1000, height: 1000 }}> <Layer> <Rect config={{ x: 100, y: 100, width: 400, height: 200, fill: 'blue' }} /> </Layer> </Stage>