Ejemplo n.º 1
0
    public void SwapColours()
    {
        ColourSet swappedColours = (ColourSet)ScriptableObject.CreateInstance("ColourSet");

        swappedColours.light = currentColour.dark;
        swappedColours.dark  = currentColour.light;
        SetColour(swappedColours);
    }
Ejemplo n.º 2
0
 private static string MakeColourSetRestore(ColourSet colourSet)
 {
     var colourSetter = string.Empty;
     if (colourSet.ForegroundSetter != null)
         colourSetter += MakeInstruction(colourSet.ForegroundSetter);
     if (colourSet.BackgroundSetter != null)
         colourSetter += MakeInstruction(colourSet.BackgroundSetter);
     return colourSetter;
 }
Ejemplo n.º 3
0
 static void Main(string[] args)
 {
     Console.WriteLine("Hello World!");
     for (int i = 0; i < 10; i++)
     {
         ColourSet set = new ColourSet();
         Console.WriteLine(set.ToString());
     }
     Console.ReadKey();
 }
Ejemplo n.º 4
0
    public void GenerateColourSet()
    {
        this.CurrentSet = this.sets[nextIndex];

        nextIndex++;
        if (nextIndex >= this.sets.Length)
        {
            nextIndex = 0;
        }
    }
Ejemplo n.º 5
0
        public void SetColour(string label, SetColourPayload payload)
        {
            var bulb = Bulbs.Single(x => x.Label == label);

            SendPayloadToMacAddress(payload, bulb.MacAddress, bulb.IpAddress);

            ColourSet?.Invoke(new LabelAndColourPayload()
            {
                Label = label, Payload = payload
            }, null);
        }
Ejemplo n.º 6
0
        public void SetColour(string label, SetColourPayload payload, bool updateBox)
        {
            var bulb = Bulbs.Single(x => x.Label == label);

            SendPayloadToMacAddress(payload, bulb.MacAddress, bulb.IpAddress);
            // this updates the bulb monitor, skip for multizone lights
            if (updateBox)
            {
                ColourSet?.Invoke(new LabelAndColourPayload()
                {
                    Label = label, Payload = payload
                }, null);
            }
        }
Ejemplo n.º 7
0
    public void SetColour(ColourSet colour)
    {
        //No need to waste resources trying to apply the same colour to the shield.
        if (currentColour.Equals(colour))
        {
            return;
        }

        if (currentPattern != null)
        {
            previewShield.sprite = SpriteColourModifier.MakeSprite(previewShield.sprite,
                                                                   currentPattern,
                                                                   colour,
                                                                   templateColours);
        }
        currentColour = colour;
    }
Ejemplo n.º 8
0
    private void InstantiateColour(ColourSet colour)
    {
        int tabIndex = (int)ShieldBuilderTab.COLOURS;

        Transform  parent    = tabContents[tabIndex];
        GameObject colourSet = Instantiate(prefabs[tabIndex], parent);

        //Assign colours
        Image colourPalette = colourSet.transform.GetChild(0).GetComponent <Image>();

        colourPalette.sprite = SpriteColourModifier.MakeSprite(colourPalette.sprite,
                                                               colourPalette.sprite,
                                                               colour,
                                                               templateColours);
        colourSet.GetComponentInChildren <TMP_Text>().text = colour.name;
        colourSet.GetComponentInChildren <Button>().onClick.AddListener(() => SetColour(colour));
    }
Ejemplo n.º 9
0
        protected ClusterFit(ColourSet colours, SquishOptions flags)
            : base(colours, flags)
        {
            // Set the iteration count.
            this._IterationCount = flags.HasFlag(SquishOptions.ColourIterativeClusterFit) ? MaxIterations : 1;

            // Initialise the best error.
            this._BestError = new Vector4(float.MaxValue);

            // Initialize the metric
            var perceptual = flags.HasFlag(SquishOptions.ColourMetricPerceptual);
            if (perceptual)
                this._Metric = new Vector4(0.2126f, 0.7152f, 0.0722f, 0.0f);
            else
                this._Metric = new Vector4(1.0f);

            // Get the covariance matrix.
            var covariance = Sym3x3.ComputeWeightedCovariance(colours.Count, colours.Points, colours.Weights);

            // Compute the principle component
            this._Principle = Sym3x3.ComputePrincipledComponent(covariance);
        }
Ejemplo n.º 10
0
            public void Initialize(ColourSet colours, SquishFlags flags, Vector3F? metric)
            {
                _colours = colours;
                _flags = flags;
                _xsum_wsum = new Vector4F();

                // set the iteration count
                _iterationCount = (flags & SquishFlags.ColourIterativeClusterFit) != 0 ? MaxIterations : 1;

                // initialise the metric (old perceptual = 0.2126f, 0.7152f, 0.0722f)
                if (metric.HasValue)
                  _metric = new Vector4F(metric.Value.X, metric.Value.Y, metric.Value.Z, 1.0f);
                else
                  _metric = Vector4F.One;

                // initialise the best error
                _besterror = new Vector4F(float.MaxValue);

                // cache some values
                int count = _colours.Count;
                Vector3F[] values = _colours.Points;

                // get the covariance matrix
                Sym3x3 covariance = ComputeWeightedCovariance(count, values, _colours.Weights);

                // compute the principle component
                _principle = ComputePrincipleComponent(covariance);
            }
Ejemplo n.º 11
0
 protected ColourFit(ColourSet colours, SquishOptions flags)
 {
     this._Colours = colours;
     this._Flags = flags;
 }
Ejemplo n.º 12
0
 public void TestNotInitedProperly()
 {
     ColourSet csWrong = new ColourSet("YELLOW");
 }
Ejemplo n.º 13
0
        public ShineView(Context context, ShineButtonControl shineButton, ShineParams shineParams, ColourSet randomColourSet = null) : base(context)
        {
            // Populate a custom selection of random colours if provided
            if (randomColourSet != null && randomColourSet.ColourSelection?.Length != 0)
            {
                suppliedColorRandom = randomColourSet.ColourSelection;
            }

            InitShineParams(shineParams, shineButton);

            this.shineAnimator       = new ShineAnimator(animDuration, shineDistanceMultiple, clickAnimDuration);
            ValueAnimator.FrameDelay = FRAME_REFRESH_DELAY;
            this.shineButton         = shineButton;

            paint             = new Paint();
            paint.Color       = bigShineColor;
            paint.StrokeWidth = 20;
            paint.SetStyle(Paint.Style.Stroke);
            paint.StrokeCap = Paint.Cap.Round;

            paint2             = new Paint();
            paint2.Color       = Color.White;
            paint2.StrokeWidth = 20;
            paint2.StrokeCap   = Paint.Cap.Round;

            paintSmall             = new Paint();
            paintSmall.Color       = smallShineColor;
            paintSmall.StrokeWidth = 10;
            paintSmall.SetStyle(Paint.Style.Stroke);
            paintSmall.StrokeCap = Paint.Cap.Round;

            clickAnimator            = ValueAnimator.OfFloat(0f, 1.1f);
            ValueAnimator.FrameDelay = FRAME_REFRESH_DELAY;
            clickAnimator.SetDuration(clickAnimDuration);
            clickAnimator.SetInterpolator(new EasingInterpolator(Ease.QuartOut));

            clickAnimator.Update += (s, e) =>
            {
                clickValue = (float)e.Animation.AnimatedValue;
                Invalidate();
            };

            clickAnimator.AnimationEnd += (s, e) =>
            {
                clickValue = 0;
                Invalidate();
            };

            shineAnimator.AnimationEnd += (s, e) =>
            {
                shineButton.RemoveView(this);
            };
        }
Ejemplo n.º 14
0
 protected ColourFit(ColourSet colours, SquishOptions flags)
 {
     _Colours = colours;
     _Flags   = flags;
 }
Ejemplo n.º 15
0
            public void Initialize(ColourSet colours, SquishFlags flags)
            {
                _colours = colours;
                _flags = flags;

                // grab the single colour
                Vector3F[] values = _colours.Points;
                _colour[0] = (byte)FloatToInt(255.0f * values[0].X, 255);
                _colour[1] = (byte)FloatToInt(255.0f * values[0].Y, 255);
                _colour[2] = (byte)FloatToInt(255.0f * values[0].Z, 255);

                // initialise the best error
                _besterror = int.MaxValue;
            }
Ejemplo n.º 16
0
            public void Initialize(ColourSet colours, SquishFlags flags, Vector3F? metric)
            {
                _colours = colours;
                _flags = flags;

                // initialise the metric (old perceptual = 0.2126f, 0.7152f, 0.0722f)
                if (metric.HasValue)
                  _metric = metric.Value;
                else
                  _metric = new Vector3F(1.0f);

                // initialise the best error
                _besterror = float.MaxValue;

                // cache some values
                int count = _colours.Count;
                Vector3F[] values = _colours.Points;
                float[] weights = _colours.Weights;

                // get the covariance matrix
                Sym3x3 covariance = ComputeWeightedCovariance(count, values, weights);

                // compute the principle component
                Vector3F principle = ComputePrincipleComponent(covariance);

                // get the min and max range as the codebook endpoints
                Vector3F start = new Vector3F(0.0f);
                Vector3F end = new Vector3F(0.0f);
                if (count > 0)
                {
                  float min, max;

                  // compute the range
                  start = end = values[0];
                  min = max = Vector3F.Dot(values[0], principle);
                  for (int i = 1; i < count; ++i)
                  {
                float val = Vector3F.Dot(values[i], principle);
                if (val < min)
                {
                  start = values[i];
                  min = val;
                }
                else if (val > max)
                {
                  end = values[i];
                  max = val;
                }
                  }
                }

                // clamp the output to [0, 1]
                start = Vector3F.Clamp(start, 0, 1);
                end = Vector3F.Clamp(end, 0, 1);

                // clamp to the grid and save
                Vector3F grid = new Vector3F(31.0f, 63.0f, 31.0f);
                Vector3F gridrcp = new Vector3F(1.0f / 31.0f, 1.0f / 63.0f, 1.0f / 31.0f);
                Vector3F half = new Vector3F(0.5f);
                _start = Truncate(grid * start + half) * gridrcp;
                _end = Truncate(grid * end + half) * gridrcp;
            }
Ejemplo n.º 17
0
    public static Sprite MakeSprite(Sprite original,
                                    Sprite template,
                                    ColourSet colourSet,
                                    ColourSet templateColourSet)
    {
        Texture2D originalTexture = original.texture;
        Texture2D templateTexture = template.texture;

        //If read / write isn't enabled in the sprite import setting it'll throw an error when you try and get / set
        //pixels in the sprites.
        if (!originalTexture.isReadable || !templateTexture.isReadable)
        {
            Debug.LogWarning("You must enable read / write for the sprites in the sprite import settings to use SpriteColourModifier. Returned original");
            return(original);
        }

        if (originalTexture.width != templateTexture.width || originalTexture.height != templateTexture.height)
        {
            Debug.LogWarning("The original sprite must be the same size as the template sprite to use SpriteColourModifier. Returned original");
            return(original);
        }

        Color32[] colours         = colourSet.GetColoursAsSingleArray();
        Color32[] templateColours = templateColourSet.GetColoursAsSingleArray();

        //This process will not work if these arrays aren't the same length
        if (templateColours.Length != colours.Length)
        {
            return(original);
        }

        Texture2D newTexture = new Texture2D(templateTexture.width, templateTexture.height);

        newTexture.filterMode = FilterMode.Point;

        for (int x = 0; x < templateTexture.width; x++)
        {
            for (int y = 0; y < templateTexture.height; y++)
            {
                if (templateTexture.GetPixel(x, y).a == 0)
                {
                    if (originalTexture.GetPixel(x, y).a == 0)
                    {
                        newTexture.SetPixel(x, y, Color.clear);
                    }
                    else
                    {
                        newTexture.SetPixel(x, y, originalTexture.GetPixel(x, y));
                    }
                    continue;
                }

                bool changedPixel = false;
                for (int i = 0; i < templateColours.Length; i++)
                {
                    Color32 templateColour = templateColours[i];
                    if (templateTexture.GetPixel(x, y).Equals(templateColour))
                    {
                        changedPixel = true;
                        newTexture.SetPixel(x, y, colours[i]);
                        //No need to keep checking if the colour matches once one has been found
                        break;
                    }
                }
                //This is just in case there is a border (or something like that) around both the template and the original
                //As because there isn't an alpha pixel on the template, the intial if statement want call.
                if (!changedPixel)
                {
                    newTexture.SetPixel(x, y, originalTexture.GetPixel(x, y));
                }
            }
        }
        //Apply the changes to the texture
        newTexture.Apply();

        Sprite newSprite = Sprite.Create(newTexture, template.rect, template.pivot, 1, 0, SpriteMeshType.Tight);

        return(newSprite);
    }
Ejemplo n.º 18
0
 protected ColourFit(ColourSet colours, SquishFlags flags)
 {
     MColours = colours;
     MFlags   = flags;
 }