Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #3041

Re: A Question About Fractals

From "Chris M. Thomasson" <no@spam.invalid>
Newsgroups comp.programming
Subject Re: A Question About Fractals
Date 2013-02-18 15:53 -0800
Organization Aioe.org NNTP Server
Message-ID <kfuetu$msp$1@speranza.aioe.org> (permalink)
References <b3b13a29-514f-43b1-9ca7-03ae8189d635@gu9g2000vbb.googlegroups.com>

Show all headers | View raw


"Brian"  wrote in message 
news:b3b13a29-514f-43b1-9ca7-03ae8189d635@gu9g2000vbb.googlegroups.com...

> Hi, I was reading an article about fractals, and the article says that
> fractals by themselves have no shape or form, but that computers can
> be used to convert fractals into images.  What exactly is a fractal?

Self-similarity across various levels of scaling. Think of repeating 
patterns that can curve around and repeat themselves at a slightly lower 
scale until it hits critical limit. Critical limit can be how far you are 
willing to go wrt the infinitely repeating pattern. For instance, a simple 
fractal could be something as simple as finding the points of intersections 
between a set of cirlces. Then simply draw smaller circles around said 
points. Repeat!

FWIW, and since this is comp.programming, here is a retarded first attempt 
at creating such circle intersection fractal, presented in AS3 of course!


__________________________________________________________________________
package
{
    import flash.display.Sprite;
    import flash.events.Event;

    /**
     * ...
     * @author Chris M. Thomasson
     */
    public class Main extends Sprite
    {

        private var mcr1:Number = 3;
        private var mcr2:Number = 3;



        public function
        prv_draw(i:uint, cmp1:Array, cmp2:Array):void {

            if (i > 33 || ! cmp1 || ! cmp2) return;

            //cmp1[2] * 314628
            //.5 / (i / 22)
            // c=(i + 1) * (cmp1[2] * cmp1[2]) * (cmp1[2] * cmp1[2]) * 
314628
            this.graphics.lineStyle(.277 / (i / 22),
                0xFFFF00, .03);
            prv_circle_draw(cmp1, 0);

            if (cmp1 != cmp2)
            {
                //this.graphics.lineStyle(.75 / (i / 22), 0x00FFFF, 1);
                //prv_circle_draw(cmp2, 0);
            }


            var isect1:Array = prv_circle_isect(cmp1, cmp2, 0, 3);


            if (isect1)
            {
               // prv_circle_draw(isect1, 0);


                prv_draw(i + 1, isect1, cmp1);
                prv_draw(i + 1, isect1, cmp2);


                prv_draw(i + 1, cmp1, isect1);
                prv_draw(i + 1, cmp2, isect1);
            }




            /*

            var isect1:Array = prv_circle_isect(cmp1, cmp2, 0, 3);
            var isect2:Array = prv_circle_isect(cmp2, cmp1, 0, 3);

            if (isect1)
            {
                prv_circle_draw(isect1, 0);

                prv_draw(i + 1, cmp1, isect1);
                prv_draw(i + 1, cmp2, isect1);
                prv_draw(i + 1, isect1, cmp1);
                prv_draw(i + 1, isect1, cmp2);
            }

            if (isect2)
            {
                prv_circle_draw(isect2, 0);

                prv_draw(i + 1, cmp1, isect2);
                prv_draw(i + 1, cmp2, isect2);
                prv_draw(i + 1, isect2, cmp1);
                prv_draw(i + 1, isect2, cmp2);
            }

            */
        }



        public function
        Main():void {





            //prv_cdraw_render();

            addEventListener(Event.ENTER_FRAME, prv_cdraw_render);


           /*
           var circles:Array = [
                200, 300, 100,
                250, 300, 100];

           this.graphics.lineStyle(1, 0xFFFFFF);


           //prv_circle_draw(circles, 0);


           //prv_circle_draw(circles, 3);

           //var isect:Array = prv_circle_isect(circles, circles, 0, 3);

           //if (! isect) return;

           var i:uint = 0;

           for (var ci:uint = 0; ci < circles.length && i < 22; ci += 3, 
++i)
           {
               var ci2:uint = ci + 3;
               if (ci2 + 3 > circles.length) break;



               var isect_fresh:Array =
                    prv_circle_isect(circles, circles, ci, ci2);

               if (! isect_fresh) continue; //fixup?

               prv_circle_draw(circles, ci);

               prv_circle_draw(isect_fresh, 0);

               circles = circles.concat(isect_fresh);
           }



           */



           /*

           prv_circle_draw(isect, 0);



           var isect2a:Array = prv_circle_isect(circles, isect, 0, 0);
           var isect2b:Array = prv_circle_isect(isect, circles, 0, 3);


           prv_circle_draw(isect2a, 0);
           prv_circle_draw(isect2b, 0);



           var isect3a:Array = prv_circle_isect(circles, isect2a, 0, 0);
           var isect3b:Array = prv_circle_isect(isect2b, circles, 0, 3);


           prv_circle_draw(isect3a, 0);
           prv_circle_draw(isect3b, 0);


           //isect2:Array = prv_circle_isect(circles, isect, 0, 0);

           */
        }







        public function
        prv_cdraw_render(e5:Event = null):void {
            this.graphics.clear();

            var circles:Array = [
                355, 300, 222,
                555, 300, 177];


            this.graphics.lineStyle(1, 0xFFFFFF, .1);

            this.graphics.drawCircle(circles[0], circles[1], circles[2]);
            this.graphics.drawCircle(circles[3], circles[4], circles[5]);

            prv_draw(0, circles, circles);


            //var circles2:Array = [
            //    200, 100, 333 - mcr2,
            //    444, 100, 333 - mcr2];

            //this.graphics.drawCircle(circles2[0], circles2[1], 
circles2[2]);
            //this.graphics.drawCircle(circles2[3], circles2[4], 
circles2[5]);
                //
              //  prv_draw(0, circles2, circles);

            mcr1 -= .007;
            mcr2 += .17;
        }




        public function
        prv_draw_mid_point_circle(
            circles:Array,
            offset:uint
        ):Array {

            this.graphics.moveTo(circles[0], circles[1]);
            var dis:Number = prv_distance(circles, 0);

            this.graphics.lineStyle(circles[2]);
            this.graphics.lineTo(circles[3], circles[4]);


            this.graphics.moveTo(circles[0], circles[1]);
            this.graphics.lineStyle(circles[5], 0xFFFF00);

            var ggg:Array = prv_mid_point(circles, 0);
            this.graphics.lineTo(ggg[0], ggg[1]);


            this.graphics.lineStyle(circles[5] + circles[2], 0x3366AA);
            this.graphics.drawCircle(ggg[0], ggg[1], dis / 2);

            return ggg;
        }




        public function
        prv_distance(
            points:Array,
            offset:uint
        ):Number {

            var x_diff_sq:Number =
                (points[offset + 3] - points[offset]) *
                (points[offset + 3] - points[offset]);

            var y_diff_sq:Number =
                (points[offset + 4] - points[offset + 1]) *
                (points[offset + 4] - points[offset + 1]);

            return Math.sqrt(x_diff_sq + y_diff_sq);
        }




        public function
        prv_mid_point(
            points:Array,
            offset:uint
        ):Array {

            var x_mid_pt:Number =
                (points[offset] + points[offset + 3]) / 2;

            var y_mid_pt:Number =
                (points[offset + 1] + points[offset + 4]) / 2;

            return [x_mid_pt, y_mid_pt, 0];
        }




        public function
        prv_circle_draw(
            circles:Array,
            oi:uint
        ):void {

            if (! circles) return;

            //this.graphics.beginFill(0xFF0000, .025);

            this.graphics.moveTo(circles[oi + 3], circles[oi + 4]);

            if (circles[oi + 2] < 33)
            {
                this.graphics.lineTo(circles[oi + 0], circles[oi + 1]);
                /*
                this.graphics.drawCircle(
                        circles[oi + 0],
                        circles[oi + 1],
                        circles[oi + 2]);

                        */



            }
           // this.graphics.endFill();

            //this.graphics.beginFill(0x0000FF, .025);


            this.graphics.moveTo(circles[oi + 0], circles[oi + 1]);

            if (circles[oi + 5] < 33)
            {
                this.graphics.lineTo(circles[oi + 3], circles[oi + 4]);

                /*
                this.graphics.drawCircle(
                        circles[oi + 3],
                        circles[oi + 4],
                        circles[oi + 5]);
                      */


            }
            //this.graphics.endFill();
        }




         public function
        prv_circle_isect(
            circles:Array,
            circles2:Array,
            ci1:uint,
            ci2:uint
        ):Array {

            if (circles[ci1 + 0] == circles2[ci2 + 0] &&
                circles2[ci2 + 1] == circles2[ci2 + 1])
            {
                return null;
            }

            if (circles[ci1 + 2] < 1 || circles2[ci2 + 2] < 1)
            {
                return null;
            }

            var distance:Number =
                prv_distance(
                    circles,
                    0);


            var dx:Number = circles2[ci2 + 0] - circles[ci1 + 0];
            var dy:Number = circles2[ci2 + 1] - circles[ci1 + 1];
            var d:Number = Math.sqrt((dy * dy) + (dx * dx));

            if (d > circles[ci1 + 2] + circles2[ci2 + 2])
            {
                return null;
            }

            if (d < Math.abs(circles[ci1 + 2] - circles2[ci2 + 2]))
            {
                return null;
            }


            var a:Number =
                ((circles[ci1 + 2] * circles[ci1 + 2]) -
                 (circles2[ci2 + 2] * circles2[ci2 + 2]) +
                 (d * d)) / (2 * d);

            var x2:Number = circles[ci1 + 0] + (dx * a / d);
            var y2:Number = circles[ci1 + 1] + (dy * a / d);
            var h:Number = Math.sqrt((circles[ci1 + 2] * circles[ci1 + 2]) - 
(a * a));

            // center circle
           // this.graphics.drawEllipse(x2 - (h * 2), y2 - h, d * 2, h * 2);
          // this.graphics.drawCircle(x2, y2, h);



            var rx:Number = -dy * (h / d);
            var ry:Number = dx * (h / d);


            var p1x:Number = x2 + -h * (circles2[ci2 + 1] - circles[ci1 + 
1]) / d;
            var p1y:Number = y2 + h * (circles2[ci2 + 0] - circles[ci1 + 0]) 
/ d;
            var p2x:Number = p1x - ((p1x - x2) * 2);
            var p2y:Number = p1y - ((p1y - y2) * 2);

            /*
            this.graphics.drawCircle(p1x, p1x, 10);
            this.graphics.drawCircle(p2x, p2y, 10);
            this.graphics.moveTo(p1x, p1y);
            this.graphics.lineTo(p2x, p2y);
            */

            var hr:Number = h / mcr1;

            return [p1x, p1y, hr, p2x, p2y, hr];
        }






        public function
        prv_circle_isectx1111(
            circles:Array,
            ci1:uint,
            ci2:uint
        ):Array {

            if (circles[ci1 + 2] < .5 || circles[ci2 + 2] < .5)
            {
                return null;
            }

            var distance:Number =
                prv_distance(
                    circles,
                    0);


            var dx:Number = circles[ci2 + 0] - circles[ci1 + 0];
            var dy:Number = circles[ci2 + 1] - circles[ci1 + 1];
            var d:Number = Math.sqrt((dy * dy) + (dx * dx));

            if (d > circles[ci1 + 2] + circles[ci2 + 2])
            {
                return null;
            }

            if (d < Math.abs(circles[ci1 + 2] - circles[ci2 + 2]))
            {
                return null;
            }


            var a:Number =
                ((circles[ci1 + 2] * circles[ci1 + 2]) -
                 (circles[ci2 + 2] * circles[ci2 + 2]) +
                 (d * d)) / (2 * d);

            var x2:Number = circles[ci1 + 0] + (dx * a / d);
            var y2:Number = circles[ci1 + 1] + (dy * a / d);
            var h:Number = Math.sqrt((circles[ci1 + 2] * circles[ci1 + 2]) - 
(a * a));

            // center circle
           // this.graphics.drawEllipse(x2 - (h * 2), y2 - h, d * 2, h * 2);
          // this.graphics.drawCircle(x2, y2, h);



            var rx:Number = -dy * (h / d);
            var ry:Number = dx * (h / d);


            var p1x:Number = x2 + -h * (circles[ci2 + 1] - circles[ci1 + 1]) 
/ d;
            var p1y:Number = y2 + h * (circles[ci2 + 0] - circles[ci1 + 0]) 
/ d;
            var p2x:Number = p1x - ((p1x - x2) * 2);
            var p2y:Number = p1y - ((p1y - y2) * 2);

            /*
            this.graphics.drawCircle(p1x, p1x, 10);
            this.graphics.drawCircle(p2x, p2y, 10);
            this.graphics.moveTo(p1x, p1y);
            this.graphics.lineTo(p2x, p2y);
            */



            return [p1x, p1y, h, p2x, p2y, h];
        }




        public function
        prv_circle_isectxx(
            circles:Array,
            ci1:uint,
            ci2:uint
        ):Array {

            if (circles[ci1 + 2] < .5 || circles[ci2 + 3] < .5)
            {
                return null;
            }

            var distance:Number =
                prv_distance(
                    circles,
                    0);


            var dx:Number = circles[ci2 + 0] - circles[ci1 + 0];
            var dy:Number = circles[ci2 + 2] - circles[ci1 + 1];
            var d:Number = Math.sqrt((dy * dy) + (dx * dx));

            if (d > circles[ci1 + 2] + circles[ci2 + 3])
            {
                return null;
            }

            if (d < Math.abs(circles[ci1 + 2] - circles[ci1 + 3]))
            {
                return null;
            }


            var a:Number =
                ((circles[ci1 + 2] * circles[ci1 + 2]) -
                 (circles[ci2 + 3] * circles[ci2 + 3]) +
                 (d * d)) / (2 * d);

            var x2:Number = circles[ci1 + 0] + (dx * a / d);
            var y2:Number = circles[ci1 + 1] + (dy * a / d);
            var h:Number = Math.sqrt((circles[ci1 + 2] * circles[ci1 + 2]) - 
(a * a));

            // center circle
           // this.graphics.drawEllipse(x2 - (h * 2), y2 - h, d * 2, h * 2);
          // this.graphics.drawCircle(x2, y2, h);



            var rx:Number = -dy * (h / d);
            var ry:Number = dx * (h / d);


            var p1x:Number = x2 + -h * (circles[ci2 + 2] - circles[ci1 + 1]) 
/ d;
            var p1y:Number = y2 + h * (circles[ci2 + 0] - circles[ci1 + 0]) 
/ d;
            var p2x:Number = p1x - ((p1x - x2) * 2);
            var p2y:Number = p1y - ((p1y - y2) * 2);

            /*
            this.graphics.drawCircle(p1x, p1x, 10);
            this.graphics.drawCircle(p2x, p2y, 10);
            this.graphics.moveTo(p1x, p1y);
            this.graphics.lineTo(p2x, p2y);
            */



            return [p1x, p1y, h, p2x, p2y, h];
        }







        public function
        prv_circle_isectx(
            circles:Array
        ):Array {

            if (circles[2] < .5 || circles[5] < .5)
            {
                return null;
            }

            var distance:Number =
                prv_distance(
                    circles,
                    0);


            var dx:Number = circles[3] - circles[0];
            var dy:Number = circles[4] - circles[1];
            var d:Number = Math.sqrt((dy * dy) + (dx * dx));

            if (d > circles[2] + circles[5])
            {
                return null;
            }

            if (d < Math.abs(circles[2] - circles[5]))
            {
                return null;
            }


            var a:Number =
                ((circles[2] * circles[2]) -
                 (circles[5] * circles[5]) +
                 (d * d)) / (2 * d);

            var x2:Number = circles[0] + (dx * a / d);
            var y2:Number = circles[1] + (dy * a / d);
            var h:Number = Math.sqrt((circles[2] * circles[2]) - (a * a));

            // center circle
           // this.graphics.drawEllipse(x2 - (h * 2), y2 - h, d * 2, h * 2);
          // this.graphics.drawCircle(x2, y2, h);



            var rx:Number = -dy * (h / d);
            var ry:Number = dx * (h / d);


            var p1x:Number = x2 + -h * (circles[4] - circles[1]) / d;
            var p1y:Number = y2 + h * (circles[3] - circles[0]) / d;
            var p2x:Number = p1x - ((p1x - x2) * 2);
            var p2y:Number = p1y - ((p1y - y2) * 2);

            /*
            this.graphics.drawCircle(p1x, p1x, 10);
            this.graphics.drawCircle(p2x, p2y, 10);
            this.graphics.moveTo(p1x, p1y);
            this.graphics.lineTo(p2x, p2y);
            */



            return [p1x, p1y, h / 1.14, p2x, p2y, h / 1.14];
        }
    }
}
__________________________________________________________________________



Perhaps it might be of service to your query. 

Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

A Question About Fractals Brian <briansipler@yahoo.com> - 2013-01-19 12:10 -0800
  Re: A Question About Fractals Geoff <geoff@invalid.invalid> - 2013-01-19 12:45 -0800
    Re: A Question About Fractals Brian <briansipler@yahoo.com> - 2013-01-19 13:09 -0800
      Re: A Question About Fractals Geoff <geoff@invalid.invalid> - 2013-01-19 14:16 -0800
      Re: A Question About Fractals Robin Vowels <robin.vowels@gmail.com> - 2013-01-19 15:53 -0800
  Re: A Question About Fractals "Chris M. Thomasson" <no@spam.invalid> - 2013-02-18 15:53 -0800
    Re: A Question About Fractals "Chris M. Thomasson" <no@spam.invalid> - 2013-02-18 16:36 -0800
      Re: A Question About Fractals "Chris M. Thomasson" <no@spam.invalid> - 2013-02-20 18:25 -0800
    Re: A Question About Fractals "Chris M. Thomasson" <no@spam.invalid> - 2013-02-26 02:21 -0800
      Re: A Question About Fractals "Chris M. Thomasson" <no@spam.invalid> - 2013-03-03 17:59 -0800
        Re: A Question About Fractals luser droog <mijoryx@yahoo.com> - 2013-05-17 18:55 -0700
          Re: A Question About Fractals "Chris M. Thomasson" <no@spam.invalid> - 2013-05-17 22:27 -0700
      Re: A Question About Fractals "Chris M. Thomasson" <no@spam.invalid> - 2013-03-04 13:17 -0800
      Re: A Question About Fractals "Chris M. Thomasson" <no@spam.invalid> - 2013-03-10 18:10 -0700
      Re: A Question About Fractals "Chris M. Thomasson" <no@spam.invalid> - 2013-03-10 18:21 -0700
  Re: A Question About Fractals James Dow Allen <gmail@jamesdowallen.nospam> - 2013-02-19 17:45 +0000
    Re: A Question About Fractals "Chris M. Thomasson" <no@spam.invalid> - 2013-02-19 13:11 -0800

csiph-web