HTML5 canvas 椭圆示例
要使用 Konva
创建椭圆形状,我们可以实例化一个 Konva.Ellipse()
对象。
有关属性和方法的完整列表,请参见 椭圆 API 参考。
- 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 ellipse = new Konva.Ellipse({ x: stage.width() / 2, y: stage.height() / 2, radiusX: 100, radiusY: 50, fill: 'yellow', stroke: 'black', strokeWidth: 4 }); layer.add(ellipse);
import { Stage, Layer, Ellipse } from 'react-konva'; const App = () => { return ( <Stage width={window.innerWidth} height={window.innerHeight}> <Layer> <Ellipse x={window.innerWidth / 2} y={window.innerHeight / 2} radiusX={100} radiusY={50} fill="yellow" stroke="black" strokeWidth={4} /> </Layer> </Stage> ); }; export default App;
<template> <v-stage :config="stageSize"> <v-layer> <v-ellipse :config="ellipseConfig" /> </v-layer> </v-stage> </template> <script setup> const stageSize = { width: window.innerWidth, height: window.innerHeight }; const ellipseConfig = { x: window.innerWidth / 2, y: window.innerHeight / 2, radiusX: 100, radiusY: 50, fill: 'yellow', stroke: 'black', strokeWidth: 4 }; </script>