Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var btn = document.createElement("button");
- btn.setAttribute("id", "coolrandombtn");
- var t = document.createTextNode("CLICK ME IF YOU WANT TO GET A LOT OF 'CODE'. (WARNING: DO NOT TRY THIS ON ONE OF YOUR IMPORTANT SKETCHES!!");
- btn.appendChild(t);
- document.body.appendChild(btn);
- var finished = document.createElement("button");
- finished.setAttribute("id", "coolrandombtn-finished");
- var t2 = document.createTextNode("Click me to finish writing random code.");
- finished.appendChild(t2);
- document.body.appendChild(finished);
- var editorelement = document.getElementsByClassName("code-input ace_editor ace-chrome")[0];
- var editor = ace.edit(editorelement);
- var text = "function draw() { \n";
- var codepossible = {};
- codepossible.shapes = [
- "ellipse","rect"
- ];
- var myInterval;
- var stopped = true;
- finished.addEventListener("click", function(){
- text += "}\n";
- editor.setValue(text);
- });
- btn.addEventListener("click", function(){
- if(stopped){
- myInterval = setInterval(function(){
- var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- for(var d = 0; d < 1; d++){
- for (var i = 0; i < Math.floor(1); i++)
- text += "fill(" + Math.floor(Math.random()*255) + ", " + Math.floor(Math.random()*255) + ", " + Math.floor(Math.random()*255) + ", " + Math.floor(Math.random()*255) + ");\n";
- text += codepossible.shapes[Math.floor(Math.random()*codepossible.shapes.length)] + "(" + Math.floor(Math.random()*900) + ", " + Math.floor(Math.random()*950) + ", " + Math.floor(Math.random()*950) + ", " + Math.floor(Math.random()*900) + ");\n";
- editor.setValue(text);
- }
- }, 1500);
- stopped = false;
- } else {
- stopped = true;
- clearInterval(myInterval);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement