Hello All,
Here are the homework assignments for tomorrow with the exception of the oscillating
Lissajous pattern one, which I will try again later, but my brain is having trouble mapping sound
oriented things into visuals…
All of these examples needed appropriate use of Arrays and For Loops. Why?
Because it not only makes things more efficient and easier for you to code.
But it also allows you to customize the same code for other purposes by changing variables
instead of random parameters that map onto a value that you’ve already forgotten.
Why write a thousand lines when you can write two???
Anyhow. Here is a picture of my look alike for A1. Simple but effective. I started doing the others, but
they all pretty much implement the same concept, so why kick a dead horse?
My A1 Version
And here is my code for it. I am sure it can be more efficient if I were better at math:
// Assignment to create a set of drawings like those in this folder – Try and recreate the drawings A1, A2, A3
// Suggested steps in developing the code:
// a) recreate using the most obvious means – drawing primitives and coordinates – laborious but effective
// b) replace repetitive steps by for loops
// c) replace parameters by variables, and place these at the top of the program
//This Code will create circles in diagonals from the top left to bottom right, vice versa
float[ ] myCircleX;
float[ ] myCircleY;
float[ ] myCircleY2; //the inverse of myCircleY to make 2nd diagonal
float distX; //the distance between the x pos of circle radius
float distY; //the distance bet. the y pos of circle radius
float circleW; //the width of the ellipse
float circleH; //the height of the ellipse
float currentX;
float currentY;
float currentY2;
void setup(){
size(500,500);
myCircleX = new float [10];
myCircleY = new float [10];
myCircleY2 = new float [10];
distX = width/10;
distY = height/10;
circleW = (distX/2)-5; //width of ellipse = radius minus offset of 5
circleH = (distY/2)-5;
currentX = circleW+5; //= radius of circle plus 5 offset
currentY = circleH+5;
currentY2 = height-(circleH+5);
//loops fills in x values for circles
for(int i=0; i<myCircleX.length; i++){
myCircleX[i] = currentX;
currentX = currentX + distX;
}
//fill in y circle values into array
for(int i=0; i<myCircleY.length; i++){
myCircleY[i] = currentY;
currentY = currentY + distY;
}
for(int i=0; i<myCircleY2.length; i++){
myCircleY2[i] = currentY2;
currentY2 = currentY2 – distY;
}
}
void draw(){
background(0);
for(int i=0; i<myCircleX.length; i++){
ellipse(myCircleX[i], myCircleY[i], circleW*2, circleH*2);
fill(255, 0, 0);
}
for(int i=0; i<myCircleX.length; i++){
ellipse(myCircleX[i], myCircleY2[i], circleW*2, circleH*2);
fill(255, 0, 0);
}
}
Here is how I made the Dark Star more efficient and connected the beginning and ending points.
It’s all just replacing repetitive things with for loops
My Vertices Fix
size(1000,1000); //size of window
smooth(); //tells the renderer to apply anti-aliasing
background(255,0,0,255); //set the window background color – the 255 is not strictly necessary!
int [ ] vertexX;
int [ ] vertexY;
vertexX = new int [6];
vertexY = new int [6];
vertexX[0]=250;
vertexX[1]=750;
vertexX[2]=300;
vertexX[3]=500;
vertexX[4]=700;
vertexX[5]=250;
vertexY[0]=200;
vertexY[1]=200;
vertexY[2]=500;
vertexY[3]=100;
vertexY[4]=500;
vertexY[5]=200;
//vertices are used to define the points within a shape
//and then Processing tries to make sense of them in terms of any shape you specify
//if you don’t specify anything – it will just draw lines between each point
//you must always start with ‘beginShape’ and ‘endShape’
beginShape(); //must always have this
noFill();
strokeWeight(3.0);
//replace the busy work with a for loop to draw the shape
for(int i=0; i<vertexX.length;i++){
vertex(vertexX[i], vertexY[i]);
}
/*
vertex(250,200); //first vertex
vertex(750,200); //next vertex
vertex(300,500);
vertex(500,100);
vertex(700,500);
vertex(250,200);
*/
endShape(); //you always have to do this
//very coyly introducing how you print to the screen (as opposed to the console)
PFont font = loadFont(“CourierNewPSMT-12.vlw”); //first you grab a font file
textFont(font); //then you tell the program to use that font – until you specify another, for example
fill(0); //font color
//println(“250, 250″);
//replace the bulky text repetition with a classy for loop
for(int i=0; i<vertexX.length;i++){
text((“”+vertexX[i]+”,”+vertexY[i]),vertexX[i], vertexY[i]);
}
/*
text(“250, 250″,250, 250); //then you print the text
text(“750, 200″,750, 200); //then you print the text
text(“300, 500″,300, 500); //then you print the text
text(“500, 100″,500, 100); //then you print the text
text(“700, 500″,700, 500); //then you print the text
*/