// Note: current max# of supported lights is: // 12 point lights // 12 directional lights // lightbulb class that renders pointlight with a colored sphere to visualize its position class LightBulb extends GGen { // GGen network. a light + sphere at the same position FlatMaterial mat; GPointLight light --> GPlane bulb --> this; FileTexture cat; fun void setPath(string path) { cat.path(path); } cat.path("cat1.png"); cat.wrap(1, 1); mat.diffuseMap(cat); // set up sphere to be a flat color bulb.mat(mat); @(1, 1, 1) => bulb.scale; vec3 lightCol; Math.random2f(0.5, 1.5) => float pulseRate; // randomize pulse rate for fading in/out fun void color(float r, float g, float b) { @(r, g, b) => lightCol; // save the set color mat.color(@(r, g, b)); // set material color light.diffuse(@(r, g, b)); // set light diffuse color } // this is called automatically every frame but ChuGL // IF the GGen or one of its parents is connected to GG.scene() fun void update(float dt) { bulb.rotY(Math.random2(0, 10) * dt); } } // camera angle GG.camera() @=> GCamera @ cam; @(0, 10, 10) => cam.position; cam.lookAt(@(0, 0, 0)); // scene setup GG.scene() @=> GScene @ scene; scene.backgroundColor(@(1, 1, 1)); // black background scene.light().intensity(0); // disable default directional light // instantiate lightbulbs GGen lightGroup --> scene; LightBulb redLight--> lightGroup; LightBulb greenLight--> lightGroup; LightBulb blueLight--> lightGroup; LightBulb whiteLight--> lightGroup; 1 => lightGroup.posY; // lift all lights 1 unit off the ground // set light colors 2 => redLight.posX; redLight.setPath("cat1.png"); redLight.color(1, 1, 1); 2 => greenLight.posZ; greenLight.setPath("cat2.png"); greenLight.color(1, 1, 1); -2 => blueLight.posX; blueLight.setPath("cat3.png"); blueLight.color(1, 1, 1); -2 => whiteLight.posZ; whiteLight.setPath("cat4.png"); whiteLight.color(1, 1, 1); SndBuf meow => dac; //sound buffer ugen lets us playback from file system me.dir() + "meow.wav" => string filename; filename => meow.read; fun void audio() { Math.randomf() => float dir; if (dir > .98) { meow.samples() / 10 => meow.pos; 0.2::second => now; } } // Gameloop ================================== while (true) { // rotate lights spork ~ audio(); GG.dt() => lightGroup.rotY; // nextFrame GG.nextFrame() => now; }