Rainbow stars

Rainbow star way after the pointer.

by schrodingers

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/processing.js/1.4.15/processing.js"></script>
<canvas></canvas>

CSS

body {
    overflow: hidden;
    margin: 0;
    padding: 0;
}
</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

int num = 66;
int[] mx = new int[num];
int[] my = new int[num];
int index = 0;
//  fill(210, 70, 70, 90);

void setup() {
    size(600, 600);
    smooth();
    noStroke();
    fill(255, 200);
}

void draw() {
    background(0);
    colorMode(HSB, 360, 100, 100, 100);
    mx[index] = mouseX;
    my[index] = mouseY;
    index = (index + 1) % num;
/*    if (index == mx.length) {
        mx = expand(mx);
    }
    */
    for (int i = 0; i < num; i++) {
       // float size = (num - i) / 50;
        fill(5 * i, 90, 70, 70);
        pushMatrix();
        translate(mx[i], my[i]);
 //       scale(size);

        star();
        popMatrix();
    }
}


PShape star() {
    int pointsNum = 5;
    int vertNum = pointsNum * 2;
    float thetaRot = TWO_PI / vertNum;
    float theta;
    float tempRad;
    float x;
    float y;
    float innerRad = 15;
    float outerRad = 10;
    beginShape();

    for (int i = 0; i < pointsNum; i++) {
        for (int j = 0; j < 2; j++) {
            tempRad = innerRad;
            if (j % 2 == 0) {
                tempRad = outerRad;
            }
            x = cos(theta) * tempRad;
            y = sin(theta) * tempRad;
            vertex(x, y);
            theta += thetaRot;
        }
    }
    endShape(CLOSE);
    return star;
}