Public
Edited
May 8, 2022
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const canvasWidth = 720
const canvasHeight = 540

const canvas = DOM.canvas(canvasWidth, canvasHeight)

const p = new paper.PaperScope()
paper.setup(canvas);

const background = new p.Path.Rectangle({
point: [0, 0],
size: [canvasWidth, canvasHeight],
fillColor: {
gradient: {
stops: [swatches[color][0], swatches[color][1]]
},
origin: [0, 0],
destination: [canvasWidth * 0.6, canvasHeight]
}
});

let baseSpeed = speed
let layersNumber = peakLayer
let peaks = []
for (let i = 0; i < layersNumber; i++) {
let htight = canvasHeight * (0.68 + (i * 0.064))
if (i == 0) {
peaks.push({
peak: new p.Path({
fillColor: {
gradient: {
stops: [swatches[color][1], swatches[color][1]]
},
origin: [0, htight * 0.9],
destination: [0, htight * 1.1]
},
shadowColor: swatches[color][1],
shadowBlur: layersNumber - i,
shadowOffset: new p.Point(-1, -1),
}),
options:{
height: htight,
speed: baseSpeed * 0.2,
}
})

continue
}

peaks.push({
peak: new p.Path({
fillColor: {
gradient: {
stops: [swatches[color][i + 1], swatches[color][i]]
},
origin: [0, htight * 0.8 + (i * 0.5)],
destination: [0, htight * 0.9 + (i * 0.5)]
},
shadowColor: swatches[color][i],
shadowBlur: layersNumber - i,
shadowOffset: new p.Point(-1, -1),
}),
options:{
height: htight,
speed: baseSpeed * (i * 0.4),
}
})
}
let tag = 1
let len = 50
for (let i = 0; i < peaks.length; i++) {
for (let j = 0; j < len; j++) {
// Closed Right
if (j == 0 ) {
peaks[i].peak.add(new p.Point(canvasWidth, canvasHeight))
continue
}

buildPeaks(p, peaks[i].peak, tag, peaks[i].options.height)
tag = -tag
}
// Closed left
peaks[i].peak.add(new p.Point(peaks[i].peak.lastSegment.point.x - (Math.random() * 80 + 20), canvasHeight))
}

const windowLayer = new p.Layer()
const obscured = new p.Path.Rectangle({
point: [0, 0],
size: [canvasWidth, canvasHeight],
strokeColor: {
gradient: {
stops: ['#37494c', swatches[color][9]]
},
origin: [0, 0],
destination: [canvasWidth, canvasHeight * 0.7]
},
strokeWidth: 200,
})

const window = new p.Path.Rectangle({
point: [100, 100],
size: [canvasWidth - 205, canvasHeight - 200],
// strokeColor: '#456268',
strokeColor: {
gradient: {
stops: [swatches[color][7], '#37494c']
},
origin: [0, 0],
destination: [canvasWidth * 0.5, canvasHeight]
},
strokeWidth: 10,
shadowColor: '#000000',
shadowBlur: 4,
shadowOffset: new p.Point(2, 2)
})
paper.view.onFrame = event => {
for (let i = 0; i < peaks.length; i++) {
if (peaks[i].peak.segments[1].point.x > canvasWidth && peaks[i].peak.segments[2].point.x > canvasWidth) {
peaks[i].peak.removeSegment(1)
peaks[i].peak.removeSegment(len - 1)

buildPeaks(p, peaks[i].peak, tag, peaks[i].options.height)

// Closed left
peaks[i].peak.add(new p.Point(peaks[i].peak.lastSegment.point.x - (Math.random() * 80 + 20), canvasHeight))
tag = -tag
}
for (let j = 0; j < peaks[i].peak.segments.length; j++) {
peaks[i].peak.segments[j].point.x += peaks[i].options.speed
}

peaks[i].peak.smooth({ type: 'catmull-rom', factor: smoothFactor })
}
}

return canvas
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more