mixster
2010-03-25 14:57:48
const
largeRadius = 200;
smallRadius = 98;
stepSize = 1;
radiusDif = largeRadius - smallRadius;
var
step, maxStep: Integer;
smallTheta, largeTheta, x, y: Extended;
graph: array [-largeRadius..largeRadius] of array [-largeRadius..largeRadius] of Boolean;
bit, a, b: Integer;
function GetFactor(a, b: Integer): Integer;
var
f, l: Integer;
begin
Result := a * b;
l := Trunc(Sqrt(Min(a, b)));
f := 2;
repeat
if ((a mod f) = 0) then
if ((b mod f) = 0) then
begin
a := a div f;
b := b div f;
Result := Result div f;
Continue;
end;
f := f + 1;
until (f > l);
end;
begin
step := -stepSize;
maxStep := Round(GetFactor(largeRadius, smallRadius) * 2 * Pi);
repeat
step := step + stepSize;
largeTheta := (step / (largeRadius * 1.0));
smallTheta := (step / (smallRadius * 1.0));
x := (radiusDif * Cos(largeTheta)) + (smallRadius * Cos(smallTheta));
y := (radiusDif * Sin(largeTheta)) + (smallRadius * Sin(smallTheta));
graph[Round(y)][Round(x)] := True;
until (step > maxStep);
DisplayDebugImgWindow(largeRadius * 2 + 1, largeRadius * 2 + 1);
bit := CreateBitmap(largeRadius * 2 + 1, largeRadius * 2 + 1);
FastDrawClear(bit, clWhite);
DrawBitmapDebugImg(bit);
for a := -largeRadius to largeRadius do
for b := -largeRadius to largeRadius do
if (graph[a][b]) then
FastSetPixel(bit, b + largeRadius, a + largeRadius, clRed);
DrawBitmapDebugImg(bit);
FreeBitmap(bit);
end.Increasing step size makes it more accurate, but greatly increases time to produce. More complex patterns are generated when the large radius and small radius share no common factors (doesn't have to be prime - 3^4 and 2^6 for example, 81 & 64, should produce interesting ones).
When larger sizes are used, it's usually a better idea to have a couple of factors in common to make sure it doesn't take forever and isn't so overly complex it just looks red - I usually make them even and adjust + or - 2 to create less or more complex patterns.