Revised Sketch Code:
Original Sketch Code
Assignment
Re-work an existing assignment, using functions to compartmentalize your code. Write at least one function that takes parameters and one function that has a return value. If your existing assignments already make use of functions, or if you don’t want to build on existing work, feel free to make a new experiment from scratch. Goals and things to try:
- Break code out of
setup()
anddraw()
into functions. - Use a function to draw a complex design (like this) multiple times with different arguments.
- Write a function to that returns the result of a mathematical operation that you need to do several times in your code.
- Reorganize “groups of variables” into objects.
- If you are feeling ambitious, try embedding a function into an object.
For this week’s assignment I decided to try to rework my Persian rug closeup sketch. I was able to create a couple functions that would duplicate patterns for me like the ones below:
** after re-visiting shiffman’s 5.1-5.3 videos, I realize I should to comb back through not only for for loops but also to write my functions to take parameters instead of using translate **
// BOTTOM LAYER COLOR BLOCKS
//orange
push();
noStroke();
fill(196, 70, 0);
translate(300, 0);
foundationStripes();
pop();
//lightTan
push();
noStroke();
fill(239, 242, 205);
translate(-205, 0);
noStroke();
fill(239, 242, 205);
foundationStripes();
pop();
//skyBlue
push();
noStroke();
fill(167, 207, 209);
translate(-300, 0);
foundationStripes();
pop();
//brickRed
push();
fill(130, 82, 70);
noStroke();
translate(-410, 0);
foundationStripes();
pop();
//greenTan
push();
noStroke();
fill(203, 200, 179);
translate(-430, 0);
foundationStripes();
pop();
//navyBlue
push();
noStroke();
fill(53, 69, 94);
translate(-522, 0);
foundationStripes();
pop();
// BLUE CIRCLE COLUMN
// Row 1
push();
translate(-50, 0);
makeCircleColumn();
pop();
// Row 2
makeCircleColumn();
}
// Blue Triangle
push();
fill(53, 69, 94);
translate(-30, 0);
scale(1.2);
triangleParty();
pop();
// Small Green Triangle
push();
translate(70, 20);
fill(141, 160, 89);
scale(1.2);
triangleParty();
pop();
// Large Green Triangle
push();
translate(-200, -285);
fill(141, 160, 89);
scale(4.0);
triangleParty();
pop();
I would like to comb back through and translate the repetitive lines of code into For loops ❤ (example: all the circle lines) I also used Scale but would like to play with a Return Value in a function too. Thinking about:
- Modularity
- Reusability
- Return Values