Or, how I love to not reinvent the wheel!
I was browsing this thread over in the Java forum and I wrote a quick diddy that has a square ping pong back and forth between two "walls", nothing fancy, but illustrates a concept we as programmers should take to heart: do not reinvent the wheel.
Sure, I could have written my own function to determine if two rectangles had intersection within the next "cycle", OR I could use java.awt.Rectangle's intersects() function. But...do I really need a homebrew solution for my rectangle? The answer is a resounding no, even if I was to make the movement more complex (angles, rather then straight horizontal motion), I still could utilize (or leverage if you're into buzzwords) the power of the standard Java library to meet my needs.
Here's a picture!

How awesome are pictures?
Source code can be found here.
I was browsing this thread over in the Java forum and I wrote a quick diddy that has a square ping pong back and forth between two "walls", nothing fancy, but illustrates a concept we as programmers should take to heart: do not reinvent the wheel.
Sure, I could have written my own function to determine if two rectangles had intersection within the next "cycle", OR I could use java.awt.Rectangle's intersects() function. But...do I really need a homebrew solution for my rectangle? The answer is a resounding no, even if I was to make the movement more complex (angles, rather then straight horizontal motion), I still could utilize (or leverage if you're into buzzwords) the power of the standard Java library to meet my needs.
Here's a picture!

How awesome are pictures?
Source code can be found here.
2 Comments On This Entry
Page 1 of 1
NotarySojac
17 December 2011 - 04:33 PMQuote
How awesome are pictures?
Quite awesome.
Might you also have the liberty to share source code? I'm teaching a cousin Java and he might get a kick out of moving rectangles =)
Page 1 of 1
← January 2022 →
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 | 31 |
Tags
My Blog Links
Recent Entries
Recent Comments
Search My Blog
20 user(s) viewing
20 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)



2 Comments









|