Home | Explore | Create | Strangths | College | Research |
function drawBall() {
noStroke();
fill(25, 200, 500);
ellipse(ballX, 200, 20, 20);
ellipse(200, ballY, 20, 20);
ellipse(ballX, ballY, 20, 20); }
The purpose of this block of code is to draw the three blue balls that show up on the screen. When this code runs correctly, it draws three balls the same size as each other. The algorithm is able to achieve this result by using ellipse to position and control the size of the three balls. It also uses fill to add color to all three of the balls. If this program did not include this algorithm, the blue background would not be able to change to different colors. This algorithm works with the move function to make sure the three balls are able to move around in the screen.
function draw() {
background(BG);
Background();
stroke(0);
line(width / 2, 0, width / 2, height);
line(0, height / 2, width, height / 2);
drawBall();
move();
CheckBounderies();}
An example of an abstraction in my program is the Draw(); function. This simplifies my program by calling all the previous steps which include drawing the balls, moving, and checking the boundaries into one place. This way I have all the parts that make the program run in one single are reducing the code into simple steps. I created this function to avoid having a messy code and be able to single out any bugs because it is easier to tell if one step is not working and were I can find and change the code without breaking it. If this abstraction was not present, then there would be no balls and they would not be able to move because even though I have the code for each of the steps without calling them in this draw function they would not appear on the screen.