Presentation:
https://grassvg.mikekelly.io
Code:
https://github.com/mikekellyio/grassvg
Given 3 points, we can approximate a parabola
Divide the segments AB and BC into an arbitrary number of steps
Connect the steps with their own line segments.
The same fraction (t) that the line segment QR started at, is P.
point(a, b, c, t) {
var q = (1 - t) * a + t * b;
var r = (1 - t) * b + t * c;
var p = (1 - t) * q + t * r;
return p;
}
Connect all the points P to form a parabola
line(numSteps) {
var l = [];
for (var currentStep = 0;
currentStep <= numSteps;
currentStep++) {
var t = currentStep/numSteps;
l.push(this.point(a, b, c, t));
}
return l;
}
If we increase the number of steps, we get a higher resolution parabola
Looks kind of skinny...
var parabola =
new Parabola(a,b,c);
var line = parabola.line(20);
var svgLine =
<polyline
points={line.join(" ")}
strokeWidth="3"
stroke="green"
fill="none"
/>
Generate perpendicular lines to form ribs along the parabola
var points = [];
for (var i = 1; i < line.length; i++) {
//get perpendicular line
//to each line segment
//of the approximated parabola
var rib =
perpendicular(line[i - 1],
line[i],
length);
points.push(rib);
}
var ribs = points.map((p, i) => (
<line className="rib"
{...p}
strokeWidth="2"
stroke="#999"
key={i} />
));
Draw new outline using endpoints of the ribs, and VoilĂ !
VoilĂ * 50!
Filter Definition
Filter Definition
Transforms
{grassBlades}
{grassBlades}
{grassBlades}
{grassBlades}
{grassBlades}