Project Title: Bacterial
https://editor.p5js.org/jperry/sketches/bp1sFuMfk
This project is a design of a bacteriophage virus that I have turned into a creature.
This code was fairly difficult for me because I found it hard to work together with all the rotations and translations. If I wanted to move the order of my functions, it was difficult to get the shapes back to the position I wanted them in.
function drawCreature(x, y, a, s) {
push();
translate(0, 0);
rotate(a);
scale(s);
drawBody(-300, 0, 0, 1.0);
drawNeck(-300, 0, 0, 1.0);
drawHead(-300, 0, 0, 1.0);
drawLegL(-300, 0, 0, 1.0);
drawLegR(-300, 0, 0, 1.0);
drawLegM(-300, 0, 0, 1.0);
drawFace(-300, 0, 0, 1.0);
pop();
}
In my project, I have used translate() to move the origin point to a different part of the canvas. This allowed me to rotate the objects around a new point. push() and pop() allow for the manipulation of a specific event to not be carried over into the next object, so it separates each of the functions and resets the code to the original positions after they have run.
The user-defined functions allow you to call a block of code all at once. This has made my code more concise and organized.
My functions all included x,y, a (rotation) and s (scale). These manipulated the effects of the functions as I could adjust any of these individual characteristics to change the position, rotation or size of the shape.
The use of user defined functions radically changed the organization of my code. Instead of having multiple blocks of code in the draw function, i instead could just call what was needed. It also helped for if I wanted to change the order of my shapes on the canvas. I can just reorganize the functions instead of having to select and move the entire block of code. This also allowed me to work in any order I wanted, knowing it would be easily changed later.