Archive for the ‘ Programming ’ Category

OpenGL Project 1: Menger Sponge

I’m taking introduction to computer graphics this semester which focuses on OpenGL and our first project is due Monday. Conceptually speaking the project was supposed to be very easy as a similar project’s code was given to us, the Sierpinski Tetrahedron. The difference here is that the Menger Sponge removes central cubes from cubes.

I was agonizing over how I was going to do it for 3 days this week, then I had a breakthrough moment and spent the last 2 days working on it. This is the executable. There is a right click menu which shows allows different modes to be set as well as show you the keyboard shortcuts.

  • W, A, S, D, Q, E rotate the cube
  • F will swap between wireframe and solid cube mode
  • L will change the lighting. Useful in wireframe mode
  • V will display the inverse sponge.
  • 0-4 changes the level of iteration. I could have gone to 5 but time to render 5 iterations is about 10 seconds on my computer and on 4 iterations the rotation is very sluggish.
  • +/- Will scale the size of the cubes

If I really want to spend some extra time working on it, I’d like the change the lighting a bit and add mouse based rotation. The main function I used for drawing the cube doesn’t allow for texturing so I’d probably look into rewriting that entire function.

No source code in this zip, just the executable and the required DLL.


UPDATE: Corrected the inversion function and discovered that you need Visual Studio installed or the executable might not run. I’ll post source at the end of the semester.

1 Iteration

1 Iteration

3 Iterations

3 Iterations

Inverse 1 Iteration

Inverse 1 Iteration

Inverse 2 Iterations

Inverse 2 Iterations

Inverse 3 Iterations

Inverse 3 Iterations

Spring Semester Projects

Obviously I’m lazy with the site but this has been one of my much busier semesters. My class list was

  • Introduction to Artificial Intelligence
  • Operating Systems
  • Numerical Analysis
  • Physics of Sound and Music

Notably my plan was to be able to build world dominating robots after this semester but unbelievably that wasn’t covered in AI. I think we ran out of time or something which sucked. My project list this semester was fairly interesting though.

Numerical Analysis Project: Integration through Trapezoid/Simpson Method

This project demonstrates how precisely computers can do integration by fine tuning the resolution of the given function. The functions are hard coded into the program so if you want to toy around with it you’ll have to manually change the functions. Calling the functions is straightforward, you call which method you want to use and pass in the function to evaluate, the starting point of integration a, the ending point of integration b, and the resolution which defines how much you’re cutting up the curve. Higher resolution is more accurate integration.

I originally coded this project in C++ but I ported it over to Python 2.4.4. Download link (right click and save as):

Numerical Analysis Project: Runge-Kutta

Runge-Kutta is a method which allows you to solve initial value problems. Wiki explains it in detail. The function we’re solving doesn’t have a t term so the implementation isn’t exact. The function yPrime can be modified to accept a t term and one would have to change up the function appropriately since in this program it specifically evaluates y^2. Additionally, it’s hard coded to evaluate the 100th term so if you need any specific term it could be changed up easily enough.

This project is written in C++ for Windows. Download link (right click and save as): rungekutta.cpp

Operating Systems Project: AT

There is a command in Unix called “at”. What happens is you can call “at” to schedule a command for execution at a later date. So we were tasked to develop a very similar program with a strict set of command sequences. This program was interesting to develop and helped to solidify reading in command line arguments. The initial set of comments should help you get going.

This project was developed in C for (very old) Unix based systems. Download link (right click and save as): at.c

Operating Systems Project: Virtual Memory Management

A very roundabout project, we were tasked with taking a text document and inserting blank pages into it based on how the user executes this program. The command string is something like “program inputfilename X X X X X” where the X’s are numbers denoting how many pages to skip before writing in a blank page. We were not allowed to just manipulate the file directly though, we were to map the file into virtual memory and manipulate it entirely in memory before syncing it back to the drive.

This particular program was so procedural that instead of my usual commenting style, I simply numbered what I had to do and wrote the program out step by step. I think you can remove the math.h include, I forget why I had it.

This project was developed in C for (very old) Unix based systems. Download link (right click and save as): vmemory.c

Artificial Intelligence Project: 8 Puzzle

So if you remember being a kid and having those little sliding puzzles that either had numbers or pictures on them, that’s what 8 puzzle is. Our job was to simply be able to read in a text file that had the current state of the puzzle and the state you want to go to and then generate the set of actions that would make the first puzzle look like the second puzzle saved to a file.

The assignment was to write this project in either C++ for Unix or Java (platform independent). I sort of dreaded this since I’m very rusty with my C++ data structures (needed to use tree and vectors) so I initially thought I’d use my sister for guidance since she’s much more proficient in Java. We hashed out the reading of the file and the heuristics over Spring Break. Those things were the easy part for sure though and as the deadline approached I decided to try a crazy idea. Over the past few months I’ve been urged to learn Python and as such I’ve even bought a few books on Python. I haven’t had a chance to read them yet. But I figured I could ask the professor to see if I could use Python instead. He agreed as long as I had a detailed report on my exact implementation. This is the reason the code I’m posting has little/no comments because I moved them out to a report.

Anyway, the partial Java program was around 100 lines and all it did was read the file and apply heuristics to board states. My finished Python project was around 100 lines and did (nearly) everything. Uncommonly, we had to present our projects to either the professor or the TA. It was a particularly strange event. I sat down with the TA and he asked why I used Python and I explained I used this as an excuse to learn the language. The program itself was to be hard coded to read a very specific file and he asked me why I didn’t just allow user input pick which file to open. This was odd to me because I’m very strict about how the guidelines are written for programs now after other classes which have nitpicked me about going too far above and beyond what I’m supposed to do. Also I assume it’s simply easier on the teacher to grade when they all perform uniformly.

8 puzzle I feel is slightly unfinished but I’m posting it anyway. I’m not sure if I’ll go back and make these changes but if I were to make changes they would be:

  • Allow user to choose the file to inspect
  • Alternately allow the user to simply type in board states and go with default goal state

I do have one other problem with this project which is that there are placement schemes that are basically unsolvable and my program will just churn forever on those. So I should probably also address that.

This project was developed in Python 2.4.4. Download link (right click and save as):

So combining my projects I’d only have a robot that could do your calculus homework and solve sliding puzzles which you could schedule for later execution. I guess that’s alright.