-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03afbf2
commit 8699c1b
Showing
12 changed files
with
315 additions
and
114 deletions.
There are no files selected for viewing
Binary file renamed
BIN
+11.9 KB
...964a1e325ed338ecd63a990839efa6ecdd023.idx → ...e4e256db2022cde860fee7431094e5989400b.idx
Binary file not shown.
Binary file renamed
BIN
+148 KB
...64a1e325ed338ecd63a990839efa6ecdd023.pack → ...4e256db2022cde860fee7431094e5989400b.pack
Binary file not shown.
Binary file renamed
BIN
+1.61 KB
...964a1e325ed338ecd63a990839efa6ecdd023.rev → ...e4e256db2022cde860fee7431094e5989400b.rev
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { Graphics } from "../pixi.min.mjs"; | ||
import { getContainer } from "./app.js"; | ||
|
||
function fromPoints(boxFrom) { | ||
return [boxFrom.x + boxFrom.width / 2, boxFrom.y + boxFrom.height]; | ||
} | ||
|
||
function toPoints(boxFrom, boxTo) { | ||
const fromX = boxFrom.x + boxFrom.width / 2; | ||
const fromY = boxFrom.y + boxFrom.height; | ||
const toX = boxTo.x + boxTo.width / 2; | ||
const toY = boxTo.y; | ||
|
||
let cpFromY, cpToY, cpFromX, cpToX; | ||
|
||
if (toY > fromY) { | ||
cpFromY = (toY - fromY) / 2 + fromY; | ||
cpToY = cpFromY; | ||
} else { | ||
cpFromY = (fromY - toY) / 2 + fromY; | ||
cpToY = toY - (fromY - toY) / 2; | ||
} | ||
if (toX > fromX) { | ||
cpFromX = (toX - fromX) / 4 + fromX; | ||
cpToX = (3 * (toX - fromX)) / 4 + fromX; | ||
} else { | ||
cpFromX = (3 * (fromX - toX)) / 4 + toX; | ||
cpToX = (fromX - toX) / 4 + toX; | ||
} | ||
return [cpFromX, cpFromY, cpToX, cpToY, toX, toY]; | ||
} | ||
|
||
function bezierCurve({ | ||
fromX, | ||
fromY, | ||
cpFromX, | ||
cpFromY, | ||
cpToX, | ||
cpToY, | ||
toX, | ||
toY, | ||
color, | ||
}) { | ||
const curve = new Graphics(); | ||
curve.moveTo(fromX, fromY); | ||
curve.bezierCurveTo(cpFromX, cpFromY, cpToX, cpToY, toX, toY); | ||
curve.stroke({ width: 2, color }); | ||
return curve; | ||
} | ||
|
||
export function drawBezierLink(link) { | ||
const [fromX, fromY] = fromPoints(link.from); | ||
const [cpFromX, cpFromY, cpToX, cpToY, toX, toY] = toPoints( | ||
link.from, | ||
link.to | ||
); | ||
|
||
let curve = bezierCurve({ | ||
fromX: fromX + link.xShift, | ||
fromY: fromY, | ||
cpFromX: cpFromX + link.xShift, | ||
cpFromY: cpFromY, | ||
cpToX: cpToX + link.xShift, | ||
cpToY: cpToY, | ||
toX: toX + link.xShift, | ||
toY: toY, | ||
color: link.color, | ||
}); | ||
|
||
const boxFrom = link.from.renderedBox; | ||
const boxTo = link.to.renderedBox; | ||
|
||
const container = getContainer(); | ||
boxFrom.on("pointerdown", () => { | ||
boxFrom.on("pointermove", () => { | ||
container.removeChild(curve); | ||
const [fromX, fromY] = fromPoints(boxFrom); | ||
const [cpFromX, cpFromY, cpToX, cpToY, toX, toY] = toPoints( | ||
boxFrom, | ||
boxTo | ||
); | ||
curve = bezierCurve({ | ||
fromX: fromX + link.xShift, | ||
fromY: fromY, | ||
cpFromX: cpFromX + link.xShift, | ||
cpFromY: cpFromY, | ||
cpToX: cpToX + link.xShift, | ||
cpToY: cpToY, | ||
toX: toX + link.xShift, | ||
toY: toY, | ||
color: link.color, | ||
}); | ||
container.addChild(curve); | ||
}); | ||
}); | ||
|
||
boxTo.on("pointerdown", () => { | ||
boxTo.on("pointermove", () => { | ||
container.removeChild(curve); | ||
const [fromX, fromY] = fromPoints(boxFrom); | ||
const [cpFromX, cpFromY, cpToX, cpToY, toX, toY] = toPoints( | ||
boxFrom, | ||
boxTo | ||
); | ||
curve = bezierCurve({ | ||
fromX: fromX + link.xShift, | ||
fromY: fromY, | ||
cpFromX: cpFromX + link.xShift, | ||
cpFromY: cpFromY, | ||
cpToX: cpToX + link.xShift, | ||
cpToY: cpToY, | ||
toX: toX + link.xShift, | ||
toY: toY, | ||
color: link.color, | ||
}); | ||
container.addChild(curve); | ||
}); | ||
}); | ||
|
||
container.addChild(curve); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.