Created
March 28, 2014 20:46
-
-
Save LucyMatch/9842651 to your computer and use it in GitHub Desktop.
Digital Cave Painting with New York's Tribal Drums
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
//Arduino Stuff | |
import processing.serial.*; | |
import cc.arduino.*; | |
Arduino arduino; | |
//ARDUINO ANALOG INPUTS | |
/****************Drummer One********************/ | |
int drum_one_sensor_1 = 5; | |
int drum_one_value_1 = 0; | |
int drum_one_sensor_2 = 4; | |
int drum_one_value_2 = 0; | |
/****************Drummer Two********************/ | |
int drum_two_sensor_1 = 3; | |
int drum_two_value_1 = 0; | |
int drum_two_sensor_2 = 2; | |
int drum_two_value_2 = 0; | |
/****************Drummer Three********************/ | |
int drum_three_sensor_1 = 1; | |
int drum_three_value_1 = 0; | |
int drum_three_sensor_2 = 0; | |
int drum_three_value_2 = 0; | |
//Pressure Value thresholds | |
int low = 20; | |
int medium = 50; | |
int high = 100; | |
int drum_one_hit_counter = 0; | |
int drum_one_hit_counter2 = 0; | |
int drum_two_hit_counter = 0; | |
int drum_two_hit_counter2 = 0; | |
int drum_three_hit_counter = 0; | |
int drum_three_hit_counter2 = 0; | |
int random_number; | |
//a path for each drummer | |
Path drummer_1; | |
Path drummer_2; | |
Path drummer_3; | |
int drum_counter_1 = 0; | |
int drum_counter_2 = 0; | |
int drum_counter_3 = 0; | |
//speed varibles | |
int hit_speed_timer = 2000; | |
int hit_speed_counter = 0; | |
int time=0; | |
int fast_hit = 32; | |
int medium_hit = 16; | |
int slow_hit = 8; | |
boolean direction; | |
//background | |
PImage background_img; | |
//default variables for path drawing | |
int length_h = 20; | |
int length_v = 15; | |
int bends_h = 3; | |
int bends_v = 4; | |
PVector colour; | |
Hex hex; | |
int screen_counter = 0; | |
void setup() { | |
//size(1420,840); | |
size(displayWidth, displayHeight); | |
//background | |
tint(200, 125); | |
background_img = loadImage("cracked-wall-texture1.jpg"); | |
image(background_img, 0, 0, width, height); | |
drummer_1 = new Path(); | |
drummer_2 = new Path(); | |
drummer_3 = new Path(); | |
hex = new Hex(); | |
hex.initialize(); | |
//Initiatate connection to ardy | |
println(Arduino.list()); | |
arduino = new Arduino(this, Arduino.list()[9], 57600); | |
colour = new PVector (85, 247, 235); | |
} | |
void draw() { | |
/**ALL OF MY PATH FUNCTIONS | |
.display(); | |
.move_vertical(int duration, int numer_of_bends, boolean right_movement_change,boolean linked_with_line); | |
.move_horizontal(int duration, int numer_of_bends, boolean right_movement_change,boolean linked_with_line); | |
.update_bends(); | |
.full_triangle_move(int size, PVector colour, PVector colour2); | |
.reset_movement(); | |
*/ | |
/** ALL OF THE HEX FUNCTIONS | |
.initialize(); | |
.drawCell(int x, int y, float straightProbability); | |
.fillCell(int x, int y); | |
.drawConnection(int x, int y, int s1, int s2); | |
.drawConnectionLine(int x, int y, int s1, int s2, float curvature); | |
*/ | |
int x_background = 0; | |
int y_background = 0; | |
// drum_one_value_1 = arduino.analogRead(5); | |
// drum_one_value_2 = arduino.analogRead(4); | |
// drum_two_value_1 = arduino.analogRead(3); | |
// drum_two_value_2 = arduino.analogRead(2); | |
// drum_three_value_1 = arduino.analogRead(1); | |
// drum_three_value_2 = arduino.analogRead(0); | |
direction = true; | |
playing_drums(); | |
drummer_1.display(); | |
drummer_2.display(); | |
drummer_3.display(); | |
drummer_1.move_vertical(length_v, bends_v, direction, direction); | |
drummer_2.move_horizontal(length_h, bends_h, direction, direction); | |
drummer_3.move_horizontal(length_h, bends_h, direction, direction); | |
if(drum_one_value_1 > 1 ) { | |
drum_one_hit_counter++; | |
drum_one_value_1 =0; | |
} | |
if(drum_one_value_2 > 1) { | |
drum_one_hit_counter2++; | |
drum_one_value_2 =0; | |
} | |
if(drum_two_value_1 > 1) { | |
drum_two_hit_counter++; | |
drum_two_value_1 =0; | |
} | |
if(drum_two_value_2 > 1) { | |
drum_two_hit_counter2++; | |
drum_two_value_2 =0; | |
} | |
if(drum_three_value_1 > 1 ) { | |
drum_three_hit_counter++; | |
drum_three_value_1 =0; | |
} | |
if(drum_three_value_2 > 1) { | |
drum_three_hit_counter2++; | |
drum_three_value_2 =0; | |
} | |
// println("drum_one_hit_counter = " + drum_one_hit_counter); | |
//println("drum 2 counter" + drum_two_hit_counter); | |
if(drum_one_hit_counter%20 == 0 && drum_one_hit_counter !=0) { | |
// changes the location of the hexagon | |
x_background = int(random(0, hex.sizeX)); | |
y_background = int(random(0, hex.sizeY)); | |
colour.x = int(random(0,255)); | |
colour.y = int(random(0,255)); | |
colour.z = int(random(0,255)); | |
//draws the hexagons | |
hex.fillCell(x_background, y_background, colour); | |
hex.drawCell(x_background, y_background, random(0, 1)); | |
//changes the size of the hex | |
int random_hex_size = int(random(5,80)); | |
hex.BIG_RADIUS = (random_hex_size*10); | |
//add one more to the counter so it only goes through this statement once | |
drum_one_hit_counter ++; | |
} | |
if(drum_one_hit_counter2%5 == 0 && drum_one_hit_counter2 !=0) { | |
drum_one_hit_counter2++; | |
//by triggering the second sensor in drum one it changes the opacity of the Hex's | |
int stroke_transp = int(random(10,255)); | |
hex.stroke_trans = stroke_transp; | |
int fill_transp = int(random(10,255)); | |
hex.fill_trans = fill_transp; | |
} | |
if(drum_two_hit_counter%5 == 0 && drum_two_hit_counter !=0) { | |
// drum 2 draws completely transparent hexs with a thick white stroke | |
colour.x = int(random(0,255)); | |
colour.y = int(random(0,255)); | |
colour.z = int(random(0,255)); | |
x_background = int(random(0, hex.sizeX)); | |
y_background = int(random(0,hex.sizeY)); | |
int stroke_transp = int(random(10,255)); | |
hex.stroke_trans = 255; | |
int fill_transp = int(random(10,255)); | |
hex.fill_trans = 0; | |
hex.fillCell(x_background, y_background, colour); | |
hex.drawCell(x_background, y_background, random(0, 1)); | |
drum_two_hit_counter++; | |
hex.fill_trans = fill_transp; | |
} | |
if(drum_two_hit_counter2%50 == 0 && drum_two_hit_counter2 !=0 ) { | |
// drum_two_hit_counter2++; | |
// drummer_2.reset_movement(); | |
// drummer_2.display(); | |
// | |
// length_h = int(random(10,90)); | |
// length_v = int(random(10,90)); | |
// bends_h = int(random(1,10)); | |
// bends_v = int(random(1,10)); | |
colour.x = int(random(0,255)); | |
colour.y = int(random(0,255)); | |
colour.z = int(random(0,255)); | |
x_background = int(random(0, hex.sizeX)); | |
y_background = int(random(0,hex.sizeY)); | |
int stroke_transp = int(random(10,255)); | |
hex.stroke_trans = 255; | |
int fill_transp = int(random(10,255)); | |
hex.fill_trans = 0; | |
hex.fillCell(x_background, y_background, colour); | |
hex.drawCell(x_background, y_background, random(0, 1)); | |
drum_two_hit_counter++; | |
} | |
if(drum_three_hit_counter%5 == 0 && drum_three_hit_counter !=0 ) { | |
drum_three_hit_counter++; | |
float random_width = random(5,30); | |
float random_width2 = random(5, 30); | |
hex.LINE_WIDTH = random_width; | |
hex.OUTLINE_WIDTH = random_width2; | |
} | |
if(drum_three_hit_counter2%5 == 0 && drum_three_hit_counter2 !=0 ) { | |
drum_three_hit_counter2++; | |
drummer_3.reset_movement(); | |
drummer_3.display(); | |
length_h = int(random(10,90)); | |
length_v = int(random(10,90)); | |
bends_h = int(random(1,10)); | |
bends_v = int(random(1,10)); | |
} | |
} | |
void playing_drums() { | |
drum_one_value_1 = arduino.analogRead(5); | |
drum_one_value_2 = arduino.analogRead(4); | |
drum_two_value_1 = arduino.analogRead(3); | |
drum_two_value_2 = arduino.analogRead(2); | |
drum_three_value_1 = arduino.analogRead(1); | |
drum_three_value_2 = arduino.analogRead(0); | |
println(drum_one_value_1); | |
println(drum_one_value_2); | |
println(drum_two_value_1); | |
println(drum_two_value_2); | |
println(drum_three_value_1); | |
println(drum_three_value_2); | |
if(drum_one_value_1 > 10) { | |
drum_one_value_1++; | |
} | |
if(drum_one_value_2 > 1) { | |
drum_one_value_2++; | |
} | |
if(drum_two_value_1 > 1) { | |
drum_two_value_1++; | |
} | |
if(drum_two_value_2 > 1) { | |
drum_two_value_2++; | |
} | |
if(drum_three_value_1 > 1) { | |
drum_three_value_1++; | |
} | |
if(drum_three_value_2 > 1) { | |
drum_three_value_2++; | |
} | |
} | |
//key pressed alternative to test | |
void keyPressed () { | |
if(key == 'q' || key == 'Q') { | |
drum_one_value_1++; | |
} | |
if(key == 'a' || key == 'A') { | |
drum_one_value_2++; | |
} | |
if(key == 'w' || key == 'W') { | |
drum_two_value_1++; | |
} | |
if(key == 's' || key == 'S') { | |
drum_two_value_2++; | |
} | |
if(key == 'e' || key == 'E' ) { | |
drum_three_value_1++; | |
} | |
if(key == 'd' || key == 'D' ) { | |
drum_three_value_2++; | |
} | |
} | |
boolean sketchFullScreen() { | |
return true; | |
} | |
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
/* OpenProcessing Tweak of *@*http://www.openprocessing.org/sketch/5453*@* */ | |
/* * Inspiration code from Hex Braid by Algirdas Rascius (http://mydigiverse.com).*/ | |
class Hex{ | |
float BIG_RADIUS; | |
float LINE_WIDTH; | |
float OUTLINE_WIDTH; | |
int DELTA_X_NUM; | |
float DELTA_X; | |
float DELTA_Y; | |
float SMALL_RADIUS; | |
int sizeX; | |
int sizeY; | |
int cells[][]; | |
int stroke_trans = 10; | |
int fill_trans = 30; | |
//constructor | |
Hex() { | |
BIG_RADIUS = 100; | |
LINE_WIDTH = 10.0; | |
OUTLINE_WIDTH= 10.0; | |
DELTA_X_NUM = 3; | |
DELTA_X = BIG_RADIUS * sqrt(DELTA_X_NUM); | |
DELTA_Y = BIG_RADIUS * 1.5; | |
SMALL_RADIUS = DELTA_X / 2; | |
smooth(); | |
sizeX = (int)(width / DELTA_X + 1); | |
sizeY = (int)(height / DELTA_Y + 1); | |
} | |
void initialize() { | |
for (int x=0; x<sizeX; x++) { | |
for (int y=0; y<sizeY; y++) { | |
stroke(255,100); | |
//fillCell(x, y); | |
//drawCell(x, y, 1); | |
} | |
} | |
} | |
void drawCell(int x, int y, float straightProbability) { | |
boolean[] used = new boolean[6]; | |
for (int i=0; i<3; i++) { | |
int s1 = nextEmpty(used, (int)random(0, 6)); | |
used[s1] = true; | |
int s2 = random(0, 1) <= straightProbability ? (s1+3)%6 : (int)random(0, 6); | |
s2 = nextEmpty(used, s2); | |
used[s2] = true; | |
stroke(255,stroke_trans); | |
drawConnection(x, y, s1, s2); | |
} | |
} | |
int nextEmpty(boolean[] used, int i) { | |
while (used[i]) { | |
i = (i+1) % used.length; | |
} | |
return i; | |
} | |
void fillCell(int x, int y, PVector colour_temp) { | |
float xc = (x+0.5) * DELTA_X - (y%2==1 ? DELTA_X/2 : 0); | |
float yc = (y+0.5) * DELTA_Y; | |
fill(colour_temp.x, colour_temp.y,colour_temp.z,fill_trans); | |
//stroke(255); | |
beginShape(); | |
for (int i=0; i<=6; i++ ) { | |
float a = (i+0.5)*TWO_PI/6; | |
vertex(xc + BIG_RADIUS*cos(a), yc + BIG_RADIUS*sin(a)); | |
} | |
endShape(); | |
} | |
void drawConnection(int x, int y, int s1, int s2) { | |
float curvature = random(0.1, 0.6); | |
noFill(); | |
stroke(255,stroke_trans); | |
//stroke(255,100); | |
strokeWeight(OUTLINE_WIDTH); | |
strokeCap(SQUARE); | |
drawConnectionLine(x, y, s1, s2, curvature); | |
stroke(255, stroke_trans); | |
//noStroke(); | |
strokeWeight(LINE_WIDTH); | |
strokeCap(ROUND); | |
drawConnectionLine(x, y, s1, s2, curvature); | |
} | |
void drawConnectionLine(int x, int y, int s1, int s2, float curvature) { | |
float xc = (x+0.5) * DELTA_X - (y%2==1 ? DELTA_X/2 : 0); | |
float yc = (y+0.5) * DELTA_Y; | |
float a1 = s1*TWO_PI/6; | |
float a2 = s2*TWO_PI/6; | |
bezier( | |
xc + SMALL_RADIUS*cos(a1), yc + SMALL_RADIUS*sin(a1), | |
xc + SMALL_RADIUS*cos(a1)*curvature, yc + SMALL_RADIUS*sin(a1)*curvature, | |
xc + SMALL_RADIUS*cos(a2)*curvature, yc + SMALL_RADIUS*sin(a2)*curvature, | |
xc + SMALL_RADIUS*cos(a2), yc + SMALL_RADIUS*sin(a2)); | |
} | |
} |
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
class Path { | |
int x, y; | |
int saveX, saveY; | |
int counter_v = 1; | |
int counter_h = 1; | |
int random_choice = 0; | |
//when using dual lines | |
int line_width = 30; | |
int stroke_weight = 6; | |
// to determine direction of path | |
boolean up_movement, right_movement, ok = true; | |
int increment; | |
PVector point_one, point_two, point_three; | |
int number_bends_horizontal; | |
int number_bends_vertical; | |
boolean[][] grid; | |
Path() { | |
x = int(random(0,width)); | |
y = int(random(0,height)); | |
grid = new boolean[width][height]; | |
number_bends_horizontal = 0; | |
number_bends_vertical = 0; | |
} | |
void reset_movement() { | |
x = int(random(0,width)); | |
y = int(random(0,height)); | |
number_bends_horizontal = 0; | |
number_bends_vertical = 0; | |
ok = true; | |
} | |
void display() { | |
strokeWeight(stroke_weight); | |
stroke(247,247,247,20); | |
noFill(); | |
line(x,y,x,y); | |
line(x+line_width,y,x+line_width,y); | |
} | |
void move_vertical(int duration, int number_of_bends, boolean right_movement_change,boolean linked_with_line) { | |
//to determine if we want the line to move right or left across the screen | |
if(right_movement_change == true) { | |
increment = 1; | |
}else { | |
increment = -1; | |
} | |
if(ok == true) { | |
saveX = x; | |
saveY = y; | |
println("saved x: "+saveX); | |
println("saved y: "+saveY); | |
ok = false; | |
} | |
if(number_bends_vertical <= number_of_bends && ok == false) { | |
if(y <= (saveY+duration) && counter_v == 1 ){ // drawing the line in a downward motion | |
y+=increment; | |
//println("i'm in move vert first if state and y = " + y); | |
up_movement = true; // boolean to determine if the line is moving up or down the page | |
if(y == (saveY+duration)){ // if we have reached the length of the line and we want to have a linked line between them draw it | |
for(int i = 0; i <= line_width; i++) { | |
x+=increment; //if hits the top of the sketch either move across right or left depending on movement | |
display(); | |
counter_v = 2; | |
} | |
number_bends_vertical++; | |
//println("i'm in move vert and bends = " + number_bends_vertical); | |
} | |
} | |
if(y <= (saveY+duration) && counter_v == 2){ | |
y-=increment; | |
//println("i'm in move vert first if state and y = " + y); | |
up_movement = false; // boolean to determine if the line is moving up or down the page | |
if(y == saveY ){ //|| y == (height - line_width)?? | |
for(int i =0; i<=line_width; i++) { | |
x+=increment; //if hits the top of the sketch either move across right or left depending on movement | |
display(); | |
counter_v= 1; | |
} | |
number_bends_vertical++; | |
} | |
} | |
if(x >= (width-5) && right_movement_change == true) { // if it is towards the right and hits the width limit send it page to the left of the page | |
x = 5; | |
}else if(x <= 5 && right_movement_change != true) { // if it is moving towards the left and hits the far left move it back to the right | |
x = width- 5; | |
} | |
if(y >= (height-5) && right_movement_change == true) { // if it is towards the right and hits the width limit send it page to the left of the page | |
y = 5; | |
}else if(y <= 5 && right_movement_change != true) { // if it is moving towards the left and hits the far left move it back to the right | |
y = height- 5; | |
} | |
} | |
} | |
void move_horizontal(int duration, int number_of_bends, boolean right_movement_change,boolean linked_with_line) { | |
//to determine if we want the line to move right or left across the screen | |
if(right_movement_change == true) { | |
increment = 1; | |
}else { | |
increment = -1; | |
} | |
if(ok == true) { | |
saveX = x; | |
saveY = y; | |
println("saved x: "+saveX); | |
println("saved y: "+saveY); | |
ok = false; | |
} | |
if(number_bends_horizontal <= number_of_bends && ok == false) { | |
if(x <= (saveX+duration) && counter_v == 1 ){ // drawing the line in a downward motion | |
x+=increment; | |
//println(x); | |
up_movement = true; // boolean to determine if the line is moving up or down the page | |
if(x == (saveX+duration)){ // if we have reached the length of the line and we want to have a linked line between them draw it | |
for(int i = 0; i <= line_width; i++) { | |
y+=increment; //if hits the top of the sketch either move across right or left depending on movement | |
display(); | |
counter_v = 2; | |
} | |
number_bends_horizontal++; | |
} | |
} | |
if(x <= (saveX+duration) && counter_v == 2){ | |
x-=increment; | |
up_movement = false; // boolean to determine if the line is moving up or down the page | |
if(x == saveX || x == (height - line_width) && linked_with_line == true){ | |
for(int i =0; i<=line_width; i++) { | |
y+=increment; //if hits the top of the sketch either move across right or left depending on movement | |
display(); | |
counter_v= 1; | |
} | |
number_bends_horizontal++; | |
} | |
} | |
if(y >= (height-5) && right_movement_change == true) { // if it is towards the right and hits the width limit send it page to the left of the page | |
y = 5; | |
}else if(y <= 5 && right_movement_change != true) { // if it is moving towards the left and hits the far left move it back to the right | |
y = height- 5; | |
} | |
if(x >= (width-5) && right_movement_change == true) { // if it is towards the right and hits the width limit send it page to the left of the page | |
x = 5; | |
}else if(x <= 5 && right_movement_change != true) { // if it is moving towards the left and hits the far left move it back to the right | |
x = width- 5; | |
} | |
} | |
} | |
void full_triangle_move(int size, PVector colour, PVector colour2) { | |
point_one = new PVector(x, y); | |
for(int i =0; i <=size; i++){ | |
x++; | |
y-=2; | |
display(); | |
if(i==size) { | |
point_two = new PVector(x, y); | |
for(int j = 0; j <= size; j++){ | |
x++; | |
y+=2; | |
display(); | |
if(j == size) { | |
point_three = new PVector(x, y); | |
for(int m = 0; m <=(size*2); m++) { | |
x--; | |
display(); | |
if(m == (size*2)) { | |
for(int l =0; l<=(size*2); l++) { | |
x++; | |
display(); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
noStroke(); | |
fill(colour2.x, colour2.y, colour2.z, 150); | |
triangle(point_one.x,point_one.y, point_two.x, point_two.y, point_three.x, point_three.y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment