xxxxxxxxxx
97
let Engine = Matter.Engine,
Runner = Matter.Runner,
Bodies = Matter.Bodies,
Composite = Matter.Composite;
let engine = Engine.create();
let runner = Runner.create();
Runner.run(runner, engine);
let modules = [];
const palette = ["#B4CF66", "#FFC300", "#FF5A33", "#007BFF"];
function setup() {
createCanvas(windowWidth *.9, windowHeight *.9);
rectMode(CENTER);
// 실루엣 그리기
background(255);
textAlign(CENTER,CENTER);
textSize(200);
textStyle(BOLD);
text("WALL",width/2,height*0.7);
// 크기 정하기
let gap = 10;
// 세로 배치
for(let y=0; y<height; y=y+gap * 2){
// 가로 배치
for(let x=0; x<width; x=x+gap * 2){
let c = get(x,y);
let b = brightness(c);
// 검은색인 경우
if(b==0){
// 배열에 좌표 담기
modules.push(new Module(
createVector(x,y),
createVector(gap,gap),
true
));
}
}
}
modules.push(new Module( //floor
createVector(width/2,height),
createVector(width,10),
true
));
}
function draw() {
if(mouseIsPressed){
modules.push(new Module(
createVector(mouseX,mouseY),
createVector(20, 20)
));
}
background(0);
for(let i=0; i<modules.length; i++){
let m = modules[i];
m.display();
}
}
class Module{
constructor(pos,size,isStatic){
this.size = size;
this.body = Bodies.rectangle(
pos.x,pos.y,
size.x,size.y,
{ isStatic: isStatic }
);
Composite.add(engine.world, this.body);
this.color = random(palette);
}
display(){
let m = new p5.Vector(mouseX, mouseY);
let pos = this.body.position;
let d = m.dist(pos);
if (d < this.
let angle = this.body.angle;
push();
translate(pos.x,pos.y);
rotate(angle);
noStroke();
fill(this.color);
rect(0,0,this.size.x,this.size.y);
pop();
}
}