//base code for community link project //draws an ellipse for each member of the community (randomly positioned) //uses only arrays for data representation (ellipse positions, scale and color) //note little care taken to random distribution so some ellispe may overlap //has an exmplary "Zoe" triangle connected to two ellipse nodes = people //ZJ Wood 12/13 //***** //****assignment**** //given your assigned array index - identify 4 people in the class you are connected //to via a community connection (same socceer team, went to same pre-school, parents //are friends, etc.) //write code to draw a line between yourself and your 4 connections //*note that next we will merge everyone's code to try to draw al the connections but //start by just mastering how the arrays are indexed //lots of global data to make things simple - each ellipse has a position, scale and color int numS; int numC; float posX[]; float posY[]; float Red[]; float Green[]; float Blue[]; float ScaleX[]; float ScaleY[]; boolean ZFlag; boolean allFlag; boolean outFlag; float curLink; //initialize all the data void setup() { size(600, 600); smooth(); background(0); int i, j; float rad, ang; numS = 30; //number of students (or community members) numC = 4; //numbers of connections posX = new float[numS]; posY= new float[numS]; Red= new float[numS]; Green= new float[numS]; Blue= new float[numS]; ScaleX = new float[numS]; ScaleY = new float[numS]; ang = 0; //fairly cheap random sampling of locations on a circle //plus random scale in X and Y and color for appearance for (i=0; i < numS; i++) { ang += 0.4; rad = random(50, 280); posX[i] = 300+ rad*sin(ang); posY[i] = 300 + rad*cos(ang); Red[i] = random(10, 250); Green[i] = random(40, 240); Blue[i] = random(10, 245); ScaleX[i] = random(10, 20); ScaleY[i] = random(14, 32); } ZFlag = false; allFlag = false; outFlag = true; curLink = 0; frameRate(6); strokeWeight(2); } //control the draw parameters of the connections - all - incoming or outgoing void keyPressed() { switch(key) { case 'a': allFlag = !allFlag; break; case 'o': outFlag = !outFlag; break; case 'z': ZFlag = !ZFlag; break; case 'q': exit(); default: println("No key bound to this character"); } } //animation loop - note that framerate is controlling pulse frequency on ellipses in //conjunction with the update to curLink - idea being to let each ellipse pulse a few times //then advance to next person void draw() { background(0); int i, j; //draw connections to triangle = Zoe - just left for an example if (ZFlag) { stroke(100); line(20, 20, posX[0], posY[0]); line(20, 20, posX[5], posY[5]); stroke(255); fill(#215A25); triangle(10, 30, 20, 10, 30, 30); } //draw connections (first for draw order) //links always colored based on the originatora //TODO Add code here to draw connections between your node and your connections!!! //draw the people stroke(255); for (i=0; i < numS; i ++) { fill(Red[i], Green[i], Blue[i]); //pulse the current person for appearances if (i == int(curLink) && !allFlag) { if ((int((curLink-int(curLink))*10))%2 == 0) { ellipse(posX[i], posY[i], 2*ScaleX[i], 2*ScaleY[i]); } else { ellipse(posX[i], posY[i], ScaleX[i], ScaleY[i]); } } else { ellipse(posX[i], posY[i], ScaleX[i], ScaleY[i]); } } //update current link, slowly to accomodate pulsing animation curLink+= 0.1; if (int(curLink) == numS) { curLink = 0; } }