xxxxxxxxxx
var pg;
var angle = 0;
var activeCamera = 0;
var canvas;
var img;
function preload(){
img = loadImage("https://marketplace.canva.com/MADFCeNIbe0/1/thumbnail_large/canva-wood-texture-MADFCeNIbe0.jpg");
}
function setup() {
frameRate(60);
smooth();
canvas = createCanvas(600,600);
pg = createGraphics(200,200,WEBGL);
pg.stroke(0);
pg.fill(255);
pg.pointLight(255,0,0,400,0,0); // Red (from the right)
pg.pointLight(0,255,0,0,400,0); // Green (gtom the bottom)
pg.pointLight(0,0,255,0,0,400); // Blue (from the front);
pg.ambientMaterial(255,255,255);
// pg.texture(img);
background(0);
textSize(16);
textAlign(CENTER);
}
function draw() {
canvas.position(windowWidth/2 - width/2, windowHeight/2 - height/2);
pg.background(0);
pg.ambientLight(20);
pg.push();
pg.rotateX(angle);
pg.rotateY(angle);
pg.rotateZ(angle);
updateModel();
pg.pop();
if(activeCamera == 0){
// Back
pg.camera(0, 0, 200, 0, 0, 0, 0, 1, 0);
image(pg,200,0,200,200);
}
if(activeCamera==1){
// Front
pg.camera(0, 0, -200, 0, 0, 0, 0, 1, 0);
image(pg,200,400,200,200);
}
if(activeCamera==2){
// Right
pg.camera(200, 0, 0, 0, 0, 0, 0, 0, 1);
image(pg,400,200,200,200);
}
if(activeCamera==3){
// Left
pg.camera(-200, 0, 0, 0, 0, 0, 0, 0, 1);
image(pg,0,200,200,200);
}
if(activeCamera++>3) {
activeCamera = 0;
angle += 0.05;
}
}
function updateModel(){
pg.box(50);
}