การวาดรูปทรงหลายเหลี่ยมด้วย KonvaJS

เพื่อที่จะสร้างรูปทรงหลายเหลี่ยมด้วย KonvaJS นั้น  เราจะใช้ Konva.Polygon() ครับ. สำหรับรายละเอียดวิธีการใช้แอตทริบิวต์และเมธอดสามารถดูได้จากที่นี่ครับ API Document : http://konvajs.github.io/docs/shapes/RegularPolygon.html

ตัวอย่าง แทคที่ใช้
1
2
<div id="container">
</div>
ตัวอย่าง : วาดรูปทรงหลายเหลี่ยม
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var stage = new Konva.Stage({
  container: 'container',
  width: 300,
  height: 300
});
 
var layer = new Konva.Layer();
var poly = new Konva.RegularPolygon({
  x: 100,         // แสดงที่ตำแหน่งตามแนวแกน x
  y: 150,         // แสดงที่ตำแหน่งตามแนวแกน y
  sides: 6,       // จำนวนเหลี่ยม
  radius: 70,     // ขนาดมุม
  fill: 'red',    // ใส่สีพื้น
  stroke: 'black', // กำหนดสีเส้น
  strokeWidth: 5   // กำหนดขนาดเส้น
});
 
// เพิ่ม wedge เข้าไปใน layer
layer.add(poly);
 
// เพิ่ม layer เข้าไปใน stage
stage.add(layer);

ผลลัพธ์ที่ได้คือ

About Nop

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment