Distributed Raytracer

23rd of August 2009

I've just released the project I've been working on for the last few days. It's a collaborative raytracer, based on my new between-browser map reduce system.

It's still young, but have a play and tell me what you think.

Permalink
Posted by Peter Braden. — Modified 23/08/2009 (6 comments) Tagged: code distributed computing graphics jquery

Tracing Rays

20th of August 2009

I like coding. In fact I like it so much that every now and then I make something completely pointless and yet quite cool. That way it feels more like art and less like business.

So without further ado:

Javascript Raytracer

This only works in a modern browser that supports the <canvas> element. For example Firefox 3.5+, Safari or Chrome.

The raytracer is pretty processor intensive - I recommend you run it in Google Chrome which has the fastest javascript engine I've found. Also tested in Firefox/Safari. Will certainly not work in IE.

About

I've always been interested in Ray-Tracers - I spent hours playing about with Povray back in high school — the idea that you can make such realistic pictures algorithmically fascinates me. I've started writing a couple of my own over the years, but always shelved them around when I hit a nasty vector issue.

Vector maths is tricky.

But when I opened up my text editor this morning to play with the canvas element some more, I knew that something big was in order, bigger than pong, bigger than tetris. I was going to write a ray-tracer in the browser in the canvas element.

And 8 hours later it's done. Nothing revolutionary, but satisfyingly realistic.

View the page source to check out the code - there's only about 200 lines of it and it's pretty simple to follow. It's simple Phong shading on sphere and plane primitives.

I had originally planned to distribute the computational load between multiple browsers using a cross-browser map-reduce. But I think that's a project for another day.

I'm not the first to make a canvas based ray-tracer. It seems there's other people who like pointless code too.

Permalink
Posted by Peter Braden. — Modified 20/08/2009 (0 comments) Tagged: code jquery

Spies Have Cool Maps

15th of August 2009

So following on from yesterdays Call of Duty text effect, I had a little play around with the new Google Maps API. Here are the results - a little pointless maybe, but whatever.

Like a lot of my experimental projects, this is not thoroughly tested (works in Firefox 3.5), and almost certainly won't work in Internet Explorer. Use a proper browser.

Permalink
Posted by Peter Braden. — Modified 15/08/2009 (0 comments) Tagged: code jquery

Call of Duty Text Animation

14th of August 2009

I don't play a lot of video games, but my brother does, and every now and then I get hooked on one of his games. This afternoon I completed Call of Duty 4, which is surprisingly engrossing — shooting people in the head is quite addictive.

One of the things I liked most about the game was the visual experience of the briefing/loading screens. The designers have used all the typical elements that have become associated with this spy/military thriller genre — the aerial maps, wire-frame fly-throughs, mountains of irrelavant data. All the cliches are covered.

One particular effect that caught my eye was the fade-in/fade-out on the name of the level. It seemed very reminiscent of Bourne Identity/24. I thought I'd give a go at recreating it in javascript.

Here's the code — I've wrapped up the fade-in into a jquery extension:


$.fn.stealthIn = function(callback){
	this.each(function(){
		
		var content = $(this).text();
		$(this).text("").css({
			'color' : '#9f9',
			'text-shadow' : '#0f0 0px 0px 5px',
			'font-family' :"Bank Gothic"
			}).show();
		
		var i = 0;
		var j = 1;
		var x = $(this);
		var t = setInterval(function(){
			var cont = x.text();
			
			if (j==3){	
				x.text(cont.substr(0,i) + content[i]);
				i+=1;
				j=0;
			}else{
				x.text(cont.substr(0,i) + String.fromCharCode(
					1072 + parseInt(Math.random()*20)));	
				j+=1;
			}
					
			if (i == content.length){
				clearInterval(t);
				if (callback){
					callback();
				}
			}	
		}, 20);
		
	});

}


// Use it like:
$("#some-element").stealthIn();

And here's a live example:

Incoming Transmission: Targets Neutralized

You'll only get the full effect if you have the font "Bank Gothic" on your computer - which I believe is bundled on a mac. Sorry PC users!

Permalink
Posted by Peter Braden. — Modified 14/08/2009 (0 comments) Tagged: code jquery

Pong

9th of August 2009
This only works in a modern browser that supports the <canvas> element.

Some more <canvas> experimentation. Basic pong rules, but the AI should improve as your score increases…

Due to the cutting edge technology in this demo (canvas.fillText), it only works in Firefox 3.5+ and possibly the beta version of Safari 4.
Permalink
Posted by Peter Braden. — Modified 9/08/2009 (1 comment) Tagged: code jquery

Newest Items

Photography

Recent Writing

Subscribe

Like what you see?

Subscribe to the RSS feed and be notified whenever there's something new…