MCPcopy Index your code
hub / github.com/clips/pattern / supershape

Function supershape

pattern/canvas.js:1899–1925  ·  view source on GitHub ↗
(x, y, width, height, m, n1, n2, n3, options)

Source from the content-addressed store, hash-verified

1897/*--- SUPERSHAPE -----------------------------------------------------------------------------------*/
1898
1899function supershape(x, y, width, height, m, n1, n2, n3, options) {
1900 /* Returns a BezierPath constructed using the superformula (Gielis, 2003),
1901 * which can be used to describe many complex shapes and curves that are found in nature.
1902 */
1903 var o = options || {};
1904 var pts = (o.points !== undefined)? o.points : 100;
1905 var pct = (o.percentage !== undefined)? o.percentage : 1.0;
1906 var rng = (o.range !== undefined)? o.range : 2 * Math.PI;
1907 var path = new Path();
1908 for (var i=0; i < pts; i++) {
1909 if (i <= pts * pct) {
1910 var d = geometry.superformula(m, n1, n2, n3, i * rng / pts);
1911 var dx = d[0] * width / 2 + x;
1912 var dy = d[1] * height / 2 + y;
1913 if (path.array.length == 0) {
1914 path.moveto(dx, dy);
1915 } else {
1916 path.lineto(dx, dy);
1917 }
1918 }
1919 }
1920 path.closepath();
1921 if (o.draw === undefined || o.draw == true) {
1922 path.draw(o);
1923 }
1924 return path;
1925}
1926
1927/*##################################################################################################*/
1928

Callers

nothing calls this directly

Calls 1

drawMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…