Processing snake array
2015-07-31 Snake array technique Закольцованный массив хех.
by schrodingers
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/processing.js/1.4.13/processing.min.js"></script>
<canvas></canvas>
CSS
</style> <script type="text/javascript"> window.addEventListener('load', function() {
var scripts=document.body.getElementsByTagName('script');
var canvases=document.body.getElementsByTagName('canvas');
new Processing(canvases[0], scripts[0].text);
}
, false);
// Here prevent javascript in body from throwing error </script> <style>
JavaScript
/*
title: Arrays "snake" technique
"Закольцованный массив"
date: 2015-07-31
*/
int num = 8; // numimum number of elements
float[] posX = new float[num];
float[] posY = new float[num];
int next = 0; // counter from the first value (next value)
color[] Spring = {
#ff6699, #ff9900, #ffcc00, #9adb1b, #00cc66, #00cccc, #00ccff, #6633cc, #ff66cc
};
void setup() {
size(800, 600);
smooth();
background(0);
noStroke();
}
void draw() {
fill(0, 0, 0, 10);
rect(0, 0, width, height);
colorMode(HSB, 360, 90, 90);
posX[next] = mouseX;
posY[next] = mouseY;
next = (next + 1) % num; /* next slot to display;
must be in array.len+1 range */
for (int i = 0; i < num; i++) {
fill(Spring[next]);
ellipse(posX[next], posY[next], 15+i, 15+i);
}
}
// if (last == first) {
// first = (last+1) % num;
// }