Skip to content

Instantly share code, notes, and snippets.

@p-chan
Created July 6, 2016 10:15
Show Gist options
  • Save p-chan/6385e6a90ee082c65f7f0ce7600a5fdc to your computer and use it in GitHub Desktop.
Save p-chan/6385e6a90ee082c65f7f0ce7600a5fdc to your computer and use it in GitHub Desktop.
p5-sandbox - microorganism
// Num
const pointNum = 300;
// Size
const pointSizeMax = 10;
const pointSizeMin = 5;
// Store
let pointStore = [];
var x = 0;
var y = 0;
function setup() {
// canvas
createCanvas(windowWidth, windowHeight);
// init point
for (var i = 0; i < pointNum; i++) {
const point = {
x: random(0, windowWidth),
y: random(0, windowHeight),
size: random(pointSizeMin, pointSizeMax)
}
pointStore.push(point);
}
}
function draw() {
// re-rendering
background('#27ae60');
// start
for (var i = 0; i < pointNum; i++) {
const p = pointStore[i];
ellipse(p.x, p.y, p.size, p.size);
}
// move
for (var i = 0; i < pointNum; i++) {
const moveX = random(-1, 1);
const moveY = random(-1, 1);
pointStore[i].x += moveX;
pointStore[i].y += moveY;
}
}
<script src="//cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.2/p5.js"></script>
html {
height: 100%;
width: 100%;
}
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
background-color: #000;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment