Ejemplo n.º 1
0
        static public void Generate()
        {
            wasGenerated = true;

            // !!!{{ TODO - generate and draw maze in SVG format

            string fileName = CmdOptions.options.outputFileName;

            if (string.IsNullOrEmpty(fileName))
            {
                fileName = CmdOptions.options.html ? "out.html" : "out.svg";
            }
            string outFn = Path.Combine(CmdOptions.options.outDir, fileName);

            // SVG output:
            using (StreamWriter wri = new StreamWriter(outFn))
            {
                if (CmdOptions.options.html)
                {
                    wri.WriteLine("<!DOCTYPE html>");
                    wri.WriteLine("<meta charset=\"utf-8\">");
                    wri.WriteLine($"<title>SVG test ({CmdOptions.options.name})</title>");
                    wri.WriteLine(string.Format(CultureInfo.InvariantCulture, "<svg width=\"{0:f0}\" height=\"{1:f0}\">",
                                                CmdOptions.options.width, CmdOptions.options.height));
                }
                else
                {
                    wri.WriteLine(string.Format(CultureInfo.InvariantCulture, "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"{0:f0}\" height=\"{1:f0}\">",
                                                CmdOptions.options.width, CmdOptions.options.height));
                }

                List <Vector2> workList = new List <Vector2>();
                RandomJames    rnd      = new RandomJames();
                if (CmdOptions.options.seed > 0L)
                {
                    rnd.Reset(CmdOptions.options.seed);
                }
                else
                {
                    rnd.Randomize();
                }

                for (int i = 0; i < CmdOptions.options.columns; i++)
                {
                    workList.Add(new Vector2(rnd.RandomFloat(0.0f, (float)CmdOptions.options.width),
                                             rnd.RandomFloat(0.0f, (float)CmdOptions.options.height)));
                }

                drawCurve(wri, workList, 0, 0, string.Format("#{0:X2}{0:X2}{0:X2}", 0));

                wri.WriteLine("</svg>");

                // !!!}}
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Random generator init.
        /// </summary>
        /// <param name="seed">Random seed or 0L for Randomize().</param>
        /// <returns></returns>
        public long SetSeed(long seed)
        {
            if (seed <= 0L)
            {
                seed = rnd.Randomize();
            }
            else
            {
                rnd.Reset(seed);
            }

            return(seed);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// [Re-]initialization of the world.
        /// </summary>
        /// <param name="param">String parameter from user, e.g.: number of marbles.</param>
        public void Reset(string param)
        {
            Running = false;

            // Param parsing.
            Update(param);

            rnd.Reset(144);
            MyMarbles.Clear();

            UpdateMarbles();

            Frames  = 0;
            Time    = 0.0;
            Running = true;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// [Re-]initialization of the world.
        /// </summary>
        /// <param name="param">String parameter from user, e.g.: number of marbles.</param>
        public void Reset(string param)
        {
            Running = false;

            // Param parsing.
            Update(param);

            rnd.Reset(144);
            centers.Clear();
            radii.Clear();
            velocities.Clear();
            colors.Clear();

            UpdateMarbles();

            Frames  = 0;
            Time    = 0.0;
            Running = true;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Draw the image into the initialized Canvas object.
        /// </summary>
        /// <param name="c">Canvas ready for your drawing.</param>
        /// <param name="param">Optional string parameter from the form.</param>
        public static void Draw(Canvas c, string param)
        {
            // {{ TODO: put your drawing code here

            int         wq   = c.Width / 4;
            int         hq   = c.Height / 4;
            int         minq = Math.Min(wq, hq);
            double      t;
            int         i, j;
            double      x, y, r;
            RandomJames rnd = new RandomJames();

            c.Clear(Color.Black);

            // Example of even simpler passing of a numeric value through string param.
            long seed;

            if (long.TryParse(param, NumberStyles.Number, CultureInfo.InvariantCulture, out seed))
            {
                rnd.Reset(seed);
            }

            // 1st quadrant - anti-aliased disks in a spiral.
            c.SetAntiAlias(true);
            const int MAX_DISK = 30;

            for (i = 0, t = 0.0; i < MAX_DISK; i++, t += 0.65)
            {
                r = 5.0 + i * (minq * 0.7 - 5.0) / MAX_DISK;
                c.SetColor(Color.FromArgb(i * 255 / MAX_DISK, 255, 255 - i * 255 / MAX_DISK));
                c.FillDisc((float)(wq + r * Math.Sin(t)), (float)(hq + r * Math.Cos(t)), (float)(r * 0.3));
            }

            // 2nd quadrant - anti-aliased random dots in a heart shape..
            const int MAX_RND_DOTS = 1000;
            double    xx, yy, tmp;

            for (i = 0; i < MAX_RND_DOTS; i++)
            {
                // This is called "Rejection Sampling"
                do
                {
                    x   = rnd.RandomDouble(-1.5, 1.5);
                    y   = rnd.RandomDouble(-1.0, 1.5);
                    xx  = x * x;
                    yy  = y * y;
                    tmp = xx + yy - 1.0;
                } while (tmp * tmp * tmp - xx * yy * y > 0.0);

                c.SetColor(Color.FromArgb(rnd.RandomInteger(200, 255),
                                          rnd.RandomInteger(120, 220),
                                          rnd.RandomInteger(120, 220)));
                c.FillDisc(3.1f * wq + 0.8f * minq * (float)x,
                           1.2f * hq - 0.8f * minq * (float)y,
                           rnd.RandomFloat(1.0f, minq * 0.03f));
            }

            // 4th quadrant - CGG logo.
            c.SetColor(COLORS[0]);
            for (i = 0; i < DISC_DATA.Length / 3; i++)
            {
                x = DISC_DATA[i, 0];
                y = DISC_DATA[i, 1];
                r = DISC_DATA[i, 2];
                if (i == FIRST_COLOR)
                {
                    c.SetColor(COLORS[1]);
                }

                c.FillDisc(3.0f * wq + (float)((x - 85.0) * 0.018 * minq),
                           3.0f * hq + (float)((y - 65.0) * 0.018 * minq),
                           (float)(r * 0.018 * minq));
            }

            // 3rd quadrant - disk grid.
            const int DISKS = 12;

            for (j = 0; j < DISKS; j++)
            {
                for (i = 0; i < DISKS; i++)
                {
                    c.SetColor(((i ^ j) & 1) == 0 ? Color.White : Color.Blue);
                    c.FillDisc(wq + (i - DISKS / 2) * (wq * 1.8f / DISKS),
                               3 * hq + (j - DISKS / 2) * (hq * 1.7f / DISKS),
                               (((i ^ j) & 15) + 1.0f) / DISKS * minq * 0.08f);
                }
            }

            // }}
        }
Ejemplo n.º 6
0
        public static void Draw(Canvas c, string param)
        {
            int depthOfRecursion = 6;
            int borderWidth      = ((c.Height + c.Width) / (20 * depthOfRecursion) == 0) ? 1 : (c.Height + c.Width) / (20 * depthOfRecursion);

            int         numOfCircles = 1000;
            RandomJames rnd          = new RandomJames();
            long        seed;

            if (long.TryParse(param, NumberStyles.Number, CultureInfo.InvariantCulture, out seed))
            {
                rnd.Reset(seed);
            }

            // naming parameters like RandomJames.Reset(long ijkl), i love it :D
            RecursiveMondrian(rnd, c, new Rect()
            {
                x0 = 0, x1 = c.Width, y0 = 0, y1 = c.Height
            }, borderWidth, 0, depthOfRecursion, numOfCircles);



            // {{ TODO: put your drawing code here

            //  int wq = c.Width  / 4;
            //  int hq = c.Height / 4;
            //  int minq = Math.Min(wq, hq);
            //  double t;
            //  int i, j;
            //  double x, y, r;
            //  RandomJames rnd = new RandomJames();

            //  c.Clear(Color.Black);

            //  // Example of even simpler passing of a numeric value through string param.
            //  long seed;
            //  if (long.TryParse(param, NumberStyles.Number, CultureInfo.InvariantCulture, out seed))
            //    rnd.Reset(seed);

            //  // 1st quadrant - anti-aliased disks in a spiral.
            //  c.SetAntiAlias(true);
            //  const int MAX_DISK = 30;
            //  for (i = 0, t = 0.0; i < MAX_DISK; i++, t += 0.65)
            //  {
            //    r = 5.0 + i * (minq * 0.7 - 5.0) / MAX_DISK;
            //    c.SetColor(Color.FromArgb(i * 255 / MAX_DISK, 255, 255 - i * 255 / MAX_DISK));
            //    c.FillDisc((float)(wq + r * Math.Sin(t)), (float)(hq + r * Math.Cos(t)), (float)(r * 0.3));
            //  }

            //  // 2nd quadrant - anti-aliased random dots in a heart shape..
            //  const int MAX_RND_DOTS = 1000;
            //  double xx, yy, tmp;

            //  for (i = 0; i < MAX_RND_DOTS; i++)
            //  {
            //    // This is called "Rejection Sampling"
            //    do
            //    {
            //      x = rnd.RandomDouble(-1.5, 1.5);
            //      y = rnd.RandomDouble(-1.0, 1.5);
            //      xx = x * x;
            //      yy = y * y;
            //      tmp = xx + yy - 1.0;
            //    } while (tmp * tmp * tmp - xx * yy * y > 0.0);

            //    c.SetColor(Color.FromArgb(rnd.RandomInteger(200, 255),
            //                              rnd.RandomInteger(120, 220),
            //                              rnd.RandomInteger(120, 220)));
            //    c.FillDisc(3.1f * wq + 0.8f * minq * (float)x,
            //               1.2f * hq - 0.8f * minq * (float)y,
            //               rnd.RandomFloat(1.0f, minq * 0.03f));
            //  }

            //  // 4th quadrant - CGG logo.
            //  c.SetColor(COLORS[0]);
            //  for (i = 0; i < DISC_DATA.Length / 3; i++)
            //  {
            //    x = DISC_DATA[i, 0];
            //    y = DISC_DATA[i, 1];
            //    r = DISC_DATA[i, 2];
            //    if (i == FIRST_COLOR)
            //      c.SetColor(COLORS[1]);

            //    c.FillDisc(3.0f * wq + (float)((x - 85.0) * 0.018 * minq),
            //               3.0f * hq + (float)((y - 65.0) * 0.018 * minq),
            //               (float)(r * 0.018 * minq));
            //  }

            //  // 3rd quadrant - disk grid.
            //  const int DISKS = 12;
            //  for (j = 0; j < DISKS; j++)
            //    for (i = 0; i < DISKS; i++)
            //    {
            //      c.SetColor(((i ^ j) & 1) == 0 ? Color.White : Color.Blue);
            //      c.FillDisc(wq + (i - DISKS / 2) * (wq * 1.8f / DISKS),
            //                 3 * hq + (j - DISKS / 2) * (hq * 1.7f / DISKS),
            //                 (((i ^ j) & 15) + 1.0f) / DISKS * minq * 0.08f);
            //    }

            //  // }}
        }