# Future Render Plugin: Martin Attractors

## Recommended Posts

Example:

I found this to be a nice render/fractal.

Heres a quote taken from http://spanky.triumf.ca/www/FRACTINT/ma ... _type.html

These fractal types are from A. K. Dewdney's "Computer Recreations" column in "Scientific American". They are attributed to Barry Martin of Aston University in Birmingham, England.

Hopalong is an "orbit" type fractal like lorenz. The image is obtained by iterating this formula after setting z(0) = y(0) = 0:

x(n+1) = y(n) - sign(x(n))*sqrt(abs(b*x(n)-c))

y(n+1) = a - x(n)

Parameters are a, b, and c. The function "sign()" returns 1 if the argument is positive, -1 if argument is negative.

This fractal continues to develop in surprising ways after many iterations.

Another Martin fractal is simpler. The iterated formula is:

x(n+1) = y(n) - sin(x(n))

y(n+1) = a - x(n)

The parameter is "a". Try values near the number pi.

Michael Peters has based the HOP program on variations of these Martin types. You will find three of these here: chip, quadruptwo, and threeply.

Is this possible to achieve in Paint.NET

##### Share on other sites

This is hard to code as the pixels aren't calculated in the standard x/y loop.

The result doesn't correspond to the image...

##### Share on other sites

This is hard to code as the pixels aren't calculated in the standard x/y loop.

The result doesn't correspond to the image...

Its ok, i figured how to achieve something alike

##### Share on other sites

This is hard to code as the pixels aren't calculated in the standard x/y loop.

The result doesn't correspond to the image...

I'm sorry to contradict but I think your wrong the formulas are right there with the x's and y's...

Yes it is calculable

##### Share on other sites

MiguelPereira: I'm no coder, but I'm assuming from MadJik's response that they are the wrong type of x/y's for plugin authoring, and that maybe more work is required than simply what is presented there.

That may have been phrased wrong, though I'm sure the point is still percievable.

##### Share on other sites

Yes I know but I had today an examination that had these kind of formulas to code, and i'm now trying to transpose these to codelab...

##### Share on other sites

Be sure to post your results. I'd be interested to see what you get.

Take responsibility for your own intelligence. 😉 -Rick Brewster

##### Share on other sites

Be sure to post your results. I'd be interested to see what you get.

me too

okay i'm having some trouble, I've written the code on Matlab to see if it worked, and i can see reults, but i'm not able to program on codelab.

##### Share on other sites

The effect in CodeLab needs this formulas to be reversed...(how?)

This is an excel file that shows some result:

##### Share on other sites

Aww how come i didn't remembered that? anyways thats pretty much what i got on matlab...

The effect in CodeLab needs this formulas to be reversed...(how?)

I got there too but still reversing them will be a headache...

EDIT: I know i should look for myself on book but how do you handle vector variables on c#?

##### Share on other sites

sorry vectors on c#, variables with dimension above 1

##### Share on other sites

Still not see the point, sorry, I'm programer (not math-er)...

But perhaps, this code of Martin's fractal could help you... Let me know.

```int Amount1=1500;   //[0,9999]a (/10)
int Amount2=1000;   //[0,9999]b (/10)
int Amount3=1000;   //[0,9999]c (/10)

bool init = false;
int sAmount1=-1;
int sAmount2=-1;
int sAmount3=-1;

void Render(Surface dst, Surface src, Rectangle rect)
{
double Xa1,Ya1,Xa2,Ya2;

Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
long cX = (long)(((selection.Right - selection.Left) / 2)+selection.Left);
long cY = (long)(((selection.Bottom - selection.Top) / 2)+selection.Top);
double a = (double)Amount1 / 10.0;
double b = (double)Amount2 / 10.0;
double c = (double)Amount3 / 10.0;

long MaxiP = 8000;

if ((!init) || (sAmount1 != Amount1) || (sAmount2 != Amount2) || (sAmount3 != Amount3))
{
init = false;
sAmount1 = Amount1;
sAmount2 = Amount2;
sAmount3 = Amount3;
}

ColorBgra PrimColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
int BrushWidth = 1;// (int)EnvironmentParameters.BrushWidth;

SolidBrush Brush1 = new SolidBrush(Color.FromArgb(PrimColor.A, PrimColor.R, PrimColor.G, PrimColor.);
Pen Pen1 = new Pen(Brush1, BrushWidth);
//Pen1.StartCap = System.Drawing.Drawing2D.LineCap.Round;
//Pen1.EndCap = System.Drawing.Drawing2D.LineCap.Round;

// Calculate the X,Y coords of the curve
double [] sx1 = new double [1 + MaxiP];
double [] sy1 = new double [1 + MaxiP];

if (!init)
{
sx1[0] = 0;
sy1[0] = 0;
for (int j = 1; j < MaxiP; j++)
{
int signx = 1;
if (sx1[j-1]<0) signx=-1;
sx1[j] = sy1[j-1] - signx * Math.Sqrt(Math.Abs(b*sx1[j-1]-c));
sy1[j] = a - sx1[j-1];
}
init = false;
}

// Copy existing image (source) to destination
for (int y = rect.Top; y < rect.Bottom; ++y)
for (int x = rect.Left; x < rect.Right; ++x)
dst[x, y] = src[x, y];

Graphics g = new RenderArgs(dst).Graphics;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.Clip = new Region(rect);
Xa2 = cX + sx1[0];
Ya2 = cY + sy1[0];
for (int i = 1; i < MaxiP; ++i)
{
Xa1 = cX + sx1[i];
Ya1 = cY + sy1[i];

g.DrawLine(Pen1, (float)Xa1, (float)Ya1, (float)(Xa1 + 1), (float)(Ya1 + 1));

Xa2 = Xa1;
Ya2 = Ya1;
}
}
```

##### Share on other sites

Thanks Madjic for trying to acomplish this.

I tried making it, its close but not close enough:

##### Share on other sites

doesnt a grid and wobble and rainbow work??

##### Share on other sites

doesnt a grid and wobble and rainbow work??

Thats practically wat i did. grid, sine waves,new layer, gradient (plugin), then overlay mode

##### Share on other sites

Still not see the point, sorry, I'm programer (not math-er)...

But perhaps, this code of Martin's fractal could help you... Let me know.

`...`

Well you're far more experienced than me at coding PdN's plugins and this one is well done... i was get there by a diferent prespective but your way is the actual working one so... Good Job

EDIT: SO can you improve this making it with a little more quality on the render process? I know I can't at least for now, I have to learn C# first, and study BoltBait's codelab tut's, so can you do it, the hard part it's already done, I can do the beta testing and so, if you need help ...

##### Share on other sites

I would like the reverse the formulas first (anyone?) to change and improve the code.

In this code version you could increase the number of points to calculate:

```long MaxiP = 8000;
```

Warning: it will take time and memory wth possibly error message (out of memory)...

MaxiP = 120000 (3min)

##### Share on other sites

The loop is :

for each point p, calculate the x and y values corresponding to the formulas and plot a point at x,y position.

To reverse it, I need :

for each x,y couple, calculate if the point is plotted.

##### Share on other sites

Would that work on improving the performance?

##### Share on other sites

I think so...

for each point p, calculate the x and y values corresponding to the formulas and plot a point at x,y position.

This could give several times (many) the same point (with the rounded values)...

##### Share on other sites

Can you work on a third surface besides the destination and source ones?

cause you could print the calculated pixels onto the third one to keep tracking of which were already plotted

EDIT: Nah forget it it would take way to much memory

##### Share on other sites

Some plugins are using this method already!

It's not really so much more memory, but it won't reduce the calculation time...

##### Share on other sites

Well it's late but I'll see if I can dig up any numerical method to enhance the calculations, keep in touch

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×