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>768) yinc=-5;

if (ypos<0) yinc=5;

if(xpos>1024) xinc=-3;

if(xpos<0) xinc=3;

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.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Coding with Spencer at Taylor Sim.

meta

%d bloggers like this: