xxxxxxxxxx
let light; //lamp bulb color
let lampCol = ['#AF7AC5', '#DE3163', '#FF7F50', '#CCCCFF', '#40E0D0', '#DFFF00', '#9FE2BF', '#F0E68C', '#008080', '#00CED1' ];
let glowParticle = [];
let lHeight;
let rlampCol;
function setup() {
createCanvas(600, 600);
background(0);
angleMode(DEGREES);
ellipseMode(CENTER);
//rectMode(CENTER);
colorMode(HSB, 360, 100, 100,100); //colormode is hue saturation brightness hue is set to max 360
lHeight = random(100,350); // lamp height
for (i =0; i<60; i++){
glowParticle[i] = new glowP();
}
rlampCol = int(random(lampCol.length)); // getting a random integer value from the length of lampCol array
light = random(0,360);
}
function draw() {
//circle(mouseX, mouseY, 20);
background(20,50,0);
let rlight = map(mouseX, 0, width, 0, 360); //mouse position determines color/ only works when loop is on
//LAMP STICK AND BASE
push();
translate(0, 200)
//BASE
noStroke();
fill(lampCol[rlampCol]);
rect(245,lHeight, 110, 30); //middle shape
ellipse(width/2, lHeight+30, 110, 30); //bottom ellipse
fill(light, 100, 100,60);
ellipse(width/2, lHeight, 110, 30); //top ellipse
//STICK
fill(0,0,25);
rect(290,0, 20, lHeight);
ellipse(width/2, lHeight, 20, 10);
stroke(0,0,100);
strokeWeight(5);
line(width/2,0, width/2, 0.5*lHeight);
//line(250,0, 250, 0.5*lHeight);
pop();
//Particles
for (i =0; i <glowParticle.length; i++){
glowParticle[i].draw();
}
push();
translate(0,0);
//LIGHT BULB
noStroke();
fill(light, 100, 100,100);
circle(300, 200, 60);
//light rays intensity and width
//let rayWidth = random (20,100);
let rayWidth = 20 + noise (frameCount*0.01)*100; //noise = 0 and 1 and smoothes out random selection also depends on multiplier
beginShape();
fill(light, 100, 100,random(10,45));
vertex(200,200);
vertex(400,200);
vertex(400+rayWidth,200+lHeight+60); //height of rays
vertex(200-rayWidth,200+lHeight+60); //height of rays
endShape(CLOSE);
//LAMP SHADE
fill(lampCol[rlampCol]);
arc(width / 2, 200, 200, 200, 180, 0);
//background(20,50,0);
//noLoop();
pop();
}
class glowP{
constructor(){
this.size = random(2,5);
this.x = random(200,400);
this.y = random(200,lHeight +260 );
this.vx = random(-2,2); //particle within the light ray x value
this.vy = random(-2,2);
}
draw(){
//!*!*!*!*!*!*!*!*!*!*!*!*!*!*
//making the particles move
this.x = this.x + this.vx;
this.y = this.y + this.vy;
//if particles leave canvas then reappear within the canvas randomly
if(this.x<200||this.x>400||this.y<200||this.y>lHeight+260){
this.x = random(200,400);
this.y =random(200,lHeight);
}
fill(light,100,100);
noStroke();
circle(this.x, this.y, this.size); //the stars
}
}
function keyPressed(){
if ('key == s'){
save('lampost.jpg');
}
}