views:

68

answers:

2

I need to be able to accept elliptical(computed) brush parameters such as spacing, hardness, roundness, angle and diameter and then compute a bitmap image based on those attributes.

Does anyone know the algorithm(or where I can find it) to do this? I have limited experience in graphics programming and I have been unable to find it so far.

+1  A: 

This is the kind of thing you want to use a library for, most likely the Java 2D API. It includes facilities for fills, strokes, transforms, and filters. Its model is similar to many libraries in that you trace out a path with operators moveTo and lineTo or curveTo, which are abstracted in shapes like Ellipse2D; and then you fill or stroke the resultant path with a paint operator. I highly recommend reading the Java 2D tutorial and understanding how the different parts fit together.

I would take roughly the following steps to create this drawing:

  • Compute the final dimensions of the rotated ellipse after blurring.
  • Create a BuferredImage of that size and call its createGraphics method to acquire a drawing context.
    • Rotate the graphics object
    • Draw the ellipse
    • Fill it with black
  • Implement the Gaussian blur filter. This is not built in to the API, but it includes a framework for doing filters called ConvolveOp, and you can find an algorithm for computing the Gaussian kernel in Java.
  • Apply the filter to the image, and then return the results.

Another option might be Apache’s Batik SVG library, since you can declaratively express the drawing you want (including transformations and filters) and have it rasterized for you.

jleedev
A: 

An extremely useful list of formulas for an ellipse can be found here: http://xahlee.org/SpecialPlaneCurves_dir/Ellipse_dir/ellipse.html

Think about what each formula implies about an individual pixel in your bitmap (whether it's in/out of the ellipse, whether it's near the edge) and which properties would be useful to you.

eplawless