Exemplo n.º 1
0
    /// <summary>
    /// Necessary so that the gameObject can be exposed to the radiation.
    /// Performs all the needed steps for calculating and recieving the radiation.
    /// </summary>
    private void GetAndApplyDose()
    {
        if (RaySource.Instance == null)
        {
            return;
        }

        // update vertices
        controller.UpdateVertices(RaySource.Instance.transform.position);
        controller.SortOutUnhittedVertices(RaySource.Instance.RayTracer);

        // get doses
        float[] distances  = RaySource.Instance.RayTracer.GetDistances(controller.GetRelevantVerticePositions());
        float[] addedDoses = DoseCalculator.Calculate(distances, RaySource.Instance.BaseEnergy, Time.fixedDeltaTime);

        // store doses
        controller.StoreDoses(addedDoses);

        // calculate colors and avg. dose
        float[] accumulatedDoses = controller.VerticeData.Select(x => x.Dose).ToArray();
        float   avgDose          = DoseCalculator.GetAVGDose(accumulatedDoses);

        Color32[] colors = ColorCalculator.Calculate(accumulatedDoses);

        // appy colors and avg. dose
        container.ApplyColors(colors);
        DoseInfo.Instance.Controller.SetAVGDose(avgDose);
    }
    public void CalculateReturnsExpectedColors_Test(float[] doses, float[] r, float[] g, float [] b)
    {
        // setup
        Color32[] rgbColors = GetColors(r, g, b);

        // perform
        Color32[] colors = ColorCalculator.Calculate(doses);

        // assert
        Assert.AreEqual(rgbColors, colors);
    }
Exemplo n.º 3
0
        public static Bitmap ArithmeticBlend(this Bitmap sourceBitmap, Bitmap blendBitmap,
                                     ColorCalculator.ColorCalculationType calculationType)
        {
            BitmapData sourceData = sourceBitmap.LockBits(new Rectangle(0, 0,
                                    sourceBitmap.Width, sourceBitmap.Height),
                                    ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            byte[] pixelBuffer = new byte[sourceData.Stride * sourceData.Height];
            Marshal.Copy(sourceData.Scan0, pixelBuffer, 0, pixelBuffer.Length);
            sourceBitmap.UnlockBits(sourceData);

            BitmapData blendData = blendBitmap.LockBits(new Rectangle(0, 0,
                                    blendBitmap.Width, blendBitmap.Height),
                                    ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            byte[] blendBuffer = new byte[blendData.Stride * blendData.Height];
            Marshal.Copy(blendData.Scan0, blendBuffer, 0, blendBuffer.Length);
            blendBitmap.UnlockBits(blendData);

            for (int k = 0; (k + 4 < pixelBuffer.Length) &&
                            (k + 4 < blendBuffer.Length); k += 4)
            {
                pixelBuffer[k] = ColorCalculator.Calculate(pixelBuffer[k],
                                 blendBuffer[k], calculationType);

                pixelBuffer[k + 1] = ColorCalculator.Calculate(pixelBuffer[k + 1],
                                     blendBuffer[k + 1], calculationType);

                pixelBuffer[k + 2] = ColorCalculator.Calculate(pixelBuffer[k + 2],
                                     blendBuffer[k + 2], calculationType);
            }

            Bitmap resultBitmap = new Bitmap(sourceBitmap.Width, sourceBitmap.Height);

            BitmapData resultData = resultBitmap.LockBits(new Rectangle(0, 0,
                                    resultBitmap.Width, resultBitmap.Height),
                                    ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

            Marshal.Copy(pixelBuffer, 0, resultData.Scan0, pixelBuffer.Length);
            resultBitmap.UnlockBits(resultData);

            return resultBitmap;
        }
Exemplo n.º 4
0
    void OnCollisionEnter2D(Collision2D col)
    {
        immuColor = ColorCalculator.GetDominantColour(currentColor);

        if (col.gameObject.CompareTag("Virus"))
        {
            ImmunityColour virusColor = col.gameObject.GetComponent <VirusV2>().GetColor();

            if (virusColor != immuColor)
            {
                switch (virusColor)
                {
                case (ImmunityColour.BLUE):
                    ActivateEffect(PickUpType.SlowDown, 5.0f);
                    virusHit = Instantiate(blue, transform.position, transform.rotation) as GameObject;
                    break;

                case (ImmunityColour.GREEN):
                    ActivateEffect(PickUpType.DontEat, 5.0f);
                    virusHit = Instantiate(green, transform.position, transform.rotation) as GameObject;
                    break;

                case (ImmunityColour.RED):
                    ActivateEffect(PickUpType.LoseMass, 1.0f);
                    virusHit = Instantiate(red, transform.position, transform.rotation) as GameObject;
                    break;
                }
            }
            else
            {
                //Do nothing
            }
            col.gameObject.SetActive(false);
        }

        if (canEat)
        {
            CheckEating(col.collider);
        }
    }
Exemplo n.º 5
0
        public void ScoreColors()
        {
            StreamWriter    colorsJs = new StreamWriter("Colors.js", false);
            ColorCalculator cc       = new ColorCalculator();

            cc.SetColorScale(ColorScale.Rainbow);

            String val   = String.Empty;
            String color = String.Empty;

            colorsJs.WriteLine("GuerillaTrader.Utilities.getScoreColor = function (val){");
            colorsJs.WriteLine("    var color = '';");
            for (Double i = 0.0; i <= 100.0; i += 1.0)
            {
                val   = i.ToString("N2");
                color = cc.SetPercentage(i / 100.0);

                colorsJs.WriteLine($"   else if (val <= {i.ToString("N2")}) color = '#{color}'");
            }
            colorsJs.WriteLine("    return color;");
            colorsJs.WriteLine("}");
            colorsJs.Close();
        }
Exemplo n.º 6
0
        public void Render()
        {
            // Create a new client manager.
            ClientManager clientManager = new ClientManager();

            if (!File.Exists(clientManager.FileName))
            {
                clientManager.FileName = ConfigurationManager.AppSettings["ClientDetailsRootPath"];
            }

            // Get the user's client.
            Client client = clientManager.GetSingle(this.Core.ClientName);

            string mainColor;
            string secondaryColor;
            string color5;
            string color7;
            string color9;
            string color20;
            string color21;

            ColorCalculator colorCalculator = new ColorCalculator();

            // Check if the client is null.
            if (client != null)
            {
                // Get the client's main color.
                mainColor = client.Color1;

                // Get the client's secondary color.
                secondaryColor = client.Color2;
            }
            else
            {
                mainColor      = "#6CAEE0";
                secondaryColor = "#FCB040";
            }

            color5 = colorCalculator.AdjustBrightness(new HexColor(mainColor), 1.4074074, 1.1379310, 1.04017857).ToString();
            color7 = colorCalculator.AdjustBrightness(new HexColor(mainColor), 2.09259259, 1.37356321, 1.1116071).ToString();
            color9 = colorCalculator.AdjustBrightness(new HexColor(mainColor), 1.69444444, 1.24137931, 1.0714285).ToString();

            color20 = colorCalculator.AdjustBrightness(new HexColor(secondaryColor), 1.15).ToString();
            color21 = colorCalculator.AdjustBrightness(new HexColor(secondaryColor), 1.2).ToString();

            // Get the contents of the color scheme template css file.
            string css = File.ReadAllText(Path.Combine(
                                              HttpContext.Current.Request.PhysicalApplicationPath,
                                              "App_Data",
                                              "ColorScheme.css"
                                              ));

            // Replace the main color.
            css = css.Replace("###MAINCOLOR###", mainColor);

            // Replace the secondary color.
            css = css.Replace("###SECONDARYCOLOR###", secondaryColor);

            // Replace the secondary color.
            css = css.Replace("###SECONDARYCOLOR2###", color20);

            // Replace the secondary color.
            css = css.Replace("###SECONDARYCOLOR3###", color21);

            // Replace the fifth color.
            css = css.Replace("###COLOR5###", color5);

            // Replace the seventh color.
            css = css.Replace("###COLOR7###", color7);

            // Replace the ninth color.
            css = css.Replace("###COLOR9###", color9);

            // Set the control's inner html code to the css.
            this.InnerHtml = css;
        }
Exemplo n.º 7
0
 protected void ChangeColor(Color addedColor, Bacteria eatenBacteria)
 {
     currentColor = ColorCalculator.MergeColors(currentColor, currentMass, addedColor, eatenBacteria.GetCurrentMass());
     ApplyCurrentColor();
 }
Exemplo n.º 8
0
 public ImageGeneratorController(ColorCalculator colorCalculator, FontFamily fontFamily)
 {
     _colorCalculator = colorCalculator;
     _fontFamily      = fontFamily;
 }
Exemplo n.º 9
0
        public void TestCalculator()
        {
            var color = ColorCalculator.Parse("hsl(318.413, 76.518%, 0.51568)");
            var hsl   = ColorCalculator.ToHSL(color);

            Assert.IsTrue(Math.Abs(hsl.Item1 - 318.412) < 0.1);
            Assert.IsTrue(Math.Abs(hsl.Item2 - 0.77) < 0.1);
            Assert.IsTrue(Math.Abs(hsl.Item3 - 0.52) < 0.1);
            Assert.AreEqual(226, color.R);
            Assert.AreEqual(37, color.G);
            Assert.AreEqual(168, color.B);
            color = ColorCalculator.Parse("hsl(318.413, 76.518%, 0.51568, 0.8)");
            Assert.AreEqual(226, color.R);

            color = ColorCalculator.Parse("cmyk(0, 0.83628, 0.25664, 0.11373)");
            var cmyk = ColorCalculator.ToCMYK(color);

            Assert.AreEqual(0, cmyk.Item1);
            Assert.IsTrue(Math.Abs(cmyk.Item2 - 0.83628) < 0.01);
            Assert.IsTrue(Math.Abs(cmyk.Item3 - 0.25664) < 0.01);
            Assert.IsTrue(Math.Abs(cmyk.Item4 - 0.11373) < 0.01);
            Assert.AreEqual(226, color.R);
            Assert.AreEqual(37, color.G);
            Assert.AreEqual(168, color.B);
            color = ColorCalculator.Parse("cmyk(0, 0.83628, 0.25664, 0.11373, 0.8)");
            Assert.AreEqual(37, color.G);

            color = ColorCalculator.Parse("rgb(226, 37, 0xA8)");
            Assert.AreEqual(226, color.R);
            Assert.AreEqual(37, color.G);
            Assert.AreEqual(168, color.B);
            Assert.IsTrue(Math.Abs(color.GetHue() - 318.412) < 0.1);
            color = ColorCalculator.Parse("rgb(226, 37, 168, 0.8)");
            Assert.AreEqual("rgba(226, 37, 168, 0.8)", ColorCalculator.ToRgbaString(color));
            Assert.AreEqual(168, color.B);
            Assert.AreEqual(102, ColorCalculator.Opacity(color, 0.5).A);
            Assert.AreEqual(128, ColorCalculator.Opacity(color, 0.5, true).A);
            Assert.IsTrue(ColorCalculator.Darken(color, 0.1).R < 226);

            color = ColorCalculator.Parse("red");
            Assert.AreEqual(255, color.R);
            Assert.AreEqual(0, color.G);
            Assert.AreEqual(0, color.B);
            Assert.AreEqual("rgba(255, 0, 0, 1)", ColorCalculator.ToRgbaString(color));
            color = ColorCalculator.Parse("#F00");
            Assert.AreEqual(255, color.R);
            Assert.AreEqual(0, color.G);
            Assert.AreEqual(0, color.B);
            color = ColorCalculator.Parse("#FF0000");
            Assert.AreEqual(255, color.R);
            Assert.AreEqual(0, color.G);
            Assert.AreEqual(0, color.B);
            color = ColorCalculator.Parse("#FFFF0000");
            Assert.AreEqual(255, color.R);
            Assert.AreEqual(0, color.G);
            Assert.AreEqual(0, color.B);

            color = Color.FromArgb(255, 0, 0);
            Assert.AreEqual(Color.FromArgb(0, 255, 255), ColorCalculator.Invert(color));
            Assert.AreEqual(color, ColorCalculator.ToggleBrightness(color));
            color = Color.FromArgb(240, 10, 10);
            Assert.AreEqual(Color.FromArgb(245, 15, 15), ColorCalculator.ToggleBrightness(color));

            color = ColorCalculator.Overlay(
                Color.FromArgb(128, 255, 0, 0),
                Color.FromArgb(255, 0, 0, 255));
            Assert.AreEqual(128, color.R);
            Assert.AreEqual(255, color.A);
            Assert.AreEqual(127, color.B);

            color = ColorCalculator.Mix(
                ColorMixTypes.Normal,
                Color.FromArgb(240, 0, 0),
                Color.FromArgb(0, 240, 0));
            Assert.AreEqual(120, color.R);
            Assert.AreEqual(120, color.G);
            Assert.AreEqual(0, color.B);
            color = ColorCalculator.Mix(
                ColorMixTypes.Lighten,
                Color.FromArgb(255, 192, 0),
                Color.FromArgb(0, 240, 64));
            Assert.AreEqual(255, color.R);
            Assert.AreEqual(240, color.G);
            Assert.AreEqual(64, color.B);
            color = ColorCalculator.Mix(
                ColorMixTypes.Darken,
                Color.FromArgb(255, 192, 0),
                Color.FromArgb(0, 240, 64));
            Assert.AreEqual(0, color.R);
            Assert.AreEqual(192, color.G);
            Assert.AreEqual(0, color.B);
            color = ColorCalculator.Mix(
                ColorMixTypes.Accent,
                Color.FromArgb(255, 192, 0),
                Color.FromArgb(0, 240, 64));
            Assert.AreEqual(255, color.R);
            Assert.AreEqual(255, color.G);
            Assert.AreEqual(64, color.B);
        }