View on GitHub

idmd

Bush School Interactive Digital Media Design Course

Bush School IDMD Spring Semester 2021

Code Exercises for Week 5 6 & 7

Write code to produce the following results from the extended exercises. Submit these into Github as your Week 5 6 & 7 assignments. These are due March 12th.

let cols = 30;
let rows = 10;
let canWid = 480;
let canHgt = 210;
let count = 0;
function setup() {
   createCanvas(canWid, canHgt);
   background(200);
   let xoff = canWid/(cols + 1);
   let yoff = canHgt/(rows +1);
   for (let i = 0; i < cols; i++) {
      let x1 = xoff * (i+1);
      let y1 = 0;
      let x2 = x1 + x1/2;
      let y2 = height*0.6;
      line(x1, y1, x2, y2);
      //Can you draw another line from the tip 
      // of the first line to show a kink??
      // Write Code here
   }
}
// col wise reversed text display
let cols = 10; // number of cols not pixels
let rows = 7; // number of rows
let count = 0;
let dir = 1;

function setup() {
   createCanvas(200, 100);
   background('pink');
   strokeWeight(5);
   textAlign(CENTER, CENTER);
   let xoff = width / (cols + 1);
   let yoff = height / (rows + 1);
   for (let c = 0; c < cols; c++) { // cols
      let x = xoff * (c + 1);
      if (dir == 1) {
         for (let r = 0; r < rows; r++) { // rows
         let y = yoff * (r + 1);
         count++;
         text('' + count, x, y);
         }
      } else {
         for (let r = 0; r < rows; r++) { // rows
         let y = yoff * (r + 1);
         count++;
         text('' + count, x, y);
         }
      }
   }
   dir *= -1;
}
let cols = 50;
let rows = 10;
let canWid = 480;
let canHgt = 210;
let ai = 0;
let x1 = [], x2 = [], x3 = [];
let y1 = [], y2 = [], y3 = [];

function setup() {
   createCanvas(canWid, canHgt);
   background(200);
   let xoff = canWid / (cols + 1);
   let yoff = canHgt / (rows + 1);
   for (let i = 0; i < cols; i++) {
      x1.push(xoff * (i + 1));
      y1.push(0);
      x2.push(x1[i] + x1[i] / 2);
      y2.push(height * 0.6);
      x3.push(x2[i] * 2 / 3);
      y3.push(height);
   }
   frameRate(5);
}

function draw() {
   line(x1[ai], y1[ai], x2[ai], y2[ai]);
   //Can you draw another line from the tip 
   // of the first line to show a kink??
   line(x2[ai], y2[ai], x3[ai], y3[ai]);
   ai++;
   if (ai >= cols) {
      textSize(30);
      fill('red');
      text("finished " + ai + " lines!", 
         width / 2, height / 2);
      noLoop();
   }
}

Consider adding some or all these new techniques to your Data Viz or Creative Animation projects.