Changes

Jump to: navigation, search

Students/Huyen truong

4,309 bytes added, 08:55, 20 March 2010
Final Project
[[Image:Untitled-2.jpg|250px|thumb|center|The actual board with the potentiometer and push button in the middle]]
[[Image:Art.jpg|250px|thumb|center|The artwork that comes out when you play it]]
 
-------
<pre>
/*******Arduino Code*******/
/**Credit and Thanks to SandGameMod http://www.youtube.com/watch?v=64iQZHlmWbI.
*
*/
int potPinx = 2; //horizontal x potentiometer, connected to pinAnalog 2
int valuex = 0; //x is also connected to ground
int potPiny = 5; //vertical y potentiometer, connected to pinAnalog 5
int valuey = 0; //y is also connected to ground
int buttonPin = 0; //push button connected to digitalPin 0
int val = 0; //push button also connected to ground
 
void setup() {
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
 
void loop() { //Where the program reads the user's input values and then draws it out
valuex = (analogRead(potPinx)); if(valuex > 0){ Serial.print(valuex); } //if the x potentiometer is bigger than 0, screen starts to draw
Serial.print(","); valuey = (analogRead(potPiny));
if(valuey > 0){ Serial.print(valuey); //if the y potentiometer is bigger than 0, screen starts to draw
}
 
Serial.print(",");
val = digitalRead(buttonPin);
if (val == HIGH) { Serial.print("0"); } //reads the push button values and then prints it out
else {
Serial.print("1");
}
Serial.print(",x");
delay(50);
}
/*******************************/
 
</pre>
<pre>
 
/*******Processing Code*******/
/**Credit and Thanks to SandGameMod http://www.youtube.com/watch?v=64iQZHlmWbI.
*
*/
import processing.serial.*;
Serial myPort;
String myString = null;
 
 
float convx; //the x and y axis variables
int conv2x;
int pconvx;
float convy;
int conv2y;
int pconvy;
float convb;
int conv2b;
 
void setup()
{
size(1084, 800); //size of screen
myPort = new Serial(this, Serial.list()[0], 9600); //port lists
myPort.clear();
myString = myPort.readStringUntil(120);
myString = null;
background(102);
smooth();
}
 
void draw() //draw class, where it uses the user input to draw on screen
{
pconvx=conv2x;
pconvy=conv2y;
myString = myPort.readStringUntil(120);
if (myString != null) { println(myString); String[] stri= split(myString, ',');; println(stri); convx=float (stri[0]); conv2x=int(convx); convy=float (stri[1]); conv2y=int(convy); convb=float (stri[2]); conv2b=int(convb); println(conv2b);
if (conv2b==1){ background(random(256),random(256),random(256)); }
}
 
variableEllipse(conv2x, conv2y, pconvx, pconvy); //enacts the variableEllipse class
variableEllipse2(conv2x, conv2y, pconvx, pconvy); //enacts the variableEllipse2 class
variableEllipse3(conv2x, conv2y, pconvx, pconvy); //enacts the variableEllipse3 class
variableEllipse4(conv2x, conv2y, pconvx, pconvy); //enacts the variableEllipse4 class
}
 
void variableEllipse(int x, int y, int px, int py) //this class will draw out first ellipse/circle
{
float speed = abs(x-px) + abs(y-py);
stroke(speed); //speed of the potentiometer
ellipse(x, y, speed, speed); //the ellipse values, which is circle. the speed determines the circle size
fill(random(256),random(256),random(256)); //fills in the color of the ellipse
}
 
void variableEllipse2(int x, int y, int px, int py) //this draws the second circle
{
float speed = abs(x-px) + abs(y-py);
stroke(speed);
ellipse(x, y, speed - 10, speed - 10); //this circle is -10 bigger than the circle in variableEllipse
fill(random(256),random(256),random(256));
}
 
void variableEllipse3(int x, int y, int px, int py) //third circle
{
float speed = abs(x-px) + abs(y-py);
stroke(speed);
ellipse(x-20, y-20, speed - 30, speed - 30); //the size is now -30 from variableEllipse, and it is mapped -20 on the x and y axis, which means it's further down and left from the original variableEllipse circle
fill(random(256),random(256),random(256));
}
 
void variableEllipse4(int x, int y, int px, int py)
{
float speed = abs(x-px) + abs(y-py);
stroke(speed);
ellipse(x+20, y+20, speed - 30, speed - 30);
fill(random(256),random(256),random(256));
}
/*******************************/
</pre>
== Midterm Project ==
30
edits

Navigation menu