Most recent displayed first:
I’ve been coding in C99 quite a lot lately. I wanted to write down some of the tricks I’ve been using.
I don’t take credit for any of these ideas – I’ve either directly stolen these ideas from other coders, or rediscovered techniques that have probably been known for 40 years.
I will continue updating this document as I stumble across more useful tricks.
The code on this page is Public Domain, but this article is copyright according to the notice at the very bottom.
“That’s just the way it is!”
It amazes me how easily bad ideas fool humans.
I’ve been depressed lately. I decided to make a game to make me laugh and vent some steam. Enjoy!
Doesn’t it feel great to be right?
How do dynamicly typed languages allow any variable to hold any type? There are a few different techniques, but the one I use for sink is NaN-boxing.
Watching the children around me growing up, I am always amazed at the amount of pain they are forced to deal with. Illness, uncertainty, divorce, frustration, powerlessness, death…
A child experiences such extreme amounts of pain on a daily basis.
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.
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.
Writing Prompt from /u/raybreezer:
The world as you know it has managed to exist without any free will whatsoever. One day you realize, you actually have the ability to control your own actions.
Garbage collectors (GCs) feel like some sort of esoteric programming magic. What’s really funny is that a simple good-enough garbage collector is actually quite easy to write. The core functionality of Kong’s GC is only around 250 lines of C code.
What a shame that so many people lead the same basic life.
Each paint stroke is death.
One more moment, lost to the abyss, never to be seen again.
Miniscule fragments claw themselves forward, trying to outrun their inevitable fate: the gray sludge.
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.
Live-blogging my Ludum Dare 31 experience. Most recent entries are on top. I’ll plan to post about once an hour (while working). Permanent link here. You’ll have to manually refresh the page to get updates. Follow and comment on twitter @voidqk. All timestamps in EST.
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.
Rank (of 1493) Category Rating #13 Fun 4.11 #24 Theme 4.16 #34 Overall 4.00 #60 Innovation 4.00 #200 Mood 3.45 #269 Audio 3.22 #337 Humor 2.71 #484 Graphics 3.19
The #13 ranking in Fun just blows me away! My aggregate rating is 93.6% (+0.1% from last time).
Writing Prompt from /u/BS9966:
Suddenly various living dinosaurs start appearing all across the planet. No one knows how or where they are coming from.
Like last time, I analyzed the Ludum Dare results.
Alternatively, you can download the raw data here:
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.
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 :-).
Live-blogging my Ludum Dare 30 experience. Most recent entries are on top. I’ll plan to post about once an hour (while working). Permanent link here. You’ll have to manually refresh the page to get updates. Follow and comment on twitter @voidqk. All timestamps in EST.
I became slightly annoyed at the analysis and accessibility of the Ludum Dare 29 results. So I decided to write a program that would scrape all the pages and extract the necessary data.
You can now download the LD29 results in a convenient CSV or JSON format, here:
Or, for even more fun, I made a page that analyzes results:
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.
Rank (of 1493) Category Rating Percent Improvement #63 Mood 3.88 95.8% +31.9% #70 Humor 3.64 95.3% +22.0% #101 Innovation 3.88 93.2% +26.5% #116 Overall 3.76 92.2% +23.3% #148 Fun 3.60 90.1% +10.9% #149 Audio 3.50 90.0% N/A #227 Theme 3.64 84.8% +52.3% #551 Graphics 3.17 63.1% -8.0%
Average score: 88.1% (+23.0% improvement from previous entry)
If you’re curious, you can play my game, Inner Demons! Let’s dive into the postmortem…
Live-blogging my Ludum Dare 29 experience. Most recent entries are on top. I’ll plan to post about once an hour (while working). Permanent link here. You’ll have to manually refresh the page to get updates. Follow and comment on twitter @voidqk. All timestamps in EST.
I decided to challenge myself this weekend, with a faux-game-jam. I came up with a theme on Friday (Winter Olympics), and built Sled Drifter! over the course of the long weekend.
Rank (of 1284) Category Rating Percent #267 Fun 3.22 79.2% #343 Humor 2.61 73.3% #371 Graphics 3.17 71.1% #399 Overall 3.13 68.9% #427 Innovation 3.00 66.7% #464 Mood 2.81 63.9% #867 Theme 2.14 32.5%
Average score: 65.1%
If you’re curious, you can play my game, Diner Devil! Let’s dive into the postmortem…
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!).
Live-blogging my Ludum Dare 28 experience. Most recent entries are on top. I’ll plan to post about once an hour (while working). Permanent link here. You’ll have to manually refresh the page to get updates. Follow and comment on twitter @voidqk. All timestamps in EST.
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
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.