Computer Science is a course based on learning how to program. We have learned web design such as HyperText Markup Language (HTML) and Cascading Style Sheets (CSS). We used the skills we learned to build the website you are viewing now. In addition, we have learned Java through many small programing practices, which gives the fundamentals on how to think critically and logically when it comes to programming.
One programming challenge involved finding a value for pi purely off of random chance. Students would use a “random” object to pick 2 different random doubles (numbers with up to 8 decimal points) between -1 and 1. That point would then be calculated to see how far it was away from (0,0). If the distance was less than or equal to 1, then the spot would be considered a hit. If the distance was more than 1, it was a miss. At the end, the hits were divided by the total, which was multiplied by the total area (4) to get a value for pi. After “dropping” one billion darts, which took only about 40 seconds due to my code optimization, I managed to get a running value of 3.14159.
After that, I decided to visualize the hits and misses. I used Java’s Abstract Window Toolkit (AWT) to “draw” a 1 pixel by 1 pixel where the dart was dropped. The total canvas was 1000 pixels by 1000 pixels. You can see the results when I dropped both one million and ten million darts. The color was changed to green for a hit and blue for a miss, giving the drawing of a circle.
Trouble viewing? Click HERE.
Want to see the Java code? Click HERE.
One of our labs made an optical illusion. While the results look like curved lines are used to make the design, the reality is that it is made purely out of straight lines. I randomized the color of each line and even made the design repeat itself on the inside of the design.
Trouble viewing? Click HERE.
Want to see the Java code? Click HERE.