Vardaan Shah

Music 256 Homepage

Programming Demo

Description

This is just a quick little animation with a fun chord. I tried to make the chord change but it was really not behaving, so the chord remains forever.

Screenshots

Screenshot 1 of ChucK program.

Screenshot 2 of ChucK program.

ChucK File

Event edit_done;
Event using_done;

fun void perform_rect(float x, float y) {
    
    GCube cb_bright;
    cb_bright.alpha(0);
    Color.WHITE;
    cb_bright.color(Color.WHITE);
    cb_bright.pos(x,y);
    cb_bright.sca(2);
    
    // make new cube
    GCube cb;
    cb.alpha(0);
    Color.random() => vec3 cb_color;
    cb.color(cb_color);
    cb.pos(x,y);
    cb.sca(2);
    
    cb --> GG.scene();
    cb_bright --> GG.scene();
    
    // have cube go up in brightness
    0 => float t;
    0 => float f_t;
    
    while (t <= 1) {
        t - 1 => f_t;
        f_t*f_t*f_t*f_t => f_t;
        cb_bright.alpha(1-f_t);
        0.3 + t => t;
        (1.0/60.0)::second => now;
    }
    
    0 => t;
    0 => f_t;
    
    while (t <= 1) {
        t - 1 => f_t;
        f_t*f_t*f_t*f_t => f_t;
        cb.alpha(1-f_t);
        cb_bright.alpha(f_t * f_t);
        0.05 + t => t;
        (1.0/60.0)::second => now;
    }
    0 => t;
    0 => f_t;
    
    
    // cube goes down in brightness
    while (t <= 1) {
        t * t * t => f_t;
        //1 - f_t => f_t;
        //cb.color(cb_color * f_t);
        cb.alpha(1-f_t);
        0.03 + t => t;
        (1.0/60.0)::second => now;
    }
    
    // cube is removed from scene
    cb --< GG.scene();
    
}

0 => int changing;

3 => int octs;

[48,52,54,55,59] @=> int notes[];
notes.size() => int arr_size;

for (0 => int i; i < arr_size; i++) {
    for (1 => int j; j <= octs; j++) {
        notes << notes[i] + 12 * j;
    }
}

notes.sort();

notes[0] => float low_note;
notes[-1] => float high_note;
notes.size() => int how_many;

fun void make_rects() {
    
    new BlitSaw() @=> BlitSaw saw;

    0 => float rand_x;
    0 => float rand_y;
    6 => float extent;
    extent/2 => float y_xt;
    extent/2 * 1.4 => float x_xt;
    
    notes[0] => float new_freq;
    saw.freq(new_freq);
    
    new Gain() @=> Gain g;
    new GVerb() @=> GVerb verb;
    new ABSaturator() @=> ABSaturator sat;
    new Echo() @=> Echo d;
    new Gain() @=> Gain d_g;
    
    saw.gain(0.1);
    
    verb.damping(0.4);
    verb.bandwidth(0.3);
    verb.dry(0.8);
    
    sat.dcOffset(0.2);
    sat.drive(3);
    
    d_g.gain(0.1);
    d.delay(400::ms);
    d.mix(0.2);
    d => d_g;
    d_g => d;
    
    g.gain(0.3);
    saw => d => verb => sat => g => dac;
    
    0 => int k;
    
    int internal_notes[0];
    
    for (0 => int l; l < notes.size()-1; l++) {
        internal_notes << notes[l];
    }
    
    while (true) {        
        Math.map2(internal_notes[k],low_note,high_note,-1 * y_xt, y_xt) => rand_y;
        Math.mtof(internal_notes[k]) => new_freq;
        (Math.randomf() * extent - extent/2) * 1.4 => rand_x;
        Math.random2f(-1.0,1.0) * 0.3 + rand_y => rand_y;
        spork ~ perform_rect(rand_x,rand_y);
        saw.freq(new_freq);
        (k + 1) % (how_many-1) => k;
        using_done.broadcast();
        (Math.randomf() * 0.12 + 0.003)::second => now;
    }
    
}

GG.camera().orthographic();
spork ~ make_rects();

while (true) {
    GG.nextFrame() => now;
}

List of MUSIC 256A Pages

  • Reading Response 1
  • Design Etude 1
  • Programming Demo