Created
July 6, 2016 10:15
-
-
Save p-chan/6385e6a90ee082c65f7f0ce7600a5fdc to your computer and use it in GitHub Desktop.
p5-sandbox - microorganism
This file contains hidden or 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
// 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; | |
} | |
} |
This file contains hidden or 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
<script src="//cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.2/p5.js"></script> |
This file contains hidden or 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
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