//here i create a new type of object, called a class, which gets its own space in memory and has other values and properties associated with it class Circlet { //these are data values inherent to the class private int xPos, //x position of center of circle yPos, //y position of center of circle position, //the space in the chain the circlet occupies radius, //the radius of the circle alphaVal; //the alpha value of the circle //in most programming languages you can set the accessibility of these variables, ie whether or not functions outside the class can access or //modify the contents of the varialbe. here i have set them to private, so that only the object is able to modify itself. // //however, this means that if i want to later modify these variables without creating a new instance of the object, i will need other functions //to do so. these functions are generally called accessor and mutator functions. //accessor functions //these fucntions are called when another function need information from an object of the circlet class //they are called with no parameters (nothing is sent to the function), and simply return the value of the //variable being asked for int getXPos(){ return xPos; } int getYPos(){ return yPos; } int getPosition(){ return position; } int getRadius(){ return radius; } int getAlphaVal(){ return alphaVal; } //mutator functions //these functions are used to change a value within a private variable //they are called with a specific value which the variable is then set to void setXpos(int newVal){ xPos = newVal; } void setYpos(int newVal){ yPos = newVal; } void setPosition(int newVal){ position = newVal; } void setRadius(int newVal){ radius = newVal; } void setAlphaVal(int newVal){ alphaVal = newVal; } //overall mutator function: this function will allow the program to set all of the values of a circlet in one fell swoop (i like that phrase) void setAll(int newX, int newY, int newPos, int newRadius, int newAlphaVal){ xPos = newX; yPos = newY; position = newPos; radius = newRadius; alphaVal = newAlphaVal; } //strictly speaking, setting these to public (or not specifying a public/private state) will allow the values to be set from within processing //but it is still good programming practice to shield information as much as possible //Constructors //constructors are used to set aside memory within the computer for storing data. the process is commonly referred to as "creating a new object" // the code int x = 3 invokes a constructor that creates a new object of type int (integer) and sets its value to 3 //a default constructor creates a generic instance of the object, with predefined values for its variables Circlet(){ xPos = -1; yPos = -1; position = -1; radius = 0; alphaVal = 0; } //the following constructor takes specific values and creates a new object using those values //technically, this is called overloading the constructor, as we have two functions of the same name that take different input parameters and //create different results Circlet(int newX, int newY, int newPos, int newRadius, int newAlphaVal){ xPos = newX; yPos = newY; position = newPos; radius = newRadius; alphaVal = newAlphaVal; } //the following is another specialized constructor, for use in special cases Circlet(int newX, int newY, int arrayPos){ xPos = newX; yPos = newY; position = arrayPos; radius = circleSize; alphaVal = 255 - (10*arrayPos); } //the following function will draw the circle as it is described by its parameters //its color will be determined by how far it is down the line of circlets //and the alpha value by that parameter void drawMe(){ fill(255-10*position, 255-10*position, 255-10*position, alphaVal); ellipse(xPos, yPos, radius, radius); } //the following is a print function which will spit out the values contained in the Circlet void printMe(){ println("x: "+xPos+" y: "+yPos+" rad: "+radius+" pos: "+ position+" alpha "+alphaVal); } } //global variables //these variables are accessible at any time anywhere by any function in this program // here i create an array of Circlets that has a capacity of 10 individual objects Circlet[] blurArray = new Circlet[10]; //i'm going to set the radius to a default number, but it would be easy to modify this based on user input or more code int circleSize = 10; //here i set the offset value for the distance between the circles in the motion blur int offsetVal = 5; //the setup will set the initial parameters for the viewfield void setup(){ //frameRate(30); println("setupcall"); noStroke(); //the background will be set to a solid red color initially background(255,0,0); size(400, 400); // here i iterate across each cell in the array. //arrays are numbered starting with 0, so i must go through cells 0 to 9 to get the 10 cells that i initially created Circlet temp = new Circlet(); for (int x=0; x<10; x++){ println("Array index " + x); //here i set each cell in the array to contain a dummy value for the circlet } } void draw(){ //each time the computer redraws the frame, the window will be filled with red background(255,0,0); //it will then call the function that takes care of drawing the circles based on where the mouse is drawCircles(); } void drawCircles(){ //another programming technique is the idea of pseudo-code, which is a phrase based diagram of the code //essentially it is thought-sized chunks ordered in a way that forms a blueprint for the intended code println("DrawingCircles"); /* in this case, i want the program to take the following steps: check for increasing or decreasing the length of the blur update the position of each circle in the blur redraw the whole thing */ //it seems that i can't do pointers (boo processing, yay java), so i've had to resort to the ugly, stupid array method //here i will divide the window vertically into 8 sections, each 50 pixels tall //each section the mouse descends will add a circle to the end of the tail //because of the way information is drawn to the screen, i have to draw things at the back first, and things that will fall on top of them later //so i start from the end of the array and work towards the front. for (int x = (mouseY/50)+1; x >= 0; x--){ //i will then set the circlet in each array //functions specific to objects are called in the following manner: the name of the object being called, followed by a dot, followed by the function name //in this case, each cell of the array contains an object of the class Circlet, and since the compiler is smart enough to know that //and smart enough to know that it is legal for the programmer to call a function that belongs to the thing contained in that cell, //i can write the following, which is saying, 'the Circlet contained in the array cell x should call the Circlet function called setAll //using the parameters and change the data stored within the Circlet\ //if there is something in the array to modify if(blurArray[x] != null){ //but first of all, i need to move the circlets; moving each to the position that the circlet ahead of it in the chain occupied in the previous frame //i will set the main circle in just a moment if(x>0){ //move the circlet by setting its values to the one ahead of it in the chain, and redraw it blurArray[x].setAll(blurArray[x-1].getXPos(), blurArray[x-1].getYPos(), x, circleSize, 255-10*x); blurArray[x].drawMe(); } else{ //this requires a separate case, because if it was parsed by the previous block, the code would try to access the data in the array cell -1 //which would result in an index out of range error, as the array does not contain negative elements println("head"); blurArray[x].setAll(mouseX,mouseY,1,circleSize,255); blurArray[x].drawMe(); } } else{ //there is nothing in the array, so we need to create a new Circlet to fill that cell Circlet temp = new Circlet(mouseX,mouseY,x); blurArray[x] = temp; } blurArray[x].printMe(); } }