Jump to content

Future Render Plugin: Martin Attractors

Recommended Posts

Example: n-martin.png

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



Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

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

me too :D:D

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.

Link to comment
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#?

Link to comment
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;

Link to comment
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 :) ...

Link to comment
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)

Link to comment
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

Link to comment
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

  • Create New...