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


Groups > comp.programming > #3070

Re: A Question About Fractals

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

Show all headers | View raw


"Chris M. Thomasson"  wrote in message 
news:kfuhds$skb$1@speranza.aioe.org...

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

Sorry about all the comments and renamed functions in the code. FWIW, here 
is the same but, cleaned up a bit:
__________________________________________________________________
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;

            var c:Number = cmp1[2] + cmp2[2];

            c = (c * 314) * (c * 628) + 0xFF0000;

            this.graphics.lineStyle(.277 / (i / 22),
                0xFFFFFF, .1);

            prv_circle_draw(cmp1, 0);



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


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


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

        }



        public function
        Main():void {
            addEventListener(Event.ENTER_FRAME, prv_cdraw_render);

        }



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

            var circles:Array = [
                222, 266, 222,
                488, 300, 222];


            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);


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



        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_circle_draw(
            circles:Array,
            oi:uint
        ):void {

            if (! circles) return;

            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.moveTo(circles[oi + 0], circles[oi + 1]);

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



            }
        }



         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));


            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);


            var hr:Number = h / mcr1;

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


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