User:Ember314/frog.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
$('body').prepend('<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/p5.min.js" integrity="sha512-WJXVjqeINVpi5XXJ2jn0BSCfp0y80IKrYh731gLRnkAS9TKc5KNt/OfLtu+fCueqdWniouJ1ubM+VI/hbo7POQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>');
$('body').prepend("<div id='funCanvas'></div>");
$('body').prepend('<style>#funCanvas{  position: absolute; left: 0; right: 0;top: 0;bottom: 0;height: 200%;width: 100%; z-index: 1000000;pointer-events: none; overflow: auto;}</style>');
var sketchHeight,
	sketchWidth;
function setup() {
	  sketchWidth = document.getElementById("funCanvas").offsetWidth;
  sketchHeight = document.getElementById("funCanvas").offsetHeight;
    var canvas = createCanvas(sketchWidth, sketchHeight);
    canvas.parent('funCanvas');
    //background(245);
    frameRate(3000);
}

function draw() {
    //background('rgba(245,245,245,0.01)');
    if (mouseY !=null) {
        push();
        scale(cos(frameCount * (mouseX * 0.005)));
        strokeWeight(Math.floor(Math.random() * (5 - 0 + 0.1) + 0));
        if (mouseX > 500 && mouseX < 600) {
            stroke(0, 225, 0);
            beginShape(LINES);
            vertex(0, 0);
            vertex(mouseX, mouseY);
            endShape();
            fill(0, Math.floor(Math.random() * (225 - 0 + 1) + 0), 0);
            rect(mouseX, mouseY, Math.floor(Math.random() * (50 - 10 + 1) + 10), Math.floor(Math.random() * (50 - 10 + 1) + 10));
        } else if (mouseX > 800 && mouseX < 900) {
            stroke(0, 0, 225);
            beginShape(LINES);
            vertex(0, 0);
            vertex(mouseX, mouseY);
            endShape();
            fill(0, 0, Math.floor(Math.random() * (225 - 0 + 1) + 0));
            polygon(mouseX, mouseY, Math.floor(Math.random() * (30 - 5 + 1) + 5), Math.floor(Math.random() * (10 - 3 + 1) + 3));
        } else {
            stroke(225, 0, 0);
            beginShape(LINES);
            vertex(0, 0);
            vertex(mouseX, mouseY);
            endShape();
            fill(Math.floor(Math.random() * (225 - 0 + 1) + 0), 0, 0);
            circle(mouseX, mouseY, Math.floor(Math.random() * (50 - 10 + 1) + 10));
        }
        pop();
    }
}

function polygon(x, y, radius, npoints) {
    var angle = TWO_PI / npoints;
    beginShape();
    for (var a = 0; a < TWO_PI; a += angle) {
        var sx = x + cos(a) * radius;
        var sy = y + sin(a) * radius;
        vertex(sx, sy);
    }
    endShape(CLOSE);
}