1. #creativePact 2011 - what am I doing?

    Last year I tinkered with SuperCollider and Processing, somewhat aimlessly before completely tailing off and failing to reach the end of September.

    This year, I’ve decided to create a live audio FX processor in SuperCollider. I figure if I have some sort of goal I might be tempted to stick with it for longer (this might not work out though, as I intend to be drunk for most of September… oh well!)

    The idea is partly inspired by a MaxMSP project I did in 2nd year which was broadly the same thing…but in Max…

  2. #creativePact Day ?? - an improvement!

    Here ya go!

    void setup(){

      size(360, 360);

    stroke(255);

    strokeWeight(5);

    smooth();

    noFill();

    }

    void draw(){

      background(0);

      int sides = mouseY/20;

       float x = 0, y = 0;

    float angle = mouseX;

      beginShape();

    for (int i=0; i<sides; i++){

      x = width/2+cos(radians(angle))*width/2.5;

      y = height/2+sin(radians(angle))*width/2.5;

      vertex(x, y);

      angle+=360/sides;

    }

    endShape(CLOSE);

    }

  3. #creativePact Day 21

    #creativePact Here is yesterday’s code but now the second analog stick is also in use. I’d like to change this to make the swarm attracted to whichever analog stick position is nearest. Maybe tomorrow.

    import procontroll.*;

    import net.java.games.input.*;

    Mover[] mover = new Mover[400];

    ControllIO controllIO;

    ControllDevice joypad;

    ControllStick stick1;

    ControllStick stick2;

    ControllButton buttonX;

    ControllButton buttonC;

    ControllButton buttonT; 

    ControllButton buttonS;

    ControllButton buttonL1;

    ControllButton buttonL2;

    ControllButton buttonL3;

    ControllButton buttonR1;

    ControllButton buttonR2;

    ControllButton buttonR3;

    ControllButton buttonSelect;

    ControllButton buttonStart;

    ControllButton buttonUp;

    ControllButton buttonDown;

    ControllButton buttonLeft;

    ControllButton buttonRight;

    void setup() {

      size(640, 480);

      smooth();

      background(0);

      controllIO = ControllIO.getInstance(this);

      joypad = controllIO.getDevice("Twin USB Joystick");

      stick1 = joypad.getStick(0);

      stick2 = joypad.getStick(1);

      buttonT = joypad.getButton(0);

      buttonC = joypad.getButton(1);

      buttonX = joypad.getButton(2);

      buttonS = joypad.getButton(3);

      for (int i = 0; i < mover.length; i++) {

        mover[i] = new Mover();

      }

    }

    void draw() {

      background(180, 100, 180);

      for (int i = 0; i < mover.length; i++) {

        mover[i].update();

        mover[i].display();

        mover[i].checkEdges();

      }

    }

    class Mover {

      PVector location;

      PVector velocity;

      PVector acceleration;

      float topspeed;

      PVector location1;

      PVector velocity1;

      PVector acceleration1;

      float topspeed1;

      float xsticka1;

      float ysticka1;

      float xsitcka2;

      float ysticka2;

      float xstickb1;

      float ystickb1;

      float xsitckb2;

      float ystickb2;

      Mover() {

        location = new PVector(random(width), random(height));

        velocity = new PVector(0, 0);

        topspeed = 5;

        location1 = new PVector(random(width), random(height));

        velocity1 = new PVector(0, 0);

        topspeed1 = 5;

      }

      void update() {

        float xsticka1 = stick2.getTotalY() + height/2;

        float ysticka1 = stick2.getTotalX() + width/2;

        float xsticka2 = constrain(xsticka1, 0, width);

        float ysticka2 = constrain(ysticka1, 0, height);

        float xstickb1 = stick1.getTotalX() + height/2;

        float ystickb1 = stick1.getTotalY() + width/2;

        float xstickb2 = constrain(xstickb1, 0, width);

        float ystickb2 = constrain(ystickb1, 0, height);

        PVector mouse = new PVector(xsticka2, ysticka2);

        PVector mouse1 = new PVector(xstickb2, ystickb2);

        PVector dir = PVector.sub(mouse, location);

        PVector dir1 = PVector.sub(mouse1, location1);

        dir.normalize();

        dir1.normalize();

        if (buttonT.pressed() == true) {

          dir.mult(0.000001);

        } 

        else if (buttonC.pressed() == true) {

          dir.mult(1);

        } 

        else if (buttonX.pressed() == true) {

          dir.mult(5);

        } 

        else if (buttonS.pressed() == true) {

          dir.mult(0.8);

        } 

        else {

          dir.mult(0.2);

        };

        if (buttonT.pressed() == true) {

          dir1.mult(0.000001);

        } 

        else if (buttonC.pressed() == true) {

          dir1.mult(1);

        } 

        else if (buttonX.pressed() == true) {

          dir1.mult(5);

        } 

        else if (buttonS.pressed() == true) {

          dir1.mult(0.8);

        } 

        else {

          dir1.mult(0.2);

        }

        acceleration = dir;

        acceleration1 = dir1;

        velocity.add(acceleration);

        velocity.limit(topspeed);

        location.add(velocity);

        velocity1.add(acceleration1);

        velocity1.limit(topspeed1);

        location1.add(velocity1);

      }

      void display() {

        stroke(location.x, location.y, location.y);

        fill(location.x, location.y, location.y);

        ellipse(location.x, location.y, 2, 2);

        stroke(location1.x, location1.y, location1.y);

        fill(location1.x, location1.y, location1.y);

        ellipse(location1.x, location1.y, 2, 2);

      }

      void checkEdges() {

        if ((location.x > width) || (location.x < 0)) {

          velocity.x = velocity.x * -1;

        } 

        if ((location.y > height) || (location.y < 0)) {

          velocity.y = velocity.y * -1;

        }

        if ((location1.x > width) || (location1.x < 0)) {

          velocity1.x = velocity1.x * -1;

        } 

        if ((location1.y > height) || (location1.y < 0)) {

          velocity1.y = velocity1.y * -1;

        }

      }

    }

  4. #creativePact Days 18-20

    #creativePact haven’t updated for a few days, but i did spend ages working on this on Saturday but only got it working today. It’s now controllable with a PS2 controller (I got a PS2 controller to USB cable off Amazon for it). The Left Analog stick replaces the functionality of the mouse position. The Triangle, Circle etc. replace the Button presses. I’ll add some more functionality soon.

    I sort of solved a problem with Scott McLaughlin’s worms http://creativepact-2010-scottmclaughlin.blogspot.com/ leaving the screen, by using the constrain() function to stop the swarms being able to leave the screen. Haven’t quite figured how to stop the PS2 controls position leaving the screen yet though…I’ll have a think.

    import procontroll.*;

    import net.java.games.input.*;

    Mover[] mover = new Mover[400];

    ControllIO controllIO;

    ControllDevice joypad;

    ControllStick stick1;

    ControllStick stick2;

    ControllButton buttonX;

    ControllButton buttonC;

    ControllButton buttonT; 

    ControllButton buttonS;

    ControllButton buttonL1;

    ControllButton buttonL2;

    ControllButton buttonL3;

    ControllButton buttonR1;

    ControllButton buttonR2;

    ControllButton buttonR3;

    ControllButton buttonSelect;

    ControllButton buttonStart;

    ControllButton buttonUp;

    ControllButton buttonDown;

    ControllButton buttonLeft;

    ControllButton buttonRight;

    void setup() {

      size(640, 480);

      smooth();

      background(0);

      controllIO = ControllIO.getInstance(this);

      joypad = controllIO.getDevice("Twin USB Joystick");

      stick1 = joypad.getStick(0);

      stick2 = joypad.getStick(1);

      buttonT = joypad.getButton(0);

      buttonC = joypad.getButton(1);

      buttonX = joypad.getButton(2);

      buttonS = joypad.getButton(3);

      for (int i = 0; i < mover.length; i++) {

        mover[i] = new Mover();

      }

    }

    void draw() {

      background(180, 100, 180);

      for (int i = 0; i < mover.length; i++) {

        mover[i].update();

        mover[i].display();

        mover[i].checkEdges();

      }

    }

    class Mover {

      PVector location;

      PVector velocity;

      PVector acceleration;

      float topspeed;

      float xstick2;

      float ystick2;

      float xsitck3;

      float ystick3;

      Mover() {

        location = new PVector(random(width), random(height));

        velocity = new PVector(0, 0);

        topspeed = 5;

      }

      void update() {

        float xstick2 = stick2.getTotalY() + height/2;

        float ystick2 = stick2.getTotalX() + width/2;

        float xstick3 = constrain(xstick2, 0, width);

        float ystick3 = constrain(ystick2, 0, height);

        PVector mouse = new PVector(xstick3, ystick3);

        PVector dir = PVector.sub(mouse, location);

        dir.normalize();

        if (buttonT.pressed() == true) {

          dir.mult(0.000001);

        } 

        else if (buttonC.pressed() == true) {

          dir.mult(1);

        } 

        else if (buttonX.pressed() == true) {

          dir.mult(5);

        } 

        else if (buttonS.pressed() == true) {

          dir.mult(0.8);

        } 

        else {

          dir.mult(0.2);

        }

        acceleration = dir;

        velocity.add(acceleration);

        velocity.limit(topspeed);

        location.add(velocity);

      }

      void display() {

        stroke(location.x, location.y, location.y);

        fill(location.x, location.y, location.y);

        ellipse(location.x, location.y, 2, 2);

      }

      void checkEdges() {

        if ((location.x > width) || (location.x < 0)) {

          velocity.x = velocity.x * -1;

        } 

        if ((location.y > height) || (location.y < 0)) {

          velocity.y = velocity.y * -1;

        }

      }

    }

  5. #creativePact Day 10

    Here is my submission for today. I just wanted to put MouseButton in where possible from previous days. It did make me wish MouseButton was MousePressed, so I don’t have to remember the difference from Processing, but now I have to use my memory. Boo!

    (

    {

    {SinOsc.ar(LFNoise0.ar(MouseButton.kr(rand(5, 10), rand(0.2, 0.4), 5), 1000), 0, 0.2)}.play

    }.dup(20)

    )

  6. #creativePact Day 7

    For today’s #creativePact I’m having a play with the phase of a wave, and how it creates Constructive and Destructive interference :

    (

    {SinOsc.ar(MouseY.kr(220, 440), 0, 0.1) }.play;

    {SinOsc.ar(MouseY.kr(220, 440), MouseX.kr(0, 2pi), 0.1) }.play;

    )

    This could also be done with four waves:

    (

    {SinOsc.ar(220, 0, 0.05) }.play;

    {SinOsc.ar(220, MouseX.kr(0, 2pi), 0.05) }.play;

    {SinOsc.ar(220, 0, 0.05) }.play;

    {SinOsc.ar(220, MouseY.kr(0, 2pi), 0.05) }.play;

    )

    But I also felt like making this rather lovely chordal note panner thing:

    (

    {SinOsc.ar(220, 0, MouseX.kr(0, 0.05)) }.play;

    {SinOsc.ar(277.2, 0, MouseX.kr(0.05, 0)) }.play;

    {SinOsc.ar(329.6, 0, MouseY.kr(0, 0.05)) }.play;

    {SinOsc.ar(440, 0, MouseY.kr(0.05, 0)) }.play;

    )

    Lovely A major. (I nearly had to type this into my Blackberry, but for the grace of the University Wireless)

  7. #creativePact Day 5

    #creativePact - It’s a lazy sunday, so here is a lazy rehash of yesterday, it now has an envelope, which has its uses.

    (

    {

    {SinOsc.ar(LFNoise0.ar(rand(0.8, 10), 1000), 0, EnvGen.kr(Env.linen(1, 8, 8, 0.02, -8))

    )}.play

    }.dup(20)

    )

  8. #creativePact Day 3

    Following on from yesterday’s Sine to Sawtooth, I decided to see what would happen if we skip out odd or even partials, as these would presumably create different types of waves. Here ya go:

    play({

    var freq, ampl, part, out;

    freq = MouseX.kr(220, 440);

    ampl = 0.1;

    part = 20; // number of partials

    out = 0.0;

    forBy (0, part, 2, { arg i; var p, a;

    p = freq * (i+1); // freq of partial

    a = ampl/(i+1); // amplitude of partial

    out = SinOsc.ar(p, 0, a, out) 

    });

    out

    })

    )

    And for completeness:

    play({

    var freq, ampl, part, out;

    freq = MouseX.kr(220, 440);

    ampl = 0.1;

    part = 20; // number of partials

    out = 0.0;

    forBy (1, part, 2, { arg i; var p, a;

    p = freq * (i+1); // freq of partial

    a = ampl/(i+1); // amplitude of partial

    out = SinOsc.ar(p, 0, a, out) 

    });

    out

    })