Last active
August 29, 2015 14:07
-
-
Save joselynNeon/199ab2f8a568491cf6ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Joselyn McDonald w/ help from Processing examples | |
//----arduino stuff---// | |
import processing.serial.*; | |
import cc.arduino.*; | |
Arduino arduino; | |
//hooking up the arduino - attach one outer leg to 5v; one outer leg to ground; and one to your Analog IN pins// | |
int pot1 = 2; // potentiometer 1 is attached to pin A2 | |
int readPot1; // pot 1 incoming readings | |
float freqReg1; // pot one readings to store | |
int pot2 = 1; // potentiometer 1 is attached to pin A2 | |
int readPot2; // pot 1 incoming readings | |
float ampReg2; // pot one readings to store | |
//--connecting button// | |
int but = 2; // potentiometer 1 is attached to pin A2 | |
int readBut; // pot 1 incoming readings | |
//----Sin Wave Stuff---// | |
float angle = 0; | |
float px = 0, py = 0; | |
float amplitude = 30; | |
float frequency = 0; | |
float fillGap = 2.5; | |
color c; | |
boolean half, back = false; | |
void setup() { | |
size(800, 500); | |
//---------Arduino Stuff-------// | |
println(Arduino.list()); | |
arduino = new Arduino(this, Arduino.list()[5], 57600); | |
arduino.pinMode(pot1, Arduino.INPUT); | |
arduino.pinMode(pot2, Arduino.INPUT); | |
arduino.pinMode(but, Arduino.INPUT); | |
} | |
void draw() { | |
// -----Potentiometer 1 ----//// | |
readPot1 = arduino.analogRead(pot1); | |
freqReg1 = map(readPot1, 0, 1023, .0000002, .0002); | |
//------Potentiometer 2-------///// | |
readPot2 = arduino.analogRead(pot2); | |
ampReg2 = map (readPot2, 0, 1023, 0, 800); | |
//-----button----/// | |
readBut = arduino.digitalRead(but); | |
if (readBut == Arduino.HIGH) { | |
background(0); | |
} | |
for (int i =- 75; i < height+75; i++){ | |
// Reset angle to 0, so waves stack properly | |
angle = 0; | |
// float f1 = map(mouseY, 0, 500, .002, .0000002); | |
// Increasing frequency causes more gaps | |
frequency += freqReg1; | |
println(freqReg1); | |
// frequency += .000002; | |
for (float j = 0; j < width+75; j++){ | |
py = i + sin(radians(angle)) * ampReg2; | |
angle += frequency; | |
c = color(abs(py-i)*255/amplitude, 255-abs(py-i)*255/amplitude, j*(255.0/(width+50))); | |
// Hack to fill gaps. Raise value of fillGap if you increase frequency | |
for (int filler = 0; filler < fillGap; filler++){ | |
set(int(j-filler), int(py)-filler, c); | |
set(int(j), int(py), c); | |
set(int(j+filler), int(py)+filler, c); | |
} | |
} | |
} | |
if (half == true){ | |
//background(0); | |
for (int i =+ 75; i < height+75; i++){ | |
// Reset angle to 0, so waves stack properly | |
angle = 0; | |
// Increasing frequency causes more gaps | |
frequency+=freqReg1; | |
for (float j = 0; j < width; j++){ | |
py = i + sin(radians(angle-10)) * ampReg2; | |
angle += frequency; | |
c = color(random(10, 200), 0, 100); | |
for (int filler = 0; filler < fillGap; filler++){ | |
set(int(j-filler), int(py)-filler, c); | |
set(int(j), int(py), c); | |
set(int(j+filler), int(py)+filler, c); | |
} | |
} | |
} | |
} | |
} | |
void mousePressed(){ | |
fillGap=25; | |
half = true; | |
} | |
void mouseReleased( ){ | |
fillGap=2.5; | |
half = false; | |
} | |
void keyPressed(){ | |
if(key == 'b' || key == 'B'){ | |
back = true; | |
} | |
if (key == 'a' || key == 'A'){ | |
amplitude = 300; | |
} | |
if (key == 'c' || key == 'C'){ | |
c = int(random(255)); | |
} | |
} | |
void keyReleased(){ | |
if(key == 'b' || key == 'B'){ | |
back = false; | |
} | |
if (key == 'a' || key == 'A'){ | |
amplitude = 30; | |
} | |
if (key == 'c' || key == 'C'){ | |
c = int(random(255)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment