私はFabric.jsを使用していますが、私は、六角形を描くために、次のコードを持っている:Fabric.js - 正八角形を描く
makeObject(originPoint, newPoint, canvasObject, properties) {
let width = Math.abs(newPoint.x - originPoint.x);
let height = 0;
if(this.shouldKeepProportion){
height=width;
}else{
height=Math.abs(newPoint.y - originPoint.y);
}
width = (this.minWidth!=null && width<this.minWidth ? this.minWidth: width);
height = (this.minHeight!=null && height<this.minHeight ? this.minHeight : height);
let sweep=Math.PI*2/6;
let points=[];
//generate points for 6 angles
for(let i=0;i<6;i++){
let x=width*Math.cos(i*sweep);
let y=height*Math.sin(i*sweep);
points.push({x:x/2,y:y/1.75});
}
properties = {
objectType: 'octagon',
left: originPoint.x,
top: originPoint.y,
originX: 'left',
originY: 'top',
fill: 'rgba(0, 0, 0, 1.0)',
width: width,
height: height,
originX: originPoint.x > newPoint.x ? 'right' : 'left',
originY: originPoint.y > newPoint.y ? 'bottom' : 'top',
flipX: originPoint.x > newPoint.x,
stroke: 'rgba(0, 0, 0, 1.0)',
strokeWidth: 1,
strokeLineJoin: 'round',
...properties
};
return new fabric.fabric.Polygon(points, properties);
}
私が取得したいどのような六角形と同じ正八角形、です。私はコーナー/アングルの数を変更しようとすると、私は八角形の次の型取得しています:私は実際に必要なもの
ご注意:私はそれを回転させたりする必要はありません私はそれを絵のように描く必要があります。
ありがとうございました!
EDIT:ワーキングJSFiddle:https://jsfiddle.net/42fb716n/
を共有してください。 – InferOn
https://jsfiddle.net/42fb716n/ここにご記入ください。ありがとうございました –