Just in, from "The Economist" magazine: Sales of Ayn Rand's Atlas Shrugged are booming as aficionados compare the events described in the book to our current economic malaise.
Friday, February 27, 2009
Friday, February 20, 2009
In the past, whenever I've wanted graph paper I've always written a simple program to draw horizontal and vertical lines to form the grid size I sought, then printed out the results. I was thinking about adding a little web app to jlion.com to do this as a public service, then found this site: http://incompetech.com/graphpaper/plain/. This guy has done a wonderful job and his web apps are much more comprehensive then mine would be.
Thursday, February 19, 2009
I've been working on a jigsaw puzzle application for a while now, and you can view the results here: http://www.jlion.com/tools/jpuzzle.aspx.
I learned a few things while working on this. Really, creating the jigsaw app was a fun puzzle in itself. The app divides an image into squares and then randomly designates each side of each square as "in", meaning the knob points into the square, or "out" meaning it points out into the adjoining square and that the adjoining square therefore has an "in" knob on the same side. Once the layout of the squares has been determined, I build a path the shape of each square (knobs included) and overlay it on top of the source image. The part of the image inside the path is then copied to a buffer, and from there placed in the PDF document.
There were two challenges. The first was understanding how the AddBezier function in the Drawing2D namespace works. The app uses Bezier curves to create the "knobs" of the puzzle. Each curve has a start and end point, and two control points but they don't work they way you might think if you're unfamiliar with the math behind Bezier curves.
When you look at a Bezier in a GUI app such as adobe illustrator or photoshop you see a series of connected points. Each point has two control "handles" that you can make longer or shorter. The handles, however, are constrained so that they always point 180 degrees from each other.
This constraint is not enforced in Drawing2D. You can make the ending control point of the previous line and the starting point of the next line point in completely different directions. I did this at first, until I realized what was going on and took steps to ensure that the control points were properly rotated.
AddBezier is a method of the System.Drawing.Drawing2D.GraphicsPath object, and GraphicPath objects are quite powerful. Not only can you use these to draw lines and fill regions, but you can also use them with the System.Drawing.Graphics SetClip method.
The SetClip method restricts graphics operations to within the area defined by a path. By using SetClip and a region defined by a path, you can copy part of an image to another image.
To create the image of a single puzzle piece, I created a path describing the four sides of the piece, then used the SetClip method to impose that path on the original image. I could then use the DrawImage method to copy only the part of the puzzle to another buffer image of the same size (but with a white background). I used the path again to draw a dotted line around the copied image then used DrawImage again to copy a box containing just the puzzle piece to a second image. This image I could then include in the PDF document.
Anyway, a fun project.
I learned a few things while working on this. Really, creating the jigsaw app was a fun puzzle in itself. The app divides an image into squares and then randomly designates each side of each square as "in", meaning the knob points into the square, or "out" meaning it points out into the adjoining square and that the adjoining square therefore has an "in" knob on the same side. Once the layout of the squares has been determined, I build a path the shape of each square (knobs included) and overlay it on top of the source image. The part of the image inside the path is then copied to a buffer, and from there placed in the PDF document.
There were two challenges. The first was understanding how the AddBezier function in the Drawing2D namespace works. The app uses Bezier curves to create the "knobs" of the puzzle. Each curve has a start and end point, and two control points but they don't work they way you might think if you're unfamiliar with the math behind Bezier curves.
When you look at a Bezier in a GUI app such as adobe illustrator or photoshop you see a series of connected points. Each point has two control "handles" that you can make longer or shorter. The handles, however, are constrained so that they always point 180 degrees from each other.
This constraint is not enforced in Drawing2D. You can make the ending control point of the previous line and the starting point of the next line point in completely different directions. I did this at first, until I realized what was going on and took steps to ensure that the control points were properly rotated.
AddBezier is a method of the System.Drawing.Drawing2D.GraphicsPath object, and GraphicPath objects are quite powerful. Not only can you use these to draw lines and fill regions, but you can also use them with the System.Drawing.Graphics SetClip method.
The SetClip method restricts graphics operations to within the area defined by a path. By using SetClip and a region defined by a path, you can copy part of an image to another image.
To create the image of a single puzzle piece, I created a path describing the four sides of the piece, then used the SetClip method to impose that path on the original image. I could then use the DrawImage method to copy only the part of the puzzle to another buffer image of the same size (but with a white background). I used the path again to draw a dotted line around the copied image then used DrawImage again to copy a box containing just the puzzle piece to a second image. This image I could then include in the PDF document.
Anyway, a fun project.