-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<html> | ||
<head> | ||
<title>Flow field</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" /> | ||
<style> | ||
body { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
</style> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.js"></script> | ||
<script src="./index.js"></script> | ||
</head> | ||
<body></body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* eslint-disable no-undef */ | ||
const particles = [] | ||
const noiseScale = 0.01 | ||
const speed = 4 | ||
let bgColor | ||
|
||
function setup() { | ||
bgColor = color('#1A1B3E') | ||
bgColor.setAlpha(40) | ||
|
||
createCanvas(window.innerWidth, window.innerHeight) | ||
|
||
particles.length = 0 | ||
const numberOfParticles = Math.min(height, width) | ||
for (let i = 0; i < numberOfParticles; i++) { | ||
const particle = {} | ||
initParticle(particle) | ||
particles.push(particle) | ||
} | ||
} | ||
window.onresize = setup | ||
|
||
function draw() { | ||
background(bgColor) | ||
strokeWeight(3) | ||
stroke(230) | ||
|
||
for (const particle of particles) { | ||
drawParticle(particle) | ||
moveParticle(particle) | ||
if (isOffscreen(particle)) initParticle(particle) | ||
} | ||
} | ||
|
||
const initParticle = (particle) => { | ||
particle.position = createVector(random(width), random(height)) | ||
} | ||
|
||
const drawParticle = (particle) => { | ||
point(particle.position.x, particle.position.y) | ||
} | ||
|
||
const moveParticle = (particle) => { | ||
const time = frameCount * 0.01 | ||
const noiseValue = noise(particle.position.x * noiseScale, particle.position.y * noiseScale, time) | ||
|
||
const angle = 2 * PI * noiseValue | ||
const v = p5.Vector.fromAngle(angle).setMag(speed) | ||
particle.position.add(v) | ||
} | ||
|
||
const isOffscreen = particle => particle.position.x <= 0 || particle.position.x >= width || particle.position.y <= 0 || particle.position.y >= height |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.