Ejemplo n.º 1
0
 public void Draw(Rectangle dest, SpriteBatch sb, Color first, Color second,
     ColoringAlgorithm algorithm = ColoringAlgorithm.CorrectedSinWash, float angle = 0.0f)
 {
     var num1 = 2f;
     float x = dest.X;
     float y = dest.Y;
     var num2 = HexScale*Hex.Width;
     var num3 = HexScale*Hex.Height;
     var seed = 10;
     var flag1 = true;
     while (x + (double) num2 < dest.X + dest.Width)
     {
         while (y + (double) num3 < dest.Y + dest.Height)
         {
             lcg.reSeed(seed);
             var num4 = lcg.NextFloat();
             var flag2 = false;
             var color = second;
             if (HasRedFlashyOnes && num4 <= 1.0/1000.0)
             {
                 color = Utils.AddativeRed*0.5f;
                 flag2 = true;
             }
             float amount;
             switch (algorithm)
             {
                 case ColoringAlgorithm.NegaitiveSinWash:
                     amount = (float) Math.Sin(num4 + timer*(double) lcg.NextFloat());
                     break;
                 default:
                     amount =
                         Math.Abs(
                             (float)
                                 Math.Sin(num4 + timer*(double) Math.Abs(lcg.NextFloat()*(flag2 ? 1f : 0.3f))));
                     break;
             }
             sb.Draw(Hex, Utils.RotatePoint(new Vector2(x, y), angle), new Rectangle?(),
                 Color.Lerp(first, color, amount), angle, Vector2.Zero, new Vector2(HexScale), SpriteEffects.None,
                 0.4f);
             if (algorithm == ColoringAlgorithm.OutlinedSinWash)
             {
                 if (flag2)
                     color = Utils.AddativeRed;
                 sb.Draw(Outline, Utils.RotatePoint(new Vector2(x, y), angle), new Rectangle?(),
                     Color.Lerp(first, color, amount), angle, Vector2.Zero, new Vector2(HexScale),
                     SpriteEffects.None, 0.4f);
             }
             ++seed;
             y += num3 + num1;
         }
         x += num2 - 60f*HexScale + num1;
         y = dest.Y;
         ++seed;
         if (flag1)
             y -= num3/2f;
         flag1 = !flag1;
     }
 }
        // POST: api/Graph
        public string Post(HttpRequestMessage value)
        {
            string  message  = value.Content.ReadAsStringAsync().Result;
            string  response = "";
            dynamic json     = JsonConvert.DeserializeObject(message);
            var     data     = JsonConvert.DeserializeObject <List <GraphModel> >(json);

            if (!String.IsNullOrEmpty(data[0].graphSize))
            {
                ColoringAlgorithm g1 = new ColoringAlgorithm(Int32.Parse(data[0].graphSize));
                foreach (var v in data)
                {
                    g1.addEdge(Int32.Parse(v.key), Int32.Parse(v.value));
                }
                response = g1.greedyColoring();
            }

            return(response);
        }
Ejemplo n.º 3
0
        public void Draw(Rectangle dest, SpriteBatch sb, Color first, Color second,
                         ColoringAlgorithm algorithm = ColoringAlgorithm.CorrectedSinWash, float angle = 0.0f)
        {
            var   num1  = 2f;
            float x     = dest.X;
            float y     = dest.Y;
            var   num2  = HexScale * Hex.Width;
            var   num3  = HexScale * Hex.Height;
            var   seed  = 10;
            var   flag1 = true;

            while (x + (double)num2 < dest.X + dest.Width)
            {
                while (y + (double)num3 < dest.Y + dest.Height)
                {
                    lcg.reSeed(seed);
                    var num4  = lcg.NextFloat();
                    var flag2 = false;
                    var color = second;
                    if (HasRedFlashyOnes && num4 <= 1.0 / 1000.0)
                    {
                        color = Utils.AddativeRed * 0.5f;
                        flag2 = true;
                    }
                    float amount;
                    switch (algorithm)
                    {
                    case ColoringAlgorithm.NegaitiveSinWash:
                        amount = (float)Math.Sin(num4 + timer * (double)lcg.NextFloat());
                        break;

                    default:
                        amount =
                            Math.Abs(
                                (float)
                                Math.Sin(num4 + timer * (double)Math.Abs(lcg.NextFloat() * (flag2 ? 1f : 0.3f))));
                        break;
                    }
                    sb.Draw(Hex, Utils.RotatePoint(new Vector2(x, y), angle), new Rectangle?(),
                            Color.Lerp(first, color, amount), angle, Vector2.Zero, new Vector2(HexScale), SpriteEffects.None,
                            0.4f);
                    if (algorithm == ColoringAlgorithm.OutlinedSinWash)
                    {
                        if (flag2)
                        {
                            color = Utils.AddativeRed;
                        }
                        sb.Draw(Outline, Utils.RotatePoint(new Vector2(x, y), angle), new Rectangle?(),
                                Color.Lerp(first, color, amount), angle, Vector2.Zero, new Vector2(HexScale),
                                SpriteEffects.None, 0.4f);
                    }
                    ++seed;
                    y += num3 + num1;
                }
                x += num2 - 60f * HexScale + num1;
                y  = dest.Y;
                ++seed;
                if (flag1)
                {
                    y -= num3 / 2f;
                }
                flag1 = !flag1;
            }
        }