Recreational Programming Projects
With source code! Java 3D, C, OpenGL, and more.
One of my oldest hobbies has been programming computers, especially graphics. Trapped in the 80's with BASIC on an Apple IIe probably wasn't the best place to learn graphics, but at least computers of that time were more accessible to beginning programming. Back then you could sit down at any computer, turn it on, and write a program, usually something simple like "10 PRINT "HELLO": GOTO 10". Anyway, it wasn't until entering college and learning stuff like OpenGL and Java 3D that I actually had something to show for my greatest programming ambition, modeling natural behavior and mathematical functions through computer graphics.
This page sketches some of my non-work-related graphics programs. I'll describe things so anyone can understand what's going on without having any programming experience. And I'll include lots of screenshots, since what fun is a program if you can't see what it does?
My simple trees were made up of cylindrical segments, since cylinders are a basic object in Java 3D and are rather easy to create. During each iteration, each branch would grow by one cylinder length. Each cylinder was oriented slightly randomly in space, to make the tree look natural. Each cylinder also had approximately a one in three chance of splitting into two cylinders, allowing the tree to branch off. As the tree got older, the oldest cylinder segments would grow fatter, just as the oldest parts of a tree are the fattest. The screen shot on the right shows the extent of what this program could do. (The source code is available below.)
The biggest challenge of the project probably was the 3D math. When a cylinder is instantiated in Java, it's laying along the Y axisalways. I would imagine that most of the time when you need a cylinder, you need it to extend between two points, such as from the origin (0, 0, 0) to some other point, like (3, 2, 7). Java 3D ignorantly does not provide any method for easily placing your cylinder into the desired orientation! So I had to write a 3D transform procedure which took two endpoints and figured out the rotation matrices required for putting the cylinder into that orientation. Since it took me several days to code this (and boy was I excited when I got it to work!), I've posted the source code for it below.
At any rate, the trees my program was making still appeared rather unnatural (besides the fact that they're made out of cylinders, and they don't have leaves). One reason for this is because the branches' orientations are too random. My boss pointed me in the direction of one method which can produce natural-looking plants, trees, and bushes: L-Systems.
Programming 3-D graphics in C
Making a computer learn by trial and error
Accurately representing the world, using numbers, is a lot of work
Assembly Language Space Invaders
I wrote Space Invaders using the most painful language available
In 1995 I took a PC assembly language class at U.T., and for our final project we had to write Space Invaderspurely in assembly! I never would have done something that crazy on my own (true to form, I had to stay up the entire night before in order to finish it, just in time). However, I'm pretty happy with the finished product. Thank goodness it works, because I'd never dream of trying to fix it. It's probably too fast to run on today's machines, but it still runs nicely in the SoftWindows PC emulator on my Mac. The source code is available below.
Download the PC executable here!
I had some spare time at a PC a couple summers ago, so I learned QBASIC and wrote a few fun little programs (source code available). One of them lets you choose sizes of planets and their starting positions and velocities, and then lets them go. They fly around each other according to Newton's law of gravity. However, the planets quickly interfere with each other and their orbits decay. For such a simple little program, it does a good job of demonstrating how finely tuned our solar system is (a byproduct of the way it formed).
I also wrote a fireworks simulation. One firework at a time explodes on the screen and then shimmers as it drifts down and disappears. It'd look really nice on a fast computer, I bet!
A third program I wrote was supposed to simulate a flock of birds (you know, how birds tend to stay in a loose grouping while they're flying somewhere), but the program turned out producing results closer to a swarm of insects. That's fine, but I couldn't quite figure out what quality differentiates the two behaviors. Anyway, this would also look great on a fast computer.
These are exactly the types of programs I liked to write on my Apple IIe back when I was in middle and high school. I always have a list in the back of my mind of fun programs I could write, when I have the time and resources, like I did with my tree modeling program. (My Macintosh at home isn't the ideal platform for writing these kind of things.) If you're a beginning programmer and want some ideas, let me know. I can help you get started and offer advice. Producing realistic models that you could see and interact with was always what made programming fun for me.
The Source Code
Here's the source code in its entirety for all of the projects outlined above, plus a few more that have no screen shots available. If you have trouble getting them to work, feel free to drop me a line.
Terms of usage: Feel free to use any of this source code in any project, as long as my name and web site address are present in the source code ("Scott Teresi, www.teresi.us") and listed as a small footnote in your About box (if you're application is extensive enough to have one)! I also would love hearing from you about how you found the source code useful. Thanks!
Tree.java - main application
SegmentBehavior.java - behavior class for segments of the tree (the whole tree rotates, by the way)
BranchBehavior.java - behavior class for entire branches of the tree
README - a couple notes
Java 3D cylinder creator. Instantiates a cylinder, in the orientation YOU want!
CylinderCreator.java - creates a Java3D cylinder extending between two endpoints.
C and OpenGL Sierpinski cube (and tetrahedron). Produces a Sierpinski object with varying amounts of detail. Mouse can be used to rotate the object in 3-D space.
Source code available here. Here's the monster makefile for HP-UX, and one for SGI.
C Unix mail reader. Works like a very bare-bones version of Pine. Displays two window panes, one containing a list of e-mails in your Inbox and the other the current message's contents. Requires the "curses" screen windowing library.
Here's the source code to mail.c.
Java Neural Net application. Implementation of a plain vanilla backpropagating neural network, with graphical display of neurons and synapses. I'm not sure if it learns very well. Sample data file and results file included.
Download it here, or see a directory of the files.
Rayshade 3-D graphics scenes. Refer to screenshots above. Requires Rayshade.
The big one: bigscene.ray
One of the smaller ones: scene.ray
Matlab JPEG data compression. The JPEG algorithm implemented before your very eyes. The real magic is in the discrete cosine transformation (DCT). Take a look! Matlab is very English-like, as far as math goes.
The Matlab program: jpeg.m
Sample image file, raw data format specially for Matlab: lenna.mat (may be binary format)
Data from some trial runs: jpeg.results
Help using Matlab: matlab.help
Some fun with QBASIC. Swarm of flies, a model solar system, and fireworks.
A bunch of dots swarming like flies: swarm.bas And a slightly modified version: racers.bas
A model solar system, planets orbiting a larger planet: planets.bas (all settings customizable).
Space Invaders in PC assembly! Text-based (no graphics, but it's colorful).
The executable for your PC: space.exe
The source code: mp4.asm and other necessary source files: bintoasc.asm and string.asm
A batch file to compile and link the program using the MASM compiler: com.bat
Remember, screen shots are available above for most of these programs, and drop me an e-mail if you have any questions at all about the source code or even programming in general.
Home | Contact Page
Professional Portfolio | Resume
Essay/Opinion | Photo Gallery | Digitally Altered | Video Editing | Making Music | Programming
Traveling | Skiing | Urban Exploration
About Me | Friends/Family
Jokes | Sound Clips | Links