Basic Card Drawing


I was in the process of completing a research project for my computer graphics class when I found myself wanting to write an applet that drew Tetris tiles. While brushing up on my graphics programming, I came across something interesting in this book.

I thought it would be interesting to try implementing the shortest path algorithm in Java. I began with a simple version of Bresenham’s Line Algorithm and after realizing that it was more complicated than it needed to be, refactored the code into something much more manageable. Once I had my BasicCard class finished, I wanted to try using the shortest path algorithm to draw playing cards. I was pretty impressed with the result.

how to draw cards

I have been writing about Java for almost ten years now. I wrote my first article on it way back in 1998, when I was working as a web developer and needed to know some Java fast. A short time later, I started tutoring students who wanted to learn programming and began teaching them how to use the new language that had just appeared on the scene.

I was using this particular applet to test various methods of drawing lines on a graphics context and thought that it might be useful for others who want to do similar things. I began modifying it so that I could add some additional shapes and found myself wanting to give them different colors, but realized that it would be easier to draw different shapes using the line algorithm if I could change the colors of the lines without having to actually redraw them. So, I added a parameter that would cause each line to be drawn with a random color rather than a static color and decided that it was a pretty useful little applet.

What is a basic card drawing and how does it work?

In the card drawing applet below, you’ll find a set of buttons for drawing a single card or a full deck. Clicking on one of the buttons will generate a random number between 1 and 52 and present you with either a single playing card or all 52 cards. The face images are static images included in the source code, but the colors for each card are randomly generated using the java.awt.Color class and stored in an array list so that they can be easily changed without redrawing the entire face of each card.

The different types of basic card drawings

Produced by using different algorithms for drawing lines on a graphics context. The Bresenham line algorithm is the simplest, fastest, and most widely known of the available line algorithms. However, it only works when you are drawing horizontal or vertical lines. There is another algorithm called Floyd-Steinberg that can be used to draw diagonal lines in a similar fashion to Bresenham’s line drawing algorithm. A third type of line drawing is called Midpoint circle algorithm and is used to draw circles on a graphics context.

How to use a basic card drawing in your business?

I was recently asked to write an application that would provide a user interface for working with playing cards. The requirements were pretty simple, but I knew it would be trivial to do the job using the Java Swing layout manager. After completing the project, I decided to turn my attention back to some of my old programming projects and came across this applet and decided to write an article about it.

Conclusion

The basic card drawing applet that I’ve created is simple to use and provides an easy way to view 52 different playing cards. If you are seeking to produce your own custom deck of playing cards without the need of purchasing expensive graphics software, then this may be just what you are looking for.


Leave a Reply

Your email address will not be published. Required fields are marked *