How can I draw geometric shapes, or other regular shapes, such as a gear, using macros or scripts? I'd like to experiment with creating games by combining elements, similar to geoDefense: http://www.criticalthoughtgames.com
It sounds like you're looking for snippet code in Scheme. This really isn't the place to find that. That aside...
Simple Polygons (triangles, squares, pentagons, & so-on)
These shapes are the easiest. All you need to do is find evenly distributed points along the circumference of a circle. There is 1 point per side, so a triangle will have 3 points on a circumference, a square will have 4, etc.
The seemingly "scary" part is getting the circumference coordinates but it's actually pretty simple. Here's some pseudocode:
Now that you have a simple way to find points, all you have to do is iterate your way around the circumference and draw a line from point to point.
If you combine these concepts with PhiLho's suggestion about creating SVGs, you can very easily script creation of a polygon.
Stars are only slightly more complicated than polygons. The process is the same, but you have 2 radii to deal with which means you'll have twice as many points. Notice that you need to use a smaller incrementing angle and you're adjusting it for each radii on each loop.
Again with PhiLho's excellent SVG idea:
Once you've figured out stars, you can apply the same concept to gears. You have 2 radii and you just have to alternate drawing 2 consecutive points on each circumference.
One more tip of the cap to PhiLho:
Please note this answer addresses both the question and the comments...
Some things just aren't easily scriptable. A gear isn't a "regular" shape. Basic shapes—squares, circles, and the like—are so simple to create in the apps you mention that a script isn't necessary unless you plan on doing some complex transformations with the shape afterwards. A gear, on the other hand, really isn't a scripted item in a graphics application; an image of a gear is made by hand, or a pre-existing image altered to suit particular needs, then exported to the required format per your project's spec and used accordingly during runtime.
You don't mention how far you are in planning your application, but I suggest you look at your project specs and start looking at how you intend to use the art in question, because your implementation will drive how and what you create in a graphics application if you create anything in Photoshop at all. Your framework of choice (per your example would most likely be Core Graphics or Cocos2D) may already have something to offer in terms of ready-made functions to create and manipulate simple to moderately-complex shapes.
Gears are common to games, not graphics applications. Graphics applications are more about providing the core tools needed to make any kind of gear imaginable. Games invariably require custom graphics that aren't easily scripted until you have a clear idea in mind of what you want to make, and even then, the workflow would still more than likely be similar to what @koiyu described.
Also, take into consideration that it may be (more than likely will be) faster to simply draw the gear by hand (or hire someone) than to find a programmatic way to do this.
Read the manuals?
Gimp can be scripted in Scheme (and some other languages like Lua). Inkscape can be scripted in Python, I think. Photoshop can be scripted in its own language (VBA?) too.
Beside, you can use any language to generate SVG files (assuming you learn the format...), and most of them (with the proper libraries) to generate bitmap images.
They are not really simple... But the hard part, coding, is done so that lot of shapes can be done without even coding.