Thursday, June 3, 2010

FIRST BREAKTHROUGH - USING 2 POTENTIOMETERS TO CONTROL SHAPE AND COLOUR VARIABLES IN PROCESSING

Below is a very simple sketch that Tapani and I wrote, using two potentiometers to control colour and shape variables in a simple Processing 1.1, beginners sketch. I cant quite remember what we used the third value for. An LED perhaps..?

Try this sketch yourself;


import processing.serial.*;
import cc.arduino.*;

Arduino arduino;
int value;
int value2;
int value3;

void setup()
{


size(600,600);
arduino = new Arduino (this, Arduino.list()[0],57600);
}

void draw(){
background(0);
value=arduino.analogRead(0);
value2=arduino.analogRead(1);
value3=arduino.analogRead(2);

value= int(map(value,0,1023,0,255));
value2= int(map(value2,0,1023,0,255));
value3= int(map(value3,0,1023,0,255));
arduino.analogWrite(9,(value+value2)/2);
//println (value);
//println ((value+value2)/2);
println(value3);
smooth();

fill (value/2,value2/3,(value+value2)/2);
ellipse (value*2/*+random(100,255)*/,value2*2,value3,value3);
ellipse (value*random(0,5),value2*random(0,5),50,50);
ellipse (value*random(0,5),value2*random(0,5),50,50);

}

We imported the potentiometer data, via arduino Serial, to the serial port, then into the Processing sketch;

import processing.serial.*;
import cc.arduino.*;


we mapped the values from the potentiometers from between 0-1023, to 0-255 and added some simple mathematical equasions to the shapes which you can play around with and expand on.
This was the first breakthrough I'd made interfacing physical programming in Arduino and digital graphics in Processing. Was very exciting (cheery, yet somehow cynical laughter in background)!!! ....

The above picture has some more shapes added into the same code. You could have lots of fun with this.

No comments:

Post a Comment