<section id="paths-5">
<div class="container">
<svg id="paths-5-svg" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" width="1600" height="900" viewBox="0 0 1600 900">
</svg>
</div>
</section>
<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.js@3.0/dist/svg.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.topath.js@2.0.3/dist/svg.topath.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.filter.js@3.0.8/dist/svg.filter.min.js"></script>
<script src="../../js/components/paths-5.js" type="module"></script>
<section id="paths-5">
<div class="container">
<svg id="paths-5-svg" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" width="1600" height="900" viewBox="0 0 1600 900">
</svg>
</div>
</section>
<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.js@3.0/dist/svg.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.topath.js@2.0.3/dist/svg.topath.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.filter.js@3.0.8/dist/svg.filter.min.js"></script>
<script src="{{ path '/js/components/paths-5.js' }}" type="module"></script>
/* No context defined. */
import {
createColor,
getRandomInt,
getRandomIntInclusive,
} from "./utils-v1.js";
console.log("paths-5 active");
const draw = SVG('#paths-5-svg');
const width = draw.width();
const height = draw.height();
const sqSize = Math.min(width, height);
// draw.path('M0 0 H50 A20 20 0 1 0 100 50 v25 C50 125 0 85 0 85 z')
function randomPoint(max) {
let x1 = getRandomIntInclusive(0, max);
let y1 = getRandomIntInclusive(0, max);
return [x1, y1];
}
function startPoint(x1, y1) {
let pathData = "M";
pathData += `${x1} ${y1}`;
return pathData;
}
function lineTo(x, y) {
let pathData = "L";
pathData += `${x} ${y}`;
return pathData;
}
function smoothClosedCurveTo(x, y) {
let pathData = "S";
let c1 = x - getRandomIntInclusive(200, 400);
let c2 = y + getRandomIntInclusive(100, 400);
pathData += `${c1},${c2} ${x},${y}`;
return pathData;
}
let rect = draw.rect(width, height).fill('#00abab').opacity(0.1);
let numWaves = 5;
let waveHeight = height / numWaves;
for (let waves = 0; waves < numWaves; waves++) {
let curY = waves * waveHeight;
let yLine = getRandomIntInclusive(curY, curY + waveHeight);
console.log({curY, yLine});
let x1 = 0;
let x2 = width;
let xMid = getRandomIntInclusive(width * 0.25, width * 0.75);
// Start
let stringData = startPoint(x1, yLine);
// Make a wave
stringData += smoothClosedCurveTo(x1, yLine);
stringData += smoothClosedCurveTo(xMid, yLine);
stringData += smoothClosedCurveTo(x2, yLine);
// Close it off
stringData += lineTo(x2, height);
stringData += lineTo(x1, height);
stringData += lineTo(x1, yLine);
let myPath = draw.path(stringData);
myPath.fill('#008496');
myPath.stroke({
color: '#FFF',
width: 2
});
myPath.opacity(0.15);
}
#paths-5 {
padding: 1rem;
.container {
width: 100%;
height: calc(100vh - 8rem);
display: flex;
align-items: center;
}
svg {
//border: 1px solid teal;
width: 100%;
height: auto;
}
}
No notes defined.