Coding: Bring the Noise

%26lt;0011 Em

Archive for the ‘Projects’ Category

C#/XNA: Heatmaps

leave a comment »

I ported the Iterative Diamond-Square Algorithm from Python, and added a few features.

random_generation

The biggest addition is interactivity, and the biggest optimization is using shaders for updating/drawing.  If I have time in the next few days, I might try to move the random generation to a shader.  Shouldn’t be to hard, and it would be a significant gain in speed.  In the meantime, I’ve got generation running on a separate thread (thank you C#’s anonymous functions!)

The code is available on Github.  Follow the break for usage instructions, screenshots, and code highlights.

Read the rest of this entry »

Written by delwinna

May 7, 2012 at 10:04 pm

Posted in Projects

Color Profiles

leave a comment »

Today’s post isn’t groundbreaking (are they ever) just a wrapper around a nested dictionary.  Turns out this is a really convenient pattern in general – I’m using a more general two-key dictionary in the engine that was built off of the below code.

I got sick of reading lots of this:

Color baseColor = defaultBaseColor;
if(Hostility == Hostility.Friendly)
    baseColor = Color.DarkGreen;
else if (Hostility == Hostility.Enemy)
    baseColor = Color.DarkRed;
BasicShapes.DrawSolidSquare(batch, Position, baseColor, SideLength, Rotation);

Now, the rendering code reads:

public class GameObject
{
    ColorScheme ColorScheme;
    Hostility Hostility;

    // ...

    protected Color LayerColor(LayerType layer)
    {
        return ColorScheme[Hostility, layer];
    }

    public virtual void Draw(SpriteBatch batch, RenderPass pass)
    {
        // ...
        BasicShapes.DrawSolidSquare(batch, Position,
                LayerColor(LayerType.Base), SideLength, Rotation);

        var InnerPos = Position + new Vector2(SideLength / 2);
        var SmallSide = SideLength / 2;
        BasicShapes.DrawSolidSquare(batch, InnerPos,
                LayerColor(LayerType.Highlight), SmallSide, Rotation);
    }
}

Source after the jump.
Read the rest of this entry »

Written by delwinna

March 23, 2012 at 4:17 pm

Posted in Projects

Old code: “playing with boids” OR “this would be a cool music visualizer”

leave a comment »

As I was sorting through my old code, I found this “gem” from my visual python experiments last year in college.  The code and instructions are at the end of this post.  I’d recommend reading the rest of the post before watching the video, otherwise it might not make sense.

boids

Playing with boids (you can jump to 0:45)

Attractor jump at 2:05 (which is pretty freakin cool)

I particularly like how they respond to the attractor (blue ball) once they’ve settled into an orbit- it’s like an amoeba reaching out and surrounding a smaller organism and then devouring it all at once.

There’s some music in here from this playlist.

Read the rest of this entry »

Written by delwinna

January 22, 2012 at 4:03 am

Posted in Projects, Python