Code viewer for World: Tutorial 18.7 (clone by Jo...

// Cloned by Jon Ortiz on 24 Nov 2022 from World "Tutorial 18.7" by "Coding Train" project 
// Please leave this clone trail here.
 

// 3D model in P5 

// heavily modified from:

// https://github.com/CodingTrain/website/tree/master/Tutorials/P5JS/18_p5.js_webgl/18.07_p5.js_loadModel
// Daniel Shiffman
// http://codingtra.in
// http://patreon.com/codingtrain
// Video: https://youtu.be/FUI7HEEz9B0


var angle;           // rotate angle - changes every step
var img, train;


function preload() 
{
   img = loadImage (  "/uploads/starter/latin.jpg" );
    
//  train = loadModel('/uploads/codingtrain/train-corrected.obj');
  train = loadModel('/uploads/dannydevito/lowpoly.obj');
}


function setup() 
{
        angle = AB.randomFloatAtoB ( 0, 20 );     // random start angle in radians - note PI is not defined until setup
//      angle = 8.3;                              // good angle for train close to camera for screenshot

  createCanvas( ABWorld.fullwidth(), ABWorld.fullheight(),  WEBGL );
}


function draw() 
{
  // colors 
  // https://www.w3schools.com/colors/colors_names.asp
  background("LightBlue");

  rotateX(angle);
  rotateY(angle * 0.3);
  rotateZ(angle * 0.3);
  
  scale(2);     // make everything bigger 
 
    texture(img);       // paint box with image 
    //  fill("navy");   // paint box with color 
    box(60);
 
  normalMaterial();
  model(train);
  
      angle = angle + 0.02;           // comment out this line to freeze it, e.g. for screenshot 
}



// play some audio
// http://soundbible.com/tags-train.html
// http://soundbible.com/2177-Steam-Train-Whistle.html
// http://soundbible.com/2164-Steam-Train.html

    var audio;
    audio = new Audio ( "/uploads/codingtrain/steam-train-daniel_simon.mp3" );
    // audio = new Audio ( "/uploads/codingtrain/steam-train-whistle-daniel_simon.mp3" );
    audio.loop = true;   
    audio.play();