Java I
Jonah Warrenjonah@parsons.edu
http://a.parsons.edu/~java2004
Lab 4
Complete the following exercises:
- Create a void function called twoSquares() that takes in an x position and a y position as parameters, and draws two squares, one inside the other. Call your function from loop() or setup().
- Add another parameter to your function called sideLength that will determine the size of the outer square. Make the inner square be half the size of the outer square.
- Create an int function called smallestInt that takes in 5 integers and returns the smallest one.
- Create a float function that takes in 3 floats and returns the average value.
Homework 4
(Please email me if you have any questions or problems)- Read over these processing examples related to functions...
- Custom drawing functions:
- Create a function that draws a small + simple drawing you like. Pass in its x and y values that will determine where its drawn.
- Add other parameters to your drawing function to make it as dynamic as possible (maybe pass in a color (look at this color variable type processing has), colors, height, width, nose size, isAngry (boolean)... be creative).
- Use your function in a for loop to draw it multiple times, with different attributes. Post this composition. (criminal line up? diversity poster?).
- Reactive grid:
- Take a look at the following code. Add println()s if you need help understanding specific parts:
void loop() { for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { drawReactiveRect(i*20,j*20); } } } void drawReactiveRect(int x, int y) { if (mouseX>x && mouseX<x+20 && mouseY>y && mouseY<y+20) { fill(255); } else { fill(0); } rect(x,y,20,20); } - Alter this code to make your own reactive surface. Possibilities: draw something else besides rect, use x and y to determine color, make it bigger, more dense, make a different thing happen when you rollover, make something else happen when you click... Post this composition.
- In this example, as soon as you move off a square it always turns back to black. Think about how to use an array to keep track of what state the block is in. Make it so you can tell
what blocks you have rolled over previously. Post this composition.
Pssst, here's a hint!!!
- Practice loading in and displaying images... be sure to remember to put your image file in the data directory you are working in (in the 'sketchbook' folder).
- Load at least two images into processing with some sort of relationship to one another.
- Make an simple interactive composition out of your two images. An example is to fade from one to the other using mouseX or mouseY and tint. It could just be a click. You could also use your reactive surface assignment to navigate between the images. Post this composition.
void setup() {
size(250,250);
background(0);
}
void loop() {
BImage b;
b = loadImage("utah.jpg");
image(b, 25, 25);
}