Tap near top of screen to drop boxes at random. Watch how they interact with each other. Press any key to save.
A fork of Matter by Richard Bourne
xxxxxxxxxx
// Fumie
var engine;
var boxes = []
//var colors = "f6bd60-f7ede2-f5cac3-84a59d-f28482".split("-").map(a=>"#"+a)
function setup() {
createCanvas(1112, 834);
//colorMode(HSB, 255);
background(0);
// let Engine = Matter.Engine
// let Bodies = Matter.Bodies
// let World = Matter.World
let {Engine,Bodies,World} = Matter
engine = Engine.create()
let boxA = Bodies.rectangle(400,200,80,80)
let boxB = Bodies.rectangle(360,50,80,80)
let ground = Bodies.rectangle(width/2,height,width,50,{isStatic: true})
// boxes.push(boxA)
boxes.push(ground)
// boxes.push(boxB)
World.add(engine.world,[boxA,ground,boxB])
Engine.run(engine)
}
function generateNewBox(){
let {Engine,Bodies,World} = Matter
// let boxA = Bodies.rectangle(mouseX,mouseY,80,80)
let boxA = Bodies.rectangle(mouseX,mouseY,80,120)
boxA.color = color(random(255), 255, 255);
boxes.push(boxA)
World.add(engine.world,boxA)
}
function mousePressed(){
generateNewBox()
}
function draw() {
// ellipse(mouseX, mouseY, 20, 20);
background(0)
for(let box of boxes){
//fill(box.color || 'white')
fill(10,40,190);
beginShape()
for(let vert of box.vertices){
vertex(vert.x,vert.y)
}
endShape()
}
}
function keyPressed(){
save('pix.jpg');
}