Responsive Rain Animation in Java

___________________________

In the first weeks of the semester of Fall 2017, the workload was light. So, I went looking for an interesting “weekend” project. I wanted to learn more about GUI, and was taking an interest in animation. So, how better to get your feet wet than to make a simple animation?

I wanted to brush up on the skills I’d attained over the summer, and learn how to use some of the libraries that the Java API has to offer. So, with only the very basics of Java programming under my belt, I created this simple program that utilizes the Swing and AWT libraries to display falling raindrops down the window.

The first challenge was learning how to create and manipulate the image. I knew nothing about content panes, containers, or Java’s canvases, but luckily StackExchange came to the rescue..

The next issue was learning how to impliment a runnable for the first time. Again, thanks to the countless resources online, I managed to establish a steady refresh-rate that makes the image come to life.

I quickly found that the logic of the animation was quite simple, so as a challenge to myself, I made the density of drops on the screen proportional to the size of a resizable window, using the ArrayList class, since (at the time) it was the most sophisticated data structure I knew about.

Lastly, I learned how to export the project to an executable jar file, which I thought was super cool! Just having the little icon on the desktop to double click was exciting to see for the first time.

Click here for the link to the GitHub repository and the source code.

Click here for a step-by-step, in-depth tutorial on how to build your own!

Responsive

 

My First Java Project

___________________________

In the summer of 2017, I decided it was time to teach myself basic computer programming. So, after reading Allen Downey’s book, “Think Java: How to Think Like a Computer Scientist” I felt somewhat comfortable with the fundamentals of OOP and the default Java library.

The same night that I finished the book and all it’s exercises, I was playing Magic: the Gathering with my brother. As we were playing he came up with an interesting question.. How many lands optimizes your chances of recieving 4 or more lands within the first 5 rounds of play? For those unfamiliar, Magic is a trading card game that began in the mid 90’s in which two or more players use “lands” to cast spells at eachother.

So I got to work.. and wrote a program that calculated the optimal number of “lands” in a 60 card deck. Using what I learned about the basics of algorithms and OOP, I was able to come up with a definitive answer: 17. This number optimizes the odds (24% to be exact) of drawing 4 “land” cards within the first 5 turns of play. This answer confirmed what is the generally accepted number amongst high level players.

Click here for the link to the GitHub repository and the source code.