Coding with Spencer
06/11/2013 § Leave a comment
The beginning section of the code is finding the points to position and these are what we call XPOS and YPOS. To represent the speed of the axes we’re using we use the titles “float yinc;” and “float “zinc;”.
The “float xpos2;” and “float ypos2;” show us the variables that control the position of the still point. We then set random poistion points for the moving item. ”xpos=random(1024);” same for the ypos underneath set a fixed speed and “yinc=5;” and “zinc=3;.” was used in order to set a random position for the still point.
We added the x and y speed to the desired positions using the code underneath the drawing of the line. We then start using more complicated coding:
if (ypos<0) yinc=5;
The ‘if‘ code is relating back to the canvas size. Therefore, if we go out of the top screen it will send the point towards the bottom and if it goes to the bottom it will send the point to the top. This whole code made the points bounce from the edges.