SQUARISM addicted to pixels

Parabola

Posted on April 15, 2007

parabola sketch

My goal was to create the curves above. I knew if I could draw it then I could move a box or game object along that path. It took me about two weeks of casual time and many math questions posted to yahoo answers.

The problem is, implementing a math formula in C++. It's just not as pretty as the equation and any algebra tricks are hard to express in code. Not to mention remembering algebra period. ?

Eventually, I ended up with this. I specified the starting point, the ending point and how tall I want the curve. A series of horrible equations builds the rest into a vector of x,y point structs. There's an LOD thing too that says how pretty the curve should be.

parabola3

Of course, it's pixilated and kinda ugly. I tried anti-aliasing it but it doesn't look much better. Also, I might have some math issues because in some places there seems to be small humps. I might be running into precision problems again. ?

Overall, I'm pretty exhausted. I don't know what my next project will be, I don't know if I want to make more of a game that's interactive instead of these little graphics tests.

Also, C++ is pretty ugly imo. It's used everywhere, I understand but I might pick up an actionscript book and see how much of this graphics stuff could be wrapped up in flash. I bet you can do some cool low-level drawing in flash; and then it'd be more 'portable' than an OSX app.

Anyway ... it's a thing of goddamn beauty for now. Except the code, which is ugly, untidy and probably doesn't compile by itself. I'll update it so it's stand-alone.

Filed under: C/C++, GameDev 1 Comment

lstat test

Posted on April 10, 2007

Following an interview question that was extremely hard I went to `man lstat' and tried to code up a test just based on system documentation. It was not entirely successful, however after a tip-off from an online resource I came up with this.

Filed under: C/C++, Unix Continue reading

Animated Box

Posted on April 1, 2007

I'm very, very early on in the effort of this graphics/game test. But essentially I wanted to write down where I'm at with Xcode, OpenGL and learning C++.

Learning C++ by starting with OpenGL is very stupid. I admit this. It's the wrong way to start out. It's like learning how to walk by jumping out of a Dodge Viper. But I want to get beyond the Hello World books and after trying for two or three years in my limited spare time, I'm finding that being thrown into the fire is somewhat motivating. I learned Java the same way (not that I'm a master of that either), I gave myself a goal that I really wanted to accomplish and the rest just fell into place because I couldn't think about anything else.

Such is my animated box. I want to move a box in a really smart way. Not just some Box.setX(i++); Box.setY(j++) in the main() method but something smarter that would enable me to move two, four or one-thousand boxes in the future.

animated box

More coming...

xcode glclearcolor

Chapter 4

Posted on January 21, 2007

Going through the Oreilly book Practical C++ Programming, which may be an arguable title, and I'm just trying to go through all of the examples and save them somewhere so I know where I left off the next time I'm feeling recklessly productive.

Specifically, Chapter 4 asks

Exercise 4-2: Write a program to print a block E using asterisks (*), where the E is 7 characters high and 5 characters wide.

Of course the easy way would be to just print out a bunch of strings. But I consider that cheap. So I played around with struct and typedefs but I don't know what the hell I'm doing with those so I instead forced myself to learn about passing by value vs. passing by reference.

First, the function makeE() creates an integer array which in my world of goals could be a game model, or x,y,z points for some game object. Then printE() prints out the array, but only an array of 7. If I wanted to do this whole thing much better I'd use a vector.

It's rough shifting gears back to C++. I don't know if I'll ever get really good with it and be able to get to the fun stuff. You can see below that another version just printed out way too many *'s.

e messedup

/*
 *  4-2.cpp
 *  Practical C++ Exercises
 *
 *  Created by Chris on 1/21/07.
 *  Copyright 2007 hexameter.com. All rights reserved.
 *
 */
// write a program to print a block E using *, where e is 7 high and 5 wide.
#include <iostream>

void makeE(int int_array[])
{
	int_array[0]=5;
	int_array[1]=1;
	int_array[2]=1;
	int_array[3]=5;
	int_array[4]=1;
	int_array[5]=1;
	int_array[6]=5;
}

void printE(int e[])
{

	for (int i = 0; i < 7 ; i++)
	{
		for (int j=0; j

But then finally, it worked suddenly after I made some adjustments.

e success

This is all just beginner stuff. :(

Filed under: C/C++ No Comments

SWAT

Posted on March 3, 2006

pagination
Swat, a nice PHP toolkit at silverorange.com has caught my attention a few times.

First, they (or someone in their group) designed the firefox and thunderbird vector icons. Next, they've released a few webapps (PHP). I ran into a demo they have online that showcases some widgets they've built.

It's a fantastic little page full of good UI components that would really help out usability. Unfortunately, I'm not using PHP really anymore but I hope to find (or build) something similar to this in Ruby and Java. And not ugly components either, similar quality. I'm sure there are widgets and components that are not up to this quality.

Filed under: PHP No Comments

x.succ

Posted on March 3, 2006

x.succ

[ "H", "A", "L" ].collect {|x| puts x.succ }

Prints out:

HAL, plus one letter up, equals IBM. Pretty funny.

Filed under: Ruby No Comments

Dave Thomas on Rails

Posted on November 19, 2005

dave_thomas.jpg

A while ago I ordered a Ruby book entitled, "Programming Ruby by Dave Thomas" off amazon (bookpool was close on price). I read the first few chapters, got hung up on syntax and my interest was peaked.

One week later, a coworker says "Hey! Dave Thomas is speaking at NovaJUG!" (northern virginia java users group). It was uncanny and I had to go. To be fair, the opening act (as he called it) was on PMD Applied, by Tom Copeland. He has written a book on PMD. Essentially what I got out of it was a normalization process for code. No duplicate code, no logical duplication and a Java tool to help detect it all. I think Tom discredited himself a bit (understandably) by feeling like everyone was there for the Ruby bits. This was only mostly true for me. I wanted to see what the Java end of the JavaJUG was like. I enjoyed his presentation although I felt he could have been more confident even if he was just the 'opening band'. Tom knows his stuff for sure.

Dave Thomas got up and explained what Ruby on Rails is, what Ruby is and why he's even attempting to give his talk to a Java Users Group. He explained that his talks are becoming more and more popular at Java seminars. Why? Probably because it's not a 300lbs hammer like Java is. He had a good point about Programmers aren't Programmers anymore. They are "Java Enterprise Programmers with XYZ framework experience". A carpenter with only one tool.

Ok point taken. But onto the gritty details. Where does Ruby not work? Where does it break? How can it be perfect? He did a good job of answering all of these common questions and explaining that Rails works for an estimated 70% of projects and the remaining 30% it might work 50% of the time if you changed the requirements or pushed back on the customers.

A really depressing part of the talk was when he explained that this Java programmer he talked to rewrote an app in Rails at night and in his free time. The XML configuration of his Java app was 400+ lines, just the XML config. Took him 4 months for the Java piece. The same app in Ruby was less than 400 lines of Ruby code and he did it in 4 nights (spare time). Now, obviously if you rewrite something you already know requirements, how the app works, domain experience and all the other stuff you already did. So Dave said "double the time! why not! 8 days!".

I'm still not convinced. So he starts talking about JCP. Said something like, "Take a good idea and put it into a Java committee where a bunch of vendors all influence the direction of a new spec to make the most money. JSF was written so humans can't write it! So you'd have to buy a tool! Sun has killed Java. If you look at C# and Java5, it's a checkbox contest. Generics, check. Autoboxing, check."

Ruby has configuration files that are written in Ruby. No XML (unless you want to). Ruby makes a lot of assumptions to make your life easier. You can override the assumptions but could as easily take the defaults to make it quicker.

Dave then started coding on his mac laptop and we all watched. He used MySQL as a database, YourSQL as a MySQL frontend (to create tables quick), TextMate as a text editor (did Ruby syntax autocompletion a bit) and a standard OSX terminal. He created a database table and with one line of code 'scaffold' had the table on the web with 'show', 'edit', 'destroy' functionality per row. Basic functionality. He had run some scripts to generate the controller (comes with unit test). But what he hadn't done was the killer. He had URL rewriting (Rails does that), he had a simple database mapping (Rails I think) and he had a server running on port 3000 with no jboss or tomcat config deployment etc.

Everyone was excited. I was excited.

He talked about how you can freeze your Ruby interpreter to your vendor/ directory within your development directory. So if a new version of Ruby or Rails comes along you aren't screwed if you try out the new version.

He talked about a free ruby tool called SwitchTower that lets you control versions of Ruby apps (not Ruby only) on deployment. SwitchTower can roll back versions if a bug is found. Looks neat.

He continued on at the end by talking about the future of Ruby. He talked about JRuby. Ruby running a Java VM. You can call java objects from Ruby natively, way cleaner than that JNI crap. He talked about possible verions of Ruby with bytecode like Perl6. It's all very new.

It was a great talk, he graciously signed my book. Dave Thomas is excited, honest, charmingly English (he forced him to pronounce status like us yanks -- Stah-tuss vs Stay-tuss) and approachable. I could tell he's done lots of these talks, he's invested in Ruby, he's selling his book. But that's his job for now. Ruby speaks for itself upfront and I'm just going to have to explore the rest. Dave Thomas and others were also invested in Java. But they aren't throwing it away (maybe some are). His point is to not use Java for everything. Not to use Ruby for everything. Anyone who says one tool to bind them all is a salesman.

Don't use one tool for everything. If I want to quickly parse XML in Java, what do I have to do ... get Xerces, Xalan, a million jars with the right version. XML, Webservices, Unit Tests, AJAX, real object oriented stuff is just built into Ruby. It's new. It's improved. You might like it for a side tool project. Or a Java side-helper.

Don't drop Java he said. Don't force and sell this to your boss. Try it out. Make an app quick and when people ask, "how the hell did you do that?" you say, "oh it was nothing".

What I'm doing.
I'm reading his book. I'm going to try it out. I'm going to see if I can write something quickly and use all these neat features. So far the syntax is weird, I miss my curly braces. But even without a book the commands and scripts are fairly self explanatory. Emerging rails was a cinch under gentoo:

ACCEPT_KEYWORDS="~amd64 ~x86" emerge rails

And then I just mkdir "ruby" and "cd ruby" and "rails myproject". I ran "script/server" and I had a rails server running on port 3000. That was easy. Like 5 minutes.

The rest of it is the kicker I think.

Filed under: Ruby No Comments

Data Structures Book

Posted on September 19, 2005

On a slashdot thread I was discussing whether I should roll my own data structure or try to use one of the many, many Sun data structures.

Someone recommended this book.

Filed under: Java No Comments

Spring Framework

Posted on August 4, 2005

Researching this Spring Framework. Most interesting so far is it's touting of being modular. As in, you might only use it for a single feature and it wouldn't be bloated.

Filed under: Java No Comments

distcc is cool.

Posted on November 18, 2004

Distcc is a distributed C/C++ compiler. You can easily use a bunch of machines' power to compile stuff. The setup isn't bad at all. It's just a non-root network service.

Gentoo.org has some nice instructions on setting up distcc for builds. Here, we have 2x Pentium 3 machines and 1x dual xeon helping me build nethack. Don't have numbers on how much faster it was but it seemed faster. Most makes/compiles are annoyingly slow, this seemed ok.

distcc_thumb.jpg

Filed under: C/C++ No Comments