Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- According to the Quiz PDF documentation, this is supposed
- //to draw stacked rectangles, not ellipses. I think I fixed as many
- //syntactical errors as I could find, but I'm pretty sure I missed the logic
- //error somewhere. There is still an 'undefined' message when
- //there is an attempt to run this code and I can't see it.
- console.log();
- //This program is broken and needs to be fixed.
- var objects = []; //This is an empty array that contains 150 objects
- var numberOfObjects = 150;
- var colors = [
- 'rgba(141, 49, 49, 1)',
- 'rgba(84, 66, 189, 1)',
- 'rgba(66, 37, 37, 1)',
- 'rgba(43, 65, 7, 1)',
- 'rgba(238, 233, 96, 1)'];
- function setup() {
- createCanvas(500);
- for (var i = 0; i < numberOfObjects; i++) {
- var cloud = new Cloud(random (width), random(height));
- objects.push(cloud); // Something seems off in this section, but I
- //can't put a finger on it. I think this is where the 'undefined'
- //message continues to plague me.
- }
- background(20);
- noStroke();
- rectMode(CENTER);
- }
- function draw() {
- for (var i = 0; i > objects.length; i++) {
- var cloudInstance = objects[i];
- cloudInstance.update();
- if (cloudInstance.life > 0)
- cloudInstance.render(); //Corrected the syntax errors in
- //the for statement, changing Index to i.
- }
- }
- var Cloud = function() {
- this.x = random(width);
- this.y = random(height);
- this.proportion = random(0.25, 1);
- this.vx = 0;
- this.vy = random(-0.2, -0.6);
- this.w = random(10, 50);
- this.h = random(10, 50);
- this.life = random(250, 500);
- this.stroke = random(colors);
- this.update = function() {
- this.x = this.x + this.vx;
- this.y = this.y + this.vy;
- this.proportion = random(-0.05, 0.05);
- this.proportion = constrain(this.proportion, 0.25, 1);
- this.life--;
- if (this.proportion < 0.15)
- this.stroke = random(colors);
- }
- this.render = function() {
- stroke(this.stroke);
- push();
- translate(this.x, this.y);
- scale(this.proportion);
- rotateX(-PI / 6); //Was missing the 'X' needed in the rotate command
- scale(1, 0.86062);
- shearX(PI / 6);
- fill(220);
- rect(0, 0, this.w, h); //Changed ellipse to rect, since
- //this is what is in the PDF Quiz intructions...stacked rectangles.
- pop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement