xxxxxxxxxx
133
var cam;
let centralX = 0;
let centralY = 0;
let centralZ = 0;
let R = 500;
let stepH = 10;
let stepV = 10;
let thickness = 60;
colorList = [];
let lightsOn = true;
let showAxis = true;
let takeCapture = false;
function setup(){
createCanvas(windowWidth, windowHeight, WEBGL);
easycam = new Dw.EasyCam(this._renderer, {distance:1500, center:[centralX,centralY,centralZ]});
for(let i = 0; i<=1800/stepH; i++){
let from = color('#FFD500'); //dark green
let to = color('#005BBB'); //light green
let colorValue = map(i, 0, 1800/stepH, 0.0, 1.0);
let transColor = lerpColor(from, to, colorValue);
fill(transColor); //green
//c = transColor;
c = createVector(random(255), random(255), random(255));//random
colorList.push(c);
}
}
function draw(){
background(133);
push();//overall
rotateY(radians(frameCount*1));
//push();
//rotateY(radians(frameCount*1));
//push();
rotateZ(radians(frameCount*1));
if(showAxis){
fill(255,0,0);
box(1000,10,10);
fill(0,255,0);
box(10,1000,10);
fill(0,0,255);
box(10,10,1000);
}
if(lightsOn){
directionalLight(255,255,255,1,1,-1);
directionalLight(255,255,255,-1,1,-1);
directionalLight(255,255,255,-1,1,1);
}
strokeWeight(0.5);
for(let i = 0; i<=180; i+=stepH){
noStroke();
nc = colorList[i/stepH];//random not really
//nc = colorList[i];//trans
shininess(100);
specularMaterial(nc.x, nc.y, nc.z); //random
//specularMaterial(nc); //trans
//fill(nc.x, nc.y, nc.z);
push();
rotateX(PI/2);
translate(0,0,R*cos(radians(i)));
torus(R*sin(radians(i)), thickness, 48, 16);
pop();
}
/*
for(let i = 0; i<=180; i+=stepV){
nc = colorList[i/stepH];
//shininess(100);
//specularMaterial(nc.x, nc.y, nc.z);
push();
rotateY(radians(i));
torus(R+50, thickness/5, 24, 16);
pop();
}
*/
//pop();
//pop();
pop(); //overall
}
function keyPressed(){
if(key == ' '){
//Only for random
colorList = [];
for(let i = 0; i<=1800/stepH; i++){
let from = color('#FFD500'); //dark green
let to = color('#005BBB'); //light green
let colorValue = map(i, 0, 1800/stepH, 0.0, 1.0);
let transColor = lerpColor(from, to, colorValue);
fill(transColor); //green
//c = transColor;
c = createVector(random(255), random(255), random(255));
colorList.push(c);
}
}
if(key == 'a'){
stepH = stepH + 1;
}
if(key == 'd'){
if(stepH <= 1){
stepH = 1;
}else{
stepH = stepH - 1;
}
}
}