boolean meFailEnglish = true;
int warnerBrothers = 4;
int tom = 0, jerry = 0;
void setup() {
size(400, 400); background(0);
}
void draw()
{
rect(tom, jerry, width/warnerBrothers, height/warnerBrothers);
tom+=2*width/warnerBrothers;
if (tom >= width) {
if (meFailEnglish)
{
tom = width/warnerBrothers;
}
else
tom = 0;
meFailEnglish = !!!meFailEnglish;
jerry+=height/warnerBrothers;
}
}
- What aspects (in terms of coding style) of the program can be improved?
- What changes should I introduce if I want the top-left cell to be black (instead of white)? That is, I would like to rotate the grid by 90 degrees (clock-wise or anti-clockwise). Don't use
rotate()
/pushMatrix()
/popMatrix
. Do it by simple manipulation of the existing program. - What aspect of the program makes it scalable?
- (HD) There is a very subtle bug in the program. Identify and fix it.
Explain what magic numbers are and how we may refactor our code to remove them. Furthermore, what advantages does removing magic numbers have?
Refactor the following code to use a loop.
println("#");
println("##");
println("###");
println("####");
Why is using a loop better than manually printing each row of the pyramid?
Why is top-down design called a divide and conquer strategy?