+ 1

Why Doesn't This Work On Playground?

<!doctype html> <html> <head> <title>Game</title> <script> window.onload = function() { window.focus(); var blob; var blobs = []; var numBlobs = 500; var bigBlobRadius = 26; var babyBlobRadius = 10; function setup() { // Create a canvas the same size as the window createCanvas(windowWidth, windowHeight); // Create a new blob... this is the main player blob blob = new Blob(width / 2, height / 2, bigBlobRadius); // Create numBlobs blobs for (var i = 0; i < numBlobs; i++) { // Create blobs at random locations within height*3 and width*3 var posX = random(random(-width, width * 4), Math.floor(random(width))); var posY = random(random(-height, height * 4), Math.floor(random(height))); // Add new blob to the array to later be show()'d blobs[i] = new Blob(posX, posY, babyBlobRadius); } } function windowResized() { // Fix the canvas size if the window is resized resizeCanvas(windowWidth, windowHeight); } function draw() { // Make a black background background(0); // Move the origin (0,0) of the window with the blob translate(width / 2 - blob.pos.x, height / 2 - blob.pos.y); // Show & update the big blob blob.show(); blob.update(); // Show all of the baby blobs & check if eaten for (var i = blobs.length - 1; i >= 0; i--) { blobs[i].show(); // Check if we're eating something if (blob.eats(blobs[i])) { blobs.splice(i, 1); // Remove the eat-ee } } } function Blob(x, y, r) { this.id = guid(); this._r = r; this.colour = randomColour(this.id); // Assign a position and radius this.pos = createVector(x, y); this.r = r; this.update = function() { // Displ

7th Oct 2017, 2:38 PM
ā®Š²Ī±Ī¹Ī¹ā€“ŠŗĪ¹Ī·gzāÆ dario
ā®Š²Ī±Ī¹Ī¹ā€“ŠŗĪ¹Ī·gzāÆ dario - avatar
4 Answers
+ 5
We can't read your mind. So, please provide the code through code playground.
7th Oct 2017, 3:01 PM
Ekansh
+ 1
Sorry, I didn't notice that. Here Is The Full Minified Code: <!doctype html><html><head><title>Game</title><script>window.onload=function(){window.focus();var blob;var blobs=[];var numBlobs=500;var bigBlobRadius=26;var babyBlobRadius=10;function setup(){createCanvas(windowWidth,windowHeight);blob=new Blob(width/2,height/2,bigBlobRadius);for(var i=0;i<numBlobs;i++){var posX=random(random(-width,width*4),Math.floor(random(width)));var posY=random(random(-height,height*4),Math.floor(random(height)));blobs[i]=new Blob(posX,posY,babyBlobRadius)}} function windowResized(){resizeCanvas(windowWidth,windowHeight)} function draw(){background(0);translate(width/2-blob.pos.x,height/2-blob.pos.y);blob.show();blob.update();for(var i=blobs.length-1;i>=0;i--){blobs[i].show();if(blob.eats(blobs[i])){blobs.splice(i,1)}}} function Blob(x,y,r){this.id=guid();this._r=r;this.colour=randomColour(this.id);this.pos=createVector(x,y);this.r=r;this.update=function(){text(this.id,Math.floor(this.pos.x),Math.floor(this.pos.y+(this.r+20)));textAlign(CENTER);textSize(14);var screenVector=createVector(width/2,height/2);var mouseVector=createVector(mouseX,mouseY);var d=p5.Vector.dist(screenVector,mouseVector);var vel=createVector(mouseX-width/2,mouseY-height/2);var magnitude=(d>this._r)?3:.75;vel.setMag(magnitude);this.pos.add(vel)} this.eats=function(other){var d=p5.Vector.dist(this.pos,other.pos);if(d<this.r+other.r){this.r+=other.r*0.1;return!0} return!1} this.show=function(){fill("#"+this.colour);ellipse(this.pos.x,this.pos.y,this.r*2,this.r*2)}} function guid(){function s4(){return Math.floor((1+Math.random())*0x10000).toString(16).substring(1)} return s4()+'-'+s4()+'-'+s4()} function randomColour(seed){var colour=Math.floor((Math.abs(Math.sin(parseInt(seed))*16777215))%16777215).toString(16);return colour}}</script><style>html,body{height:100%;margin:0}</style><body><!--BODY--></body></html>
7th Oct 2017, 3:31 PM
ā®Š²Ī±Ī¹Ī¹ā€“ŠŗĪ¹Ī·gzāÆ dario
ā®Š²Ī±Ī¹Ī¹ā€“ŠŗĪ¹Ī·gzāÆ dario - avatar
0
in html you should create canvas element give an id to ut then declare it insude script element
7th Oct 2017, 8:31 PM
Aditya Narayan Mishra
Aditya  Narayan Mishra - avatar
0
please help me.
8th Oct 2017, 6:45 PM
ā®Š²Ī±Ī¹Ī¹ā€“ŠŗĪ¹Ī·gzāÆ dario
ā®Š²Ī±Ī¹Ī¹ā€“ŠŗĪ¹Ī·gzāÆ dario - avatar