xxxxxxxxxx
let c1, c2 ;
let stars = [];
let xpos, ypos;
let up = false;
let h = 20;
function setup() {
createCanvas(1000, 800);
c1 = color(0);
c2 = color(60, 80, 200);
setGradient(c1, c2);
xpos = 50;
ypos = 80;
}
////////
function draw() {
//랜덤별
for (i = 0; i < 500; i++){
let star = {
x:random(0, 1000),
y:random(0, 700)
};
stars.push(star);
}
for (i = 0; i < 100; i++){
let x = stars[i].x;
let y = stars[i].y;
fill(255);
noStroke();
circle(x, y, random(1,3));
}
//키보드
if(keyIsPressed){
if(keyCode === SHIFT){
up = true;
}
}else{
up = false;
}
}
function keyTyped(){
if (keyCode === ENTER || keyCode === RETURN){
ypos += 80;
xpos = 50;
}
else{
let gray = 0;
let opc = 255;
if(key === ' '){
opc = 0;
}
if (keyCode >= 65 && keyCode <= 90){
gray = map(keyCode, 65, 90, 0, 255);
if(up === true){
h = 40;
}
else{
h = 20;
}
}
if(up === true && keyCode === 86){
fill(255, 0, 0);
}
else{
fill(gray, opc);
}
rect(xpos, ypos, 20, h);
xpos += 80;
}
}
//배경 그라디언트
function setGradient(c1, c2) {
for (let y = 0; y < height; y++) {
let inter = map(y, 0, height, 0, 1);
let c = lerpColor(c1, c2, inter);
stroke(c);
line(0, y, width, y);
}
}