Trying out Box2D

Posted in Computer / Electronics Projects, Experiments, Graphics on December 29th, 2011 by Drew Gottlieb – Be the first to comment

Dominoes falling towards a house.

What is Box2D? It’s a free and open source 2D physics engine. It is developed with C++, and has fortunately been ported to many other languages, including Actionscript and Java. I was eager to try it out.

At the same time, I was eager to get more familiar with the new C++11 standard I’ve been hearing about (a.k.a. C++0x). So I made a small program to get a taste of Box2D and C++11 features. You can view and download the program here.

To use it, drag out a rectangle with your mouse. When you release the mouse, the rectangle becomes a object in the world. It is affected by gravity, and interacts realistically with other objects. If you happen to own a touch screen, you can press space to hide the mouse cursor. You’re welcome.

Mixing Box2D with SFML graphics was a quite tricky. To keep track of the objects, I created an std::vector of this struct:

(Environment.h:19 - rev e7bf977e)
19
20
21
22
typedef struct {
    shared_ptr<sf::drawable> graphic;
    shared_ptr<b2body> body;
} PhysicsObject;</b2body></sf::drawable>

There was a problem though: The Box2D world’s coordinates are 1 unit = 1 meter, and the Y-axis increases upwards. SFML coordinates, however, are more conventional computer graphics coordinates: 1 unit = 1 pixel, and the Y-axis increased downwards. To add to these troubles, the SFML view (sf::view) has to be able to scale (zoom) and move around the world.
read more »

Finally fixed my Git server

Posted in Announcements on November 12th, 2011 by Drew Gottlieb – Be the first to comment

I went through many headaches trying to fix the Git daemon running on my server. After being down for about 1-2 months, I finally managed to fix it. This means you can now clone my public projects again, as well as viewing each file on http://projects.minipenguin.com.

Storing digital data – on an audio cassette?

Posted in Computer / Electronics Projects, Data Manipulation, Experiments on September 18th, 2011 by Drew Gottlieb – 1 Comment

The cassette recorder hooked up to my computer's front audio ports

To those few of you that still follow my blog, I’m sorry for not updating it recently.

A few days ago my dad bought a simple audio cassette player/recorder to make a digital copy of an old tape recording he had of Pioneer 10 leaving the solar system. I had the opportunity to try something I always wanted to try: Storing data on an audio cassette. After some researching, I decided to use RTTY (Radioteletype). I found an awesome program called Digital Master 780, which is part of a freeware Ham Radio software package, Ham Radio Deluxe.

To connect the tape player, I needed to use two 3.5mm TRS cables, one for my computer to hear the cassette player’s output, and another one to send audio to the player’s audio input for recording.

My DIY 3.5mm TRS cable from two earphone cables.

Since I only own one cable, I made a second one by using two old earphone wires, wire strippers, two alligator clips, and tape. It looks messy, but it gets the job done!

For reading and writing digital data to the tape, I tried out several audio formats that the program could use. Due to the low audio quality that the tape can store, I was only able to get away with using RTTY. After further experimentation, I decided that these are the best settings I can use:

100 Baud, 170 Hz shift, 7 bits (ASCII), 2 stop bits.

Success! Here’s a video of me writing two paragraphs of “Lorem ispum” text to the tape:

read more »

My multiplayer platform game comes to life!

Posted in Computer / Electronics Projects, Platform Game on June 20th, 2011 by Drew Gottlieb – Be the first to comment

Players can see and chat with each other.

Do you remember that 2D SFML-powered platform game I was working on a while back? Well for the last two months I have continued to work on it, with the push of some friends in my APCS class. As I was trying to decide where to take the game in terms of gameplay, someone suggested I make it multiplayer. I thought this was a brilliant idea, due to my experience working with two custom Minecraft servers that were coded in C++.

I started by jotting down an outline for the protocol. Here’s the front and back. However, the game was in no fit state to be converted to a client or a server. Before I could write even one line of networking code, I would need to completely change the inner-workings of the game.

First, I abstracted resource files. Originally, I was having SFML load images directly from the file paths. In order to make it possible for the server to send resource files to the clients upon connecting, I would need to abstract resource files to locations within memory. I made a Resource class (Resource.h, Resource.cpp) to manage resources for me. The game would then call pf::Resource::GetOrLoadResource("resources/path/to/resource") to get an already-loaded resource with that path, or load it from the filesystem if it’s not already loaded. This way, if the client eventually receives a resource from the server, it can construct a new Resource object and then other parts of the code will load that resource instead of the local file. read more »

No progress on the platform game, but I finally released the source code!

Posted in Computer / Electronics Projects, Platform Game on April 19th, 2011 by Drew Gottlieb – Be the first to comment

A few months ago I was working on a 2D platformer game in C++ using the SFML library. While I still haven’t made any more progress on it, and potentially never will, I uploaded its full source code to my Redmine. It compiles perfectly on Linux, Windows, and OSX, and I provided some basic instructions for compiling on each platform.

You can browse the source here.

To get the source, clone its Git repository:

git://minipenguin.com/sfml-platformer.git

 

Hello, Vala!

Posted in Computer / Electronics Projects, Experiments on April 18th, 2011 by Drew Gottlieb – 2 Comments

Avi Romanoff recently introduced me to a new programming language called Vala. It borrows much of its syntax from C#, but it cross-compiles to C before using your system’s native C compiler to finish the job. This means you get a high-level language with managed memory and no runtime. While Vala itself is cross-platform, it really shines when used for Linux applications due to its fantastic GLib support.

Making GUI programs with Vala a piece of cake! Take a look at a short program I made as I was learning Vala:

using Gtk;
 
const int initial_windows = 2;
 
int main (string[] args) {
	Gtk.init(ref args);
 
	for (int i = 0; i<initial_windows ; i++)
		(new SmartWindow()).show_all();
 
	Gtk.main();
	return 0;
}
 
class SmartWindow : Window {
	private static int window_count = 0;
	private static int window_id = 0;
 
	public SmartWindow() {
		this.resize(200, 100);
		this.set_title("Hehehe");
 
		var id_label = new Label(@"$window_id");
		id_label.modify_font(Pango.FontDescription.from_string("sans 72"));
 
		var button = new Button();
		button.add(id_label);
		this.add(button);
 
		button.clicked.connect((t) => {
			(new SmartWindow()).show_all();
		});
 
		this.destroy.connect((t) => {
			if (--window_count == 0)
				Gtk.main_quit();
		});
 
		window_id++;
		window_count++;
	}
}</initial_windows>

Compile it with this command:

valac --pkg gtk+-2.0 program.vala

read more »

Text Generator – Generating Youtube comments from Youtube comments.

Posted in Computer / Electronics Projects, Experiments on April 7th, 2011 by Drew Gottlieb – Be the first to comment

In my AP Computer Science class yesterday we started a project that generated text from other text. To use it, one just has to feed it large amounts of text. It looks at every word in the text, and learns what words commonly follow that word.

Once it does that, it can generate sentences of a desired length that are, for the most part, grammatically correct. In fact, depending on what type of text it was fed, the generator may create sentences that seem to be typed by humans.

To get the most realistic sentences, the source text should be several paragraphs long. Several pages’ worth would be best. The source text should also be about one subject, and should have proper spelling and grammar. News and encyclopedia articles work best.

As an example, let’s feed it the three paragraphs I just typed. I’ll have it generate five sentences, less than fifteen words long:

Several pages' worth would be several paragraphs. To use it, one subject, and learns what type of text should have proper spelling! To get the source text from other. To use it, one subject, and encyclopedia articles work best! News and grammar!

You can view the project’s source from its Git repository online here. I even wrote a method to grab the comments from a Youtube video as the source text. For a laugh, I had it generate text from the comments on Justin Bieber’s music video, “Baby”. If you don’t mind the profanity it picks up, you can view the output here.

 

Short film, ‘Shattered’, complete! And guess what?

Posted in Film Projects, Shattered on March 29th, 2011 by Drew Gottlieb – Be the first to comment

A short film I’ve been working on with Zach Lowry, titled Shattered, is finally complete! Although we missed the original deadline for the Greenfield Youth Film Festival, apparently we weren’t alone. As a result, those running the film festival accepted films submitted early this afternoon. Shattered was uploaded just in time and should be included in the film festival now.

This was the first serious short film we have ever made, so there are plenty of mistakes. I will point out just a few: read more »

My short film, ‘Shattered’, has shattered…

Posted in Film Projects, Shattered on March 26th, 2011 by Drew Gottlieb – Be the first to comment

Zach Lowry and I have been working on a short film since December for the Greenfield Youth Film Festival. The deadline was 6 PM EST this past Friday (3/25). After editing all day and all night, we missed the deadline due to extreme technical difficulties.

Premiere Pro would freeze my entire computer indefinitely whenever I tried to render the film, although it never had an issue before yesterday.

So basically, it’s still not done and I don’t know when it will be. My school’s film festival is on April 8th, so we’re going to try to have it finished before then.

Started Making a Compiler

Posted in Compilers, Computer / Electronics Projects, Experiments on March 21st, 2011 by Drew Gottlieb – 6 Comments

Four days ago I decided to start making a proper compiler for a programming language, just for fun. I chose to call my new language Dava, which derives from Drew and Java. The language would have a C-style syntax and would compile to an intermediate bytecode. I haven’t decided whether to execute the bytecode in a virtual machine, or write a JIT compiler yet, however.

Here’s an example of the planned syntax:

1
2
3
4
5
6
7
8
use dava.system.System;
use dava.io.Stream;
 
func main() {
	Stream console = System.getStandardStream();
	console.writeLine("Hello, World!");
	System.exec("pause");
}

As you can see, it has a package system with default libraries. It’s largely based off of C#, with Incremental Garbage Collection.

Now, I was a bit lost on how to create a parser for a programming language, but luckily I discovered this Gem: MIT OpenCourseWare – Computer Language Engineering. It has already been a huge help in learning the inner workings of a compiler.

Well, as I said, I started it. Unfortunately, I will not be working on this project for a while. This Friday (3/25) is the day a short film is due, that my friend and I have worked on since December. Once I finish that, there is another project I want to begin. I fully intend to carry out that new project until the end, unlike almost all of my past projects. I won’t make the same mistake that I made on every project I’ve ever worked on: telling people about it. I only realized this recently, after reading a blog post by Garry’s Mod developer, Garry Newman, on why you should never tell people about a project you plan to take on: Don’t reveal your plans. You can see Derek Siver’s TED talk on this subject here.

If I manage to get near the end of the project in a few months, I’ll make sure to post about it. Additionally, I’ll make sure to post my short film on my blog when it’s done on Friday.