Skip to content

Commit 70d661f

Browse files
authored
adding examples in custom-shapes
1 parent 2b9c7f5 commit 70d661f

File tree

1 file changed

+176
-0
lines changed

1 file changed

+176
-0
lines changed

src/shape/custom_shapes.js

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,93 @@ function customShapes(p5, fn) {
18211821
* }
18221822
* </code>
18231823
* </div>
1824+
*
1825+
* @example
1826+
* <div>
1827+
* <code>
1828+
* let vertexA;
1829+
* let vertexB;
1830+
* let vertexC;
1831+
* let vertexD;
1832+
* let vertexE;
1833+
* let vertexF;
1834+
*
1835+
* let markerRadius;
1836+
*
1837+
* let vectorAB;
1838+
* let vectorFE;
1839+
*
1840+
* let endOfTangentB;
1841+
* let endOfTangentE;
1842+
*
1843+
* function setup() {
1844+
* createCanvas(100, 100);
1845+
*
1846+
* // Initialize variables
1847+
* // Adjusting vertices A and F affects the slopes at B and E
1848+
*
1849+
* vertexA = createVector(35, 85);
1850+
* vertexB = createVector(25, 70);
1851+
* vertexC = createVector(30, 30);
1852+
* vertexD = createVector(70, 30);
1853+
* vertexE = createVector(75, 70);
1854+
* vertexF = createVector(65, 85);
1855+
*
1856+
* markerRadius = 4;
1857+
*
1858+
* vectorAB = p5.Vector.sub(vertexB, vertexA);
1859+
* vectorFE = p5.Vector.sub(vertexE, vertexF);
1860+
*
1861+
* endOfTangentB = p5.Vector.add(vertexC, vectorAB);
1862+
* endOfTangentE = p5.Vector.add(vertexD, vectorFE);
1863+
*
1864+
* splineProperty(`ends`, EXCLUDE);
1865+
*
1866+
* // Draw figure
1867+
*
1868+
* background(220);
1869+
*
1870+
* noFill();
1871+
*
1872+
* beginShape();
1873+
* splineVertex(vertexA.x, vertexA.y);
1874+
* splineVertex(vertexB.x, vertexB.y);
1875+
* splineVertex(vertexC.x, vertexC.y);
1876+
* splineVertex(vertexD.x, vertexD.y);
1877+
* splineVertex(vertexE.x, vertexE.y);
1878+
* splineVertex(vertexF.x, vertexF.y);
1879+
* endShape();
1880+
*
1881+
* stroke('red');
1882+
* line(vertexA.x, vertexA.y, vertexC.x, vertexC.y);
1883+
* line(vertexB.x, vertexB.y, endOfTangentB.x, endOfTangentB.y);
1884+
*
1885+
* stroke('blue');
1886+
* line(vertexD.x, vertexD.y, vertexF.x, vertexF.y);
1887+
* line(vertexE.x, vertexE.y, endOfTangentE.x, endOfTangentE.y);
1888+
*
1889+
* fill('white');
1890+
* stroke('black');
1891+
* circle(vertexA.x, vertexA.y, markerRadius);
1892+
* circle(vertexB.x, vertexB.y, markerRadius);
1893+
* circle(vertexC.x, vertexC.y, markerRadius);
1894+
* circle(vertexD.x, vertexD.y, markerRadius);
1895+
* circle(vertexE.x, vertexE.y, markerRadius);
1896+
* circle(vertexF.x, vertexF.y, markerRadius);
1897+
*
1898+
* fill('black');
1899+
* noStroke();
1900+
* text('A', vertexA.x - 15, vertexA.y + 5);
1901+
* text('B', vertexB.x - 15, vertexB.y + 5);
1902+
* text('C', vertexC.x - 5, vertexC.y - 5);
1903+
* text('D', vertexD.x - 5, vertexD.y - 5);
1904+
* text('E', vertexE.x + 5, vertexE.y + 5);
1905+
* text('F', vertexF.x + 5, vertexF.y + 5);
1906+
*
1907+
* describe('On a gray background, a black spline passes through vertices A, B, C, D, E, and F, shown as white circles. A red line segment joining vertices A and C has the same slope as the red tangent segment at B. Similarly, the blue line segment joining vertices D and F has the same slope as the blue tangent at E.');
1908+
* }
1909+
* </code>
1910+
* </div>
18241911
*/
18251912

18261913
/**
@@ -2096,6 +2183,95 @@ function customShapes(p5, fn) {
20962183
* }
20972184
* </code>
20982185
* </div>
2186+
*
2187+
* @example
2188+
*
2189+
* <div>
2190+
* <code>
2191+
* let vertexA;
2192+
* let vertexB;
2193+
* let vertexC;
2194+
* let vertexD;
2195+
* let vertexE;
2196+
* let vertexF;
2197+
*
2198+
* let markerRadius;
2199+
*
2200+
* let vectorAB;
2201+
* let vectorFE;
2202+
*
2203+
* let endOfTangentB;
2204+
* let endOfTangentE;
2205+
*
2206+
* function setup() {
2207+
* createCanvas(100, 100);
2208+
*
2209+
* // Initialize variables
2210+
* // Adjusting vertices A and F affects the slopes at B and E
2211+
*
2212+
* vertexA = createVector(35, 85);
2213+
* vertexB = createVector(25, 70);
2214+
* vertexC = createVector(30, 30);
2215+
* vertexD = createVector(70, 30);
2216+
* vertexE = createVector(75, 70);
2217+
* vertexF = createVector(65, 85);
2218+
*
2219+
* markerRadius = 4;
2220+
*
2221+
* vectorAB = p5.Vector.sub(vertexB, vertexA);
2222+
* vectorFE = p5.Vector.sub(vertexE, vertexF);
2223+
*
2224+
* endOfTangentB = p5.Vector.add(vertexC, vectorAB);
2225+
* endOfTangentE = p5.Vector.add(vertexD, vectorFE);
2226+
*
2227+
* splineProperty(`ends`, EXCLUDE);
2228+
*
2229+
* // Draw figure
2230+
*
2231+
* background(220);
2232+
*
2233+
* noFill();
2234+
*
2235+
* beginShape();
2236+
* splineVertex(vertexA.x, vertexA.y);
2237+
* splineVertex(vertexB.x, vertexB.y);
2238+
* splineVertex(vertexC.x, vertexC.y);
2239+
* splineVertex(vertexD.x, vertexD.y);
2240+
* splineVertex(vertexE.x, vertexE.y);
2241+
* splineVertex(vertexF.x, vertexF.y);
2242+
* endShape();
2243+
*
2244+
* stroke('red');
2245+
* line(vertexA.x, vertexA.y, vertexC.x, vertexC.y);
2246+
* line(vertexB.x, vertexB.y, endOfTangentB.x, endOfTangentB.y);
2247+
*
2248+
* stroke('blue');
2249+
* line(vertexD.x, vertexD.y, vertexF.x, vertexF.y);
2250+
* line(vertexE.x, vertexE.y, endOfTangentE.x, endOfTangentE.y);
2251+
*
2252+
* fill('white');
2253+
* stroke('black');
2254+
* circle(vertexA.x, vertexA.y, markerRadius);
2255+
* circle(vertexB.x, vertexB.y, markerRadius);
2256+
* circle(vertexC.x, vertexC.y, markerRadius);
2257+
* circle(vertexD.x, vertexD.y, markerRadius);
2258+
* circle(vertexE.x, vertexE.y, markerRadius);
2259+
* circle(vertexF.x, vertexF.y, markerRadius);
2260+
*
2261+
* fill('black');
2262+
* noStroke();
2263+
* text('A', vertexA.x - 15, vertexA.y + 5);
2264+
* text('B', vertexB.x - 15, vertexB.y + 5);
2265+
* text('C', vertexC.x - 5, vertexC.y - 5);
2266+
* text('D', vertexD.x - 5, vertexD.y - 5);
2267+
* text('E', vertexE.x + 5, vertexE.y + 5);
2268+
* text('F', vertexF.x + 5, vertexF.y + 5);
2269+
*
2270+
* describe('On a gray background, a black spline passes through vertices A, B, C, D, E, and F, shown as white circles. A red line segment joining vertices A and C has the same slope as the red tangent segment at B. Similarly, the blue line segment joining vertices D and F has the same slope as the blue tangent at E.');
2271+
* }
2272+
* </code>
2273+
* </div>
2274+
*
20992275
*/
21002276

21012277
/**

0 commit comments

Comments
 (0)