HTML5 canvas Star Tutorial
To create a star with Konva
, you can use the Konva.Star()
object.
For full list of properties and methods, see the Star API Reference.
- Vanilla
- React
- Vue
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 star = new Konva.Star({ x: stage.width() / 2, y: stage.height() / 2, numPoints: 5, innerRadius: 30, outerRadius: 70, fill: 'yellow', stroke: 'black', strokeWidth: 4 }); layer.add(star);
import { Stage, Layer, Star } from 'react-konva'; const App = () => { return ( <Stage width={window.innerWidth} height={window.innerHeight}> <Layer> <Star x={window.innerWidth / 2} y={window.innerHeight / 2} numPoints={5} innerRadius={30} outerRadius={70} fill="yellow" stroke="black" strokeWidth={4} /> </Layer> </Stage> ); }; export default App;
<template> <v-stage :config="stageSize"> <v-layer> <v-star :config="starConfig" /> </v-layer> </v-stage> </template> <script setup> const stageSize = { width: window.innerWidth, height: window.innerHeight }; const starConfig = { x: window.innerWidth / 2, y: window.innerHeight / 2, numPoints: 5, innerRadius: 30, outerRadius: 70, fill: 'yellow', stroke: 'black', strokeWidth: 4 }; </script>