xxxxxxxxxx
366
var cam;
let centralX = 0;
let centralY = -450;
let centralZ = 0;
//Tree tree;
let treeSpacing = 500;
let treeSpacingRand = 200;
//float treeSpacing = 100;
//float treeSpacingRand = 20;
//Island
let jointSize = 2;
let boxSize = 200;
let trussSize = 5;
let facadeOn = true;
let floorOn = true;
let jointOn = false;
let trussOn = true;
let boxOn = true;
let boxFaceOn = true;
let platformOn = false;
let sizing = 100;
let treetree;
let saving = false;
let xoff01 = 0.0;
/*
int thickness = 300;
int edgeNumber = 10;
int layerNumber = 30;
float randomRange = 100;
float layerHeight = 300;
ArrayList<PVector> jointList;
*/
//mic
let level = 0;
let open = 0;
let BGChange = false;
//capture
// the frame rate (frames per second)
var fps = 60;
// the canvas capturer instance
//var capturer = new CCapture({ format: 'png', framerate: fps });
//let savingFrames = 0;
//let record = false;
function setup(){
c = createCanvas(window.innerWidth, window.innerHeight, WEBGL);
//c = createCanvas(windowWidth, windowHeight, WEBGL);
cam = new Dw.EasyCam(this._renderer, {distance:2000, center:[centralX,centralY-200,centralZ]});
treeList= [];
rockList = [];
FTreeLocList = [];
FTreeColorList = [];
FTreeSizeList = [];
for(let i = -0; i< 0.5; i+=0.5){
for(let j =-0; j< 0.5; j+=0.5){
//loc = createVector(i*treeSpacing+random(-treeSpacingRand,treeSpacingRand),0,j*treeSpacing+random(-treeSpacingRand,treeSpacingRand));
var loc = createVector(i*treeSpacing,0,j*treeSpacing);
var jointList = [];
//PVector loc = new PVector(random(-3000,3000),0,random(-1500,1500));
//Tree(PVector loc, int thick, int eNumber, int lNumber, float rRange, float lHeight )
//tree = new Tree(loc, sizing,5,int(random(5,10)),50,150, jointList);
tree = new Tree(loc, sizing,5,11,50,150, jointList);//xmas
//tree = new Tree(loc, 100,5,8,50,150, jointList);
treeList.push(tree);
}
}
//floatingCube
for(let i = 0; i< 20; i+=1){
locRock = createVector(random(-750,750),0,random(-750,750));
floatingRock = new FloatingCube(locRock, random(180), random(10,20), random(500,1000), random(-100,-200), random(0.008,0.01));
rockList.push(floatingRock);
}
//fakeTress
for(let i = 0; i< 50; i+=1){
locFTree = createVector(random(-680,680),random(-100,-500),random(-680,680));
let colorFTree = random(150,255);
FTreeColor = createVector(colorFTree,random(200,255),colorFTree);
FTreeSize = random(20,80);
FTreeLocList.push(locFTree);
FTreeColorList.push(FTreeColor);
FTreeSizeList.push(FTreeSize);
}
//mic
mic = new p5.AudioIn();
mic.start();
/*
//capture
if(record){
frameRate(fps);
capturer.start();
}
*/
}
function draw(){
/*
if(BGChange == false){
background(color('#607D8B'));
}else{
background(color('#EDD81C'));
}
*/
background(170);
//background(255*abs(sin(frameCount*0.01)));
push();
//directionalLight(255,0,0,1,1,-1);
//directionalLight(255,255,255,1,1,-1);
//directionalLight(255,255,255,1,1,1);
pop();
//sun//star
push();
translate(0,-1600,0);
rotateY(-frameCount*0.05);
rotateZ(-frameCount*0.05);
rotateZ(PI+PI/10);
fill(255,255,0);
stroke(255,255,0);
//sphere(100);
star(0, 0, 30, 70, 5);
pop();
//platform & box
for(let i = -0; i< 0.5; i+=0.5){
for(let j =-0; j< 0.5; j+=0.5){
push();
translate(i*treeSpacing,100,j*treeSpacing);
fill(0,200,255,100);
//strokeWeight(2);
stroke(255);
//box(500,10,500);
cylinder(500,10);
pop();
}
}
for(let i = -0; i< 0.5; i+=0.5){
for(let j =-0; j< 0.5; j+=0.5){
push();
translate(i*treeSpacing,150-1200/2,j*treeSpacing);
//fill(170,220);
noFill();
strokeWeight(2);
stroke(255);
//box(500,1200,500);
pop();
}
}
//Mic Blow
push();
let vol = mic.getLevel();
target = map(mic.getLevel(),0,1,0,3600);
level = lerp(level,target,0.5);
//if(level > 50){
//rotateY(level);
//open = open + 1;
//if(open%10 == 0){
//boxOn = !boxOn;
//BGChange = !BGChange;
//}
//}
//bouncing
push();
//translate(0, 100*sin(frameCount*0.01), 0);
//floor
push();
translate(0,50,0);
fill(170);
strokeWeight(2);
stroke(255);
//box(2000,10,2000);
pop();
for(let i=0; i<treeList.length; i++){
treeList[i].display();
//push();
//scale(1,-1,1);
//treeList[i].display();
//pop();
}
cam.rotateY(0.005);
//cam.rotateZ(0.005);
//floatingCube
for(let i = 0; i< rockList.length; i+=1){
rocky = rockList[i];
rocky.display();
}
//FTree
for(let i = 0; i< FTreeLocList.length; i+=1){
push();
translate(FTreeLocList[i].x, FTreeLocList[i].y, FTreeLocList[i].z);
strokeWeight(FTreeSizeList[i]);
stroke(FTreeColorList[i].x, FTreeColorList[i].y, FTreeColorList[i].z);
point(0,0,0);
strokeWeight(2);
line(0, 0, 0, 0, -FTreeLocList[i].y+100, 0);
push();
translate(0, -FTreeLocList[i].y+100, 0);
rotateX(PI/2);
fill(FTreeColorList[i].x, FTreeColorList[i].y, FTreeColorList[i].z);
circle(0, 0, 50);
pop();
pop()
/*
stroke(FTreeColorList[i].x, FTreeColorList[i].y, FTreeColorList[i].z);
strokeWeight(3);
line(FTreeLocList[i].x, FTreeLocList[i].y, FTreeLocList[i].z,0,0,0);
line(FTreeLocList[i].x, FTreeLocList[i].y, FTreeLocList[i].z,FTreeLocList[i].x, 0, FTreeLocList[i].z);
*/
}
if (frameCount % 150 == 0 ){
open = open + 1;
if(open%5 == 0){
boxOn = !boxOn;
//BGChange = !BGChange;
}
//if (vol>0.05){
//jointList = [];
//loc = createVector(0,0,0);
//treetree = new Tree(loc,100,5,int(random(2,8)),50,150);
treeList = [];
for(let i = -0; i< 0.5; i+=0.5){
for(let j =-0; j< 0.5; j+=0.5){
//loc = createVector(i*treeSpacing+random(-treeSpacingRand,treeSpacingRand),0,j*treeSpacing+random(-treeSpacingRand,treeSpacingRand));
var loc = createVector(i*treeSpacing,0,j*treeSpacing);
var jointList = [];
//PVector loc = new PVector(random(-3000,3000),0,random(-1500,1500));
//Tree(PVector loc, int thick, int eNumber, int lNumber, float rRange, float lHeight )
tree = new Tree(loc, sizing,5,11,50,150, jointList);//xmas
//tree = new Tree(loc, 100,5,8,50,150, jointList);
treeList.push(tree);
}
}
rockList = []
for(let i = 0; i< 20; i+=1){
locRock = createVector(random(-750,750),0,random(-750,750));
floatingRock = new FloatingCube(locRock, random(180), random(10,20), random(500,1000), random(-100,-200), random(0.008,0.01));
rockList.push(floatingRock);
}
//fakeTree
FTreeLocList = [];
FTreeColorList = [];
FTreeSizeList = [];
for(let i = 0; i< 50; i+=1){
locFTree = createVector(random(-680,680),random(-100,-500),random(-680,680));
let colorFTree = random(150,255);
FTreeColor = createVector(colorFTree,random(200,255),colorFTree);
FTreeSize = random(20,80);
FTreeLocList.push(locFTree);
FTreeColorList.push(FTreeColor);
FTreeSizeList.push(FTreeSize);
}
}
pop();
pop();
/*
if(record){
if(frameCount < savingFrames){
capturer.capture(document.getElementById('defaultCanvas0'));
}else if(frameCount == savingFrames){
capturer.stop();
capturer.save();
}
}
*/
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
cam.setViewport([0,0,windowWidth, windowHeight]);
}
function star(x, y, radius1, radius2, npoints) {
let angle = TWO_PI / npoints;
let halfAngle = angle / 2.0;
for (let a = 0; a < TWO_PI; a += angle) {
let sx = x + cos(a) * radius2;
let sy = y + sin(a) * radius2;
push();
translate(sx, sy);
strokeWeight(30);
point(0,0);
pop();
strokeWeight(20);
line(0,0,sx,sy);
}
}
function keyPressed(){
if(key == 'a'){
let fs = fullscreen();
fullscreen(!fs);
}
if(key == 'f'){
facadeOn = !facadeOn;
}
if(key == 'd'){
floorOn = !floorOn;
}
if(key == 'j'){
jointOn = !jointOn;
}
if(key == 't'){
trussOn = !trussOn;
}
if(key == 'b'){
boxOn = !boxOn;
}
if(key == 'p'){
boxFaceOn = !boxFaceOn;
}
if(key == 'r'){
record = !record;
}
}