Skip to content

Instantly share code, notes, and snippets.

@Jon20111
Last active July 23, 2020 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jon20111/870dd246d1337b91ae0ed2081b1d4029 to your computer and use it in GitHub Desktop.
Save Jon20111/870dd246d1337b91ae0ed2081b1d4029 to your computer and use it in GitHub Desktop.
The sides of an svg wave box
const calculateTop = useCallback(
point => {
const xyPoint = {
x: paddingOffset + point,
y: paddingOffset - pathFunction(point)
};
return ["L", xyPoint.x, xyPoint.y].join(" ");
},
[paddingOffset, pathFunction]
);
const calculateRight = useCallback(
point => {
const xyPoint = {
x: paddingOffset + totalPoints * 0.25 + pathFunction(point),
y: paddingOffset + (point - totalPoints * 0.25)
};
return ["L", xyPoint.x, xyPoint.y].join(" ");
},
[paddingOffset, pathFunction, totalPoints]
);
const calculateBottom = useCallback(
point => {
const xyPoint = {
x: paddingOffset + totalPoints * 0.25 - (point - totalPoints / 2),
y: paddingOffset + totalPoints * 0.25 + pathFunction(point)
};
return ["L", xyPoint.x, xyPoint.y].join(" ");
},
[paddingOffset, pathFunction, totalPoints]
);
const calculateLeft = useCallback(
point => {
const xyPoint = {
x: -pathFunction(point) + paddingOffset,
y: totalPoints * 0.25 - (point - totalPoints * 0.75) + paddingOffset
};
return ["L", xyPoint.x, xyPoint.y].join(" ");
},
[paddingOffset, pathFunction, totalPoints]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment