For the third project, I have chosen the coding term 'variables'. In this post I will pinpoint the instances in which the programmes make us of variables.
Code One:
In this code, float has been used. This tells us that the numbers used will contain decimals. The beginning of the code looks like this:
float diam; // width of ellipse and weight of line
float dripRan = random(1); //random size of drips
float dripWidth = random(1); //drip width
The function of each variable is given. The size of the drips and the width of them will be a random number. This means that when 'dripRan' and 'dripWidth' are used later in the code, a random number will be retrieved. Thus creating the inconsistency of the final spray can effect. diam is used later in this line:
diam = abs(mouseY - height/2)*.18;
This variable has not been assigned a specific number, which allows the code to 'constantly recalculate diameter as a distance from the mouse to the center, and make it 10% of that'. This creates the variation of sizes of circles, adding to the randomness the other two variables establish. They are implemented like this:
dripRan = random(10, 300);
dripWidth = random(.1, 3);
There are some limits being put down here, to achieve the desired length of drips and width of the 'spray'. The float variables have enabled the code to take up few lines, as there is a randomness stored in them which is used to create the ever-changing design. You can alter the length of the drips easily, as well as the width, because variables allow you to input less code to achieve a significant change.
Code Two:
This code is begun with numerous int variables. These are:
int W = 400; // screen Width (should be evenly divisible by S)
int H = 300; // screen Height (should be evenly divisible by S)
int S = 2; // ca cell Size or Scale in pixels when rendered
int C = W / S; // number of Columns in the ca
int R = H / S; // number of Rows in the ca
int mode=1; // which "variation" is currently active
int [][] curr; // current generation of ca
int [][] prev; // previous generation of ca
The purpose of each variable is written beside it. The code will require the placement of numbers so that the complex, changing design can be created. W, H, S, C and R have been implemented in various places in the code. For example, C and R have been given the screen width/ screen height divided by scale of pixels. This is so that the number of columns and rows do not remain stable, creating the moving effect of the green and black pixels.
Through analysing this code, I was able to realise that variables can be the sum of two or more variables divided by each other, multiplied, added, subtracted etc. Variables can have an effect on the number other variables represent. This puts me in mind of hybrid objects/tools and animals, but I'll get to the metaphors in a later post...
Code Three:
This code consists of various moving triangles, which can change colour depending on the type of mouse click. This is at the start of the code:
float x = random(400,width);
float y = random(300,height);
float w = random(0,200);
float h = random(0,200);
float d = random(0,200);
These variables are used later in the 'void shake' function. Lines such as this 'x = x+random(-1,1)*speed;' are used to create the moving shapes. Here, the random with 400 pixels height and random width is shown with an x, to which random is added, coordinates are given and a speed is assigned. This is effectively creating the speed of the moving triangles. Beneath it the same is done with variables x, y, w and h. Similar coding is used to constrain the area of movement and the scale of the triangles.
All three of these codes use variables to indicate something random. Numbers are arbitrarily chosen so that the movement of each of these interactive designs is never exactly the same as the last movement (some exception in Code Two as it will only change if you click/type a number). Variables are also used to input numbers which stay the same and can be added onto, sometimes using other variables. The codes retrieve these numbers from the int or float variables in several places, making each code intricate, but not excessively long.