Ejemplo n.º 1
0
        public override IEnumerator ReceivePayload(VisualPayload payload)
        {
            var textureSize = TextureSize.GetFirstValue(payload.Data);

            var newTexture = new Texture2D(textureSize, textureSize);

            var newPixels = new Color[textureSize * textureSize];

            var gradient = ColorGradient.GetFirstValue(payload.Data);

            for (int x = 0; x < textureSize; x++)
            {
                for (int y = 0; y < textureSize; y++)
                {
                    var proportion = x / (float)textureSize;
                    var color      = gradient.Evaluate(proportion);
                    newPixels[x + y * textureSize] = color;
                }
            }

            newTexture.SetPixels(newPixels);

            newTexture.Apply();

            TextureTarget.SetValue(newTexture, payload.Data);

            var iterator = Router.TransmitAll(payload);

            while (iterator.MoveNext())
            {
                yield return(null);
            }
        }
        public override IEnumerator ReceivePayload(VisualPayload payload)
        {
            var textureSize = TextureSize.GetFirstValue(payload.Data);

            var entropy = Entropy.GetFirstValue(payload.Data);

            var entropySteps = (from step in EntropySteps.GetFirstValue(payload.Data).Split(',') select float.Parse(step.Trim())).ToArray();

            var minimumEntropyLevels = MinimumEntropyLevels.GetFirstValue(payload.Data);

            var colorOne = ColorOne.GetFirstValue(payload.Data);
            var colorTwo = ColorTwo.GetFirstValue(payload.Data);

            var entropyGridTexture = new Texture2D(textureSize, textureSize);

            var entropyLevel = 0;

            while (entropyLevel < entropySteps.Length && entropy > entropySteps[entropyLevel])
            {
                entropyLevel++;
            }

            entropyLevel += minimumEntropyLevels;

            var pixels = new Color[textureSize * textureSize];

            for (int x = 0; x < textureSize; x++)
            {
                for (int y = 0; y < textureSize; y++)
                {
                    var xImpact = Mathf.FloorToInt((x / (float)textureSize) * entropyLevel);
                    var yImpact = Mathf.FloorToInt((y / (float)textureSize) * entropyLevel);
                    pixels[x + y * textureSize] = ((xImpact + yImpact) % 2) == 1 ? colorOne : colorTwo;
                }
            }

            entropyGridTexture.SetPixels(pixels);

            entropyGridTexture.Apply();

            TextureTarget.SetValue(entropyGridTexture, payload.Data);

            var iterator = Router.TransmitAll(payload);

            while (iterator.MoveNext())
            {
                yield return(null);
            }
        }