Sign in to follow this  
Followers 0
AhmedElyamani

Circle Fractal

22 posts in this topic

Not bad at all.

 

Here's some feedback:

-It seems using '2 angles' produces a result that is virtually identical as using '1 angel'. If that is the indented (mathematically correct) result, perhaps get ride of "1" and just make the minimum option value "2".

-The "Fill Color" color wheel should be placed directly under the "Filling" checkbox. Also don't use both "Fill" and "Filling"; use one or the other.

-The "Brush Size" slider and "Outline Color" color wheel could be disabled when the "Outline" checkbox is unchecked. Likewise with the "Fill Color" color wheel and "Filling" checkbox.

-An anti-aliasing option wouldn't hurt either.

 

The source code would be appreciated for the sake of software freedom, if nothing else. :D

Edited by toe_head2001
0

Share this post


Link to post
Share on other sites

Good to see you back Ahmed! ;)

Will download - thanks.

0

Share this post


Link to post
Share on other sites

I love fractals. Any code with recursive loops gets my vote!

 

My suggestion; add more commands than DrawArc - go for the polygons.

0

Share this post


Link to post
Share on other sites

@AhmedElyamani! Thanks for the effort and plugin. 9gut87cp.gif

 

3zppfqmt.png

Edited by Seerose
2

Share this post


Link to post
Share on other sites

Well done Ahmed.

There is a small problem with the rendering because sometimes there are some empty stripes in the image (Win8.1 Paint.net 4.05)

 

post-79572-0-92003900-1431364553_thumb.j

 

 

1

Share this post


Link to post
Share on other sites

Nice to see you back too Ahmed, an interesting plugin too.

5187.gif

0

Share this post


Link to post
Share on other sites

Well done Ahmed.

There is a small problem with the rendering because sometimes there are some empty stripes in the image (Win8.1 Paint.net 4.05)

 

 

B) I do not speak English. I also wanted to say the same thing. I use google translator.

0

Share this post


Link to post
Share on other sites

Thanks for the great feedback , everyone!

 

@toe_head2001  I've applied all of your suggestions , except for disabling the UI items , as I have no idea how to do it.

@TechnoRobbo  I've now included the option to draw polygons (which turned out a bit trickier than expected :P  )

@medora & seerose I think it should be resolved now

 

Updated version is now included in the original post. You can make more fancy shapes like these:
shape3.pngshape4.pngshape5.png

 

Also here is the source code:

 

#region UICode
int Amount1 = 8; // [1,10] Angles
int Amount2 = 6; // [2,11] Vertices , 11 = Circle
bool Amount3 = true; // [0,1] Fill
ColorBgra Amount4 = ColorBgra.FromBgr(200,120,0); // Fill Color
bool Amount5 = true; // [0,1] Outline
int Amount6 = 1; // [1,100] Brush Size
ColorBgra Amount7 = ColorBgra.FromBgr(120,0,0); // Outline Color
int Amount8 = 100; // [0,200] Zoom
bool Amount9 = true; // [0,1] rotation
bool Amount10 = false; // [0,1] anti-aliasing
#endregion
//    
//DrawShapes (Graphics g ,Brush b,  Pen p, double x , double y , double r , ColorBgra c , ColorBgra cF ,bool fill,bool outline , int verts ,int rotVal)

int lengthdirX(int length, double dir)
{
	return (int)(Math.Cos(dir/180 * Math.PI)*length);
}
int lengthdirY(int length, double dir)
{
	return (int)(Math.Sin(dir/180 * Math.PI)*length);
}

void DrawShape(Graphics g ,Brush b,Pen p, int x , int y ,int r , bool fill, bool outline , int verts , int rot)
{

	if (verts>10)
	{
		Rectangle rect1 = new Rectangle(x - r , y - r , r*2 , r*2);
		if(fill)g.FillPie( b , rect1 , 0.0f , 360.0f);
		if(outline) g.DrawArc( p , rect1 , 0.0f , 360.0f );
	}
	else
	{
		if(fill)
		{
		
			System.Drawing.PointF[] shapePoints = new System.Drawing.PointF[verts];
			int length = (int)(2*r*Math.Sin(Math.PI/verts)),
				originalAngle= (180 - (verts-2) * 180 /verts)/2 ,
			angle = rot+originalAngle;
			shapePoints[0] = new System.Drawing.PointF((float)(x-lengthdirX(r,270-rot)),(float)(y+lengthdirY(r,270-rot)));
			for(int i=1; i<verts; i++)
			{
				float xx=shapePoints[i-1].X + lengthdirX(length , angle),
				yy = shapePoints[i-1].Y + lengthdirY(length , angle);
				shapePoints[i] = new System.Drawing.PointF((float)xx,(float)yy);
						angle  = (angle +originalAngle * 2)%360 ;
			}
			System.Drawing.Drawing2D.FillMode newFillMode = System.Drawing.Drawing2D.FillMode.Winding;
			g.FillPolygon(b,shapePoints,newFillMode);
		}
		
		if(outline)
		{
			System.Drawing.Point[] shapePoints = new System.Drawing.Point[verts];
			int length = (int)(2*r*Math.Sin(Math.PI/verts)),
				originalAngle= (180 - (verts-2) * 180 /verts)/2 ,
			angle = rot+originalAngle;
			shapePoints[0] = new System.Drawing.Point(x-lengthdirX(r,270-rot),y+lengthdirY(r,270-rot));
			for(int i=1; i<verts; i++)
			{
				int xx=shapePoints[i-1].X + lengthdirX(length , angle),
				yy = shapePoints[i-1].Y + lengthdirY(length , angle);
				shapePoints[i] = new System.Drawing.Point(xx,yy);
						angle  = (angle +originalAngle * 2)%360 ;
			}
			g.DrawPolygon(p, shapePoints);
		}
		
	}
}

void DrawShapes (Graphics g ,Brush b,  Pen p, double x , double y , double r , ColorBgra c , ColorBgra cF ,bool fill,bool outline , int verts ,int rotVal)
{
    if(r<=1) return;

    DrawShape(g, b,p, (int)x , (int)y,(int)r , fill , outline , verts ,rotVal);
    Pen newPen = new Pen(c);
    SolidBrush newBrush = new SolidBrush(cF);
    newPen.Width=Amount6;
    for(double Ang=360; Ang>=0; Ang-=Math.Ceiling((double)(360.00/(Amount1))))
    {
        DrawShapes(g,newBrush, newPen, x + (2 * r) * Math.Cos( Ang / 180 * Math.PI) , 
        y + (2* r) * Math.Sin( Ang / 180 * Math.PI) , r/3 ,c ,cF,fill,outline ,verts , (Amount9?(int)Ang:0));
    }
}

void Render(Surface dst, Surface src, Rectangle rect)
{

    Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    dst.CopySurface(src,rect.Location,rect);
    int CenterX = ((selection.Right - selection.Left) / 2)+selection.Left;
    int CenterY = ((selection.Bottom - selection.Top) / 2)+selection.Top;
    ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
    Graphics canvas = new RenderArgs(dst).Graphics;
    
    canvas.SmoothingMode = Amount10? System.Drawing.Drawing2D.SmoothingMode.AntiAlias:System.Drawing.Drawing2D.SmoothingMode.None;
    int BrushWidth = (int)EnvironmentParameters.BrushWidth;
    Pen myPen = new Pen(Amount7);
    SolidBrush myBrush = new SolidBrush(Amount4);
    myPen.Width=Amount6;   
    double r = ((double)Amount8/100.00) * Math.Min(selection.Right - selection.Left , selection.Bottom - selection.Top)/6;
	DrawShapes(canvas, myBrush,  myPen ,CenterX, CenterY , r , Amount7 , Amount4,Amount3,Amount5 ,Amount2 ,0);
   
    ColorBgra CurrentPixel;
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
        {
            CurrentPixel = src[x,y];
            dst[x,y] = CurrentPixel;
        }
    }
} 

 

 

circleFractal2.zip

1

Share this post


Link to post
Share on other sites

Don't forget to Dispose() unmanaged resources like pens and brushes.

Best is to use a using statement like

 

using (var pen = new Pen(...))

{

  // use the pen

}

1

Share this post


Link to post
Share on other sites

When rendering, I still see empty stripes that can seen be with or without using the anti-aliasing feature.

0

Share this post


Link to post
Share on other sites

Does this effect only work in 4.05 ?  I'm still using the old version and cannot find this effect after downloading.  It's such a cool effect and I'd really like to use it in a current project I'm working on.

Edited by Rainiqui
0

Share this post


Link to post
Share on other sites

Here I'm posting a version compatible with PdN 3.5.11 that I've been able to compile. You can find the effect under the Render menu (I hope that's correct because the source code doesn't specify otherwise).

 

Circle Fractal for PdN 3.5.11.zip

3

Share this post


Link to post
Share on other sites

Thanks so much Maximilian.  You have no idea how much I appreciate your kindness ! 

0

Share this post


Link to post
Share on other sites

Most welcome! Enjoy it! LaieA_060.gif

0

Share this post


Link to post
Share on other sites

When rendering, I still see empty stripes that can seen be with or without using the anti-aliasing feature.

 

Same here, using the latest version.

0

Share this post


Link to post
Share on other sites

 

When rendering, I still see empty stripes that can seen be with or without using the anti-aliasing feature.

 

Same here, using the latest version.

Try commenting out the last set of loops - lines 110 to 119 and rebuild. (the dst surface is already copied in line 96). Seems to work for me anyway.

The graphics objects should really be disposed as Midora suggested too.

Clever effect though! ;)

0

Share this post


Link to post
Share on other sites

circlefractals.png

 

Here is a little something for all you fractal lovers. I like the way it provides an ability to test the blending of different colors. Thank you Ahmed. Hope you come back soon.

 

0wEl3KD.png

2

Share this post


Link to post
Share on other sites

@AndrewDavid:star: I just love how colorful this is! Thank you so much. :cake: :coffee:

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0