xxxxxxxxxx
98
let mode = 0;
let crossroad;
let crossroad2;
function setup() {
createCanvas(400, 400);
crossroad = new Crossroad(0, 0, 0);
//crossroad=new Crossroad(width,0,PI/2);//vertical
// crossroad2=new Crossroad(70,0,PI/2);
// crossroad2.yPos=height-crossroad2.w;//crossroad2=new Crossroad(0,height-70,0);
// crossroad=new Crossroad(10,40,1);
}
function draw() {
background(0, 0, 0, 20);
crossroad.display();
// crossroad2.display();
}
class Crossroad {
constructor(x, y, a) {
this.spacing = 13;
this.w = 70;
this.stroke = 5;
this.color = 255;
this.counter = 0;
// this.bars=10;
this.bars = width / this.spacing; //width devided by spacebt them
this.drawCounter = 0;
this.speed = 1; //the higher the number the slower the flow
this.xPos = x || 0;
this.yPos = y || 0;
this.ang = a || 0;
}
display() {
strokeWeight(this.stroke);
stroke(this.color);
if (frameCount % this.speed == 0) {
this.drawCounter++;
}
if (this.drawCounter > this.bars) {
this.drawCounter = 0;
}
push();
translate(this.xPos, this.yPos);
rotate(this.ang);
line(
this.drawCounter * this.spacing,
0,
this.drawCounter * this.spacing,
this.w
);
pop();
}
displayAll() {
strokeWeight(this.stroke);
stroke(this.color);
for (let i = 0; i < this.bars; i++) {
push();
translate(this.xPos, this.yPos);
rotate(this.ang);
line(i * this.spacing, 0, i * this.spacing, this.w);
pop();
}
}
}
// function keyPressed() {
// switch (key) {
// case "a":
// case "1":
// mode = 0;
// break;
// case "s":
// case "2":
// mode = 1;
// break;
// case "d":
// case "3":
// mode = 2;
// break;
// case "f":
// case "4":
// mode = 3;
// break;
// case "g":
// case "5":
// mode = 4;
// break;
// default:
// mode = floor(random(0, 5));
// // console.log("Pressed something else: " +key)
// }
// }