Articles Tagged: javascript

Most recent displayed first:

  • Polygon Clipping (Part 2)

    My previous polygon clipping tutorial dove into the Greiner-Hormann clipping algorithm. Unfortunately, this algorithm fails at common cases… so let’s revist the problem and try again.

    The F. Martinez 2008 algorithm handles coincident edges (unlike Greiner-Hormann), but it still has some minor goofiness. Let’s solve this problem once and for all. more

  • Polygon Clipping (Part 1)

    Polygon clipping is an interesting problem: how do you intersect, union, or diff two polygons?

    The Greiner-Hormann clipping algorithm is quite beautiful and intuitive. Let’s dissect it and take a look. more

  • Genetic Algorithms

    In my Ludum Dare 31 entry, Bunnies!, I used a very simple genetic algorithm to breed bunnies. It can seem like magic at first, but genetic algorithms are very simple at their core. more

  • Shunting Yard (Part 3)

    Let’s continue adding to our Shunting Yard code base.

    In Part 2, we created operator precedence. This allowed us to delay application of operators indefinitely, using a stack. Next, we’ll focus on adding parentheses, so that the end-user can manually override precedence.

    Series: Part 1, Part 2, Part 3, … more

  • Shunting Yard (Part 2)

    Let’s continue building a general purpose Shunting Yard algorithm.

    We left off with bare-bones skeleton that implements a shunt to delay building of the abstract syntax tree (AST). Our skeleton left a lot to be desired. For this article, we’ll implement operator precedence.

    Please read Part 1 first, since the code here builds directly on the source from that article.

    Series: Part 1, Part 2, Part 3 more

  • Procedurally Generated Planet Textures

    For my Ludum Dare entry, I procedurally generate the textures for the planets. In the game, my math is a little off, and I didn’t have time to derive the correct formula – but now, with unlimited time, I can think a little more clearly :-). more

  • Shunting Yard (Part 1)

    The Shunting Yard Algorithm is, quite possibly, my favorite algorithm. It transforms a series of tokens into an abstract syntax tree, taking into account operator type, precedence, and parenthesis.

    Through the next series of articles, I want to build a general purpose expression parser using the algorithm. By the end, we’ll have an algorithm that can be easily extended to add many different types of operators… any arity (unary, binary, ternary, etc), prefix, infix, and postfix.

    Series: Part 1, Part 2, Part 3 more

  • Two-Dimensional Bin Packing

    Two-dimensional bin packing turns out to be quite a pickle.

    I was introduced to the problem as a 13 year old. My Dad’s friend, Keith, noticed I was taking a knack to programming, and wanted to see if I could help him. Keith was (and still is) a carpenter.

    Keith wanted me to write a program where he could input a list of shapes, and the program would figure out the best way to cut a board of wood into those shapes, while minimizing scrap wood. Seems reasonable.

    My 13 year old mind quickly exploded… I couldn’t figure out one simple, obvious way to do it. Eventually I gave up, to my ego’s dismay (and Keith’s disappointment!). more

  • How to Fix Banding in Gradients

    Photoshop’s gradient algorithm is quite disappointing. It is notorious for creating gradients with banding. Here is an example, attempting to create a gradient from #222 to #333:

    Photoshop’s Gradient with Banding


    Can you see it? If you look closely, there are vertical “lines” in the image where the color changes. This is incredibly easy to fix algorithmically - but very difficult to fix any other way. more