feat: canvas 示例

master
LCJ-MinYa 6 days ago
parent ab12deba4c
commit a950a333a0

@ -51,9 +51,18 @@ const startDraw = function () {
if (custom) {
// === custom true () ===
// 线
const gap = 55; //
const gap = 40; //
for (let i = 0; i < 6; i++) {
// gap""
let startGap = gap;
let endGap = gap;
// i=1: 寿() -> () = gap
if (i === 1) startGap -= 15;
// i=4: () -> () = gap
if (i === 4) endGap -= 15;
// ()
const angle1 = (Math.PI / 3) * i + Math.PI / 2;
const x1 = centerX + radius * Math.cos(angle1);
@ -69,16 +78,16 @@ const startDraw = function () {
const dy = y2 - y1;
const dist = Math.sqrt(dx * dx + dy * dy);
// 2*gap
if (dist > 2 * gap) {
// gap
if (dist > startGap + endGap) {
const ux = dx / dist;
const uy = dy / dist;
//
const sx = x1 + ux * gap;
const sy = y1 + uy * gap;
const ex = x2 - ux * gap;
const ey = y2 - uy * gap;
const sx = x1 + ux * startGap;
const sy = y1 + uy * startGap;
const ex = x2 - ux * endGap;
const ey = y2 - uy * endGap;
ctx.moveTo(sx, sy);
ctx.lineTo(ex, ey);

Loading…
Cancel
Save