Sunday 29 May 2011

Showing the flow of a program: Draft and further explanation into programming theory

My piece shows non programmers how a program runs “IF/else” statements in a program, and will be displayed through the medium of water.
In an “IF/else” statement, a series of Boolean decisions are made and are a matter of true or false. In this example below the computer has to work out whether “i” is true to the “IF” statement, or false. In this case if the statement is true, the program draws a line or else it asks another question.

for(int i = 5; i < 95; i += 5) {
if(i < 35) {
line( 30, i, 80, i );
} else if (i < 65) {
line( 20, i, 90, i );
} else {
line( 0, i, 100, i );
}
}

In my piece uses a series of clear hoses that have water flowing through it, the user comes along and decides which path the water takes (left or right) and each path shows a different colour. To explain in more depth and to relate my piece back to the programming foundation; the “i” or variable in the code above is the water, and each junction in the water flow system is the “IF” statement that the user can choose whether it is true or false, (the differentiation between the choices will be obvious due to the different coloured outputs.) The hoses that go off without coming to a junction again are the lines that would be drawn if it were a program.

No comments:

Post a Comment