For Loop

This is an example of using for loop to generate an unconventional “10PRINT”, the famous Commodore 64 one-liner.

let w = 20;

function drawRandLine(x,y,r,g,b){
  y *= 20;
  x *= 20;
  pop();
  fill(0);
  stroke(0);
  rect(x,y,20,20);
  push();
  stroke(r,g,b);
  if (random(1) < 0.5) {
      line(x, y, x + 20, y+20);
    } else {
      line(x, y+20, x+20, y);
    }
}

function setup() {
  createCanvas(400, 400);
  background(0);
  stroke(255);


}

function draw() {
  if(!(frameCount%10)){
    let r = random(255);
    let g = random(255);
    let b = random(255);
    for(let i=0;i<25;i++){
    drawRandLine( round(random(0, 20)), round(random(0, 20)),r,g,b);
  }
  }
}

Code language: JavaScript (javascript)

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *