Пример #1
0
        public WireWorld(int width, int height, int scale) : base(width, height, scale)
        {
            Name = "Wire World";

            ColorMapping.Add(WIRE, Color.Yellow);
            ColorMapping.Add(POSITIVE, Color.Red);
            ColorMapping.Add(NEGATIVE, Color.Blue);

            ActionMapping.Add(POSITIVE, (x, y) => {
                Write(x, y, NEGATIVE);
            });
            ActionMapping.Add(NEGATIVE, (x, y) => { Write(x, y, WIRE); });
            ActionMapping.Add(WIRE, (x, y) =>
            {
                int numPositive = 0;
                for (int xx = x - 1; xx <= x + 1; xx++)
                {
                    for (int yy = y - 1; yy <= y + 1; yy++)
                    {
                        if (Read(xx, yy) == POSITIVE)
                        {
                            numPositive++;
                        }
                    }
                }
                if (numPositive == 1 || numPositive == 2)
                {
                    Write(x, y, POSITIVE);
                }
            });

            LeftPlace   = WIRE;
            Refreshrate = 6;
        }
Пример #2
0
        /// <summary>
        /// Converts an array of DepthImagePixels into a byte array in Bgr32 format.
        /// Pixel intensity represents depth; colors indicate players.
        /// </summary>
        /// <param name="depthFrame">The depth buffer to convert.</param>
        /// <param name="minDepth">The minimum reliable depth for this frame.</param>
        /// <param name="maxDepth">The maximum reliable depth for this frame.</param>
        /// <param name="depthTreatment">The depth treatment to apply.</param>
        /// <param name="colorFrame">The buffer to fill with color pixels.</param>
        public void ConvertDepthFrame(
            DepthImagePixel[] depthFrame,
            int minDepth,
            int maxDepth,
            KinectDepthTreatment depthTreatment,
            byte[] colorFrame)
        {
            // Test that the buffer lengths are appropriately correlated, which allows us to use only one
            // value as the loop condition.
            if ((depthFrame.Length * Bgr32BytesPerPixel) != colorFrame.Length)
            {
                throw new InvalidOperationException();
            }

            ColorMapping[] mappingTable = GetColorMappingTable(minDepth, maxDepth, depthTreatment);

            for (int depthIndex = 0, colorIndex = 0;
                 colorIndex < colorFrame.Length;
                 depthIndex++, colorIndex += Bgr32BytesPerPixel)
            {
                short        depth = depthFrame[depthIndex].Depth;
                ColorMapping color = mappingTable[(ushort)depth];

                int player = depthFrame[depthIndex].PlayerIndex;

                // Write color pixel to buffer
                colorFrame[colorIndex + RedIndex]   = (byte)(color.R >> IntensityShiftByPlayerR[player]);
                colorFrame[colorIndex + GreenIndex] = (byte)(color.G >> IntensityShiftByPlayerG[player]);
                colorFrame[colorIndex + BlueIndex]  = (byte)(color.B >> IntensityShiftByPlayerB[player]);
            }
        }
Пример #3
0
    private void NewColorMapping(Color color)
    {
        ColorMapping newMapping = new ColorMapping();

        newMapping.color  = color;
        newMapping.prefab = null;
        levelData.mappings.Add(newMapping);
    }
Пример #4
0
        public void FromAnimationSet(AnimationSet set)
        {
            // Reset the animations, and read them in!
            animations = new List <EditAnimation>();
            for (int i = 0; i < set.animations.Length; ++i)
            {
                var anim     = set.getAnimation((ushort)i);
                var editAnim = new EditAnimation();
                for (int j = 0; j < anim.trackCount; ++j)
                {
                    var track     = anim.GetTrack(set, (ushort)j);
                    var editTrack = new EditTrack();
                    editTrack.ledIndices = new List <int>();
                    editTrack.ledIndices.Add(track.ledIndex);
                    var rgbTrack = track.GetTrack(set);
                    for (int k = 0; k < rgbTrack.keyFrameCount; ++k)
                    {
                        var kf     = rgbTrack.GetKeyframe(set, (ushort)k);
                        var editKf = new EditKeyframe();
                        editKf.time = (float)kf.time() / 1000.0f;
                        if (kf.colorIndex() == AnimationSet.SPECIAL_COLOR_INDEX)
                        {
                            editKf.color = new Color32(255, 255, 255, 0); // Important part is alpha
                        }
                        else
                        {
                            editKf.color = ColorMapping.InverseRemap(set.getColor(kf.colorIndex()));
                        }
                        editTrack.keyframes.Add(editKf);
                    }
                    editAnim.tracks.Add(editTrack);
                }

                // De-duplicate tracks
                for (int l = 0; l < editAnim.tracks.Count; ++l)
                {
                    for (int m = l + 1; m < editAnim.tracks.Count; ++m)
                    {
                        if (editAnim.tracks[m].keyframes.SequenceEqual(editAnim.tracks[l].keyframes, EditKeyframe.DefaultComparer))
                        {
                            // Concatenate the leds
                            editAnim.tracks[l].ledIndices.AddRange(editAnim.tracks[m].ledIndices);

                            // Remove the second edit anim
                            editAnim.tracks.RemoveAt(m);
                            m--;
                        }
                    }
                }

                editAnim.@event            = (Die.AnimationEvent)anim.animationEvent;
                editAnim.@specialColorType = (Die.SpecialColor)anim.specialColorType;
                animations.Add(editAnim);
            }
        }
Пример #5
0
 public string GetB2CColorSpecName(string APIColorCode)
 {
     try
     {
         var colorMatch = ColorMapping.FirstOrDefault(x => x.Value.Any(y => y == APIColorCode));
         return(colorMatch.Key);
     }
     catch (Exception ex)
     {
         throw new Exception("Nebim Integration->Color mapping error.APIColorCode:" + APIColorCode, ex);
     }
 }
Пример #6
0
    // Use this for initialization
    void Start()
    {
        //add component's properties
        cs_transfer = Resources.Load("Scripts/CS_Transfer") as ComputeShader;
        if (flameParticle == null)
        {
            flameParticle = Resources.Load("Prefabs/FlameParticles") as GameObject;
        }

        texture = new Texture2D(256, 256, TextureFormat.ARGB32, false);
        GetComponent <Renderer>().material.mainTexture = texture;


        colorMapper = GetComponent <ColorMapping>();

        Color32[] cols = texture.GetPixels32();
        for (int i = 0; i < cols.Length; ++i)
        {
            cols[i] = GetColor(10.0f);
        }
        texture.SetPixels32(cols);
        texture.Apply(false);

        heatVals     = new float[cols.Length];
        heatPrecVals = new float[cols.Length];

        for (int i = 0; i < cols.Length; ++i)
        {
            if (i >= 0 && i < 256)
            {
                heatVals[i]     = 250.0f;
                heatPrecVals[i] = 250.0f;
            }
            else
            {
                heatVals[i]     = 10.0f;
                heatPrecVals[i] = 10.0f;
            }
        }

        cam = Camera.main;

        Vector3 screenPos      = new Vector3(Screen.width * 0.5f, Screen.height * 0.5f, 40.0f);
        Vector3 worldPos       = cam.ScreenToWorldPoint(screenPos);
        Vector3 worldOffsetPos = cam.ScreenToWorldPoint(screenPos + new Vector3(1.0f, 0.0f, 0.0f));

        deltaX = worldOffsetPos.x - worldPos.x;
        deltaT = deltaX / 1.5f;
        //deltaT = deltaX / (radius * 2);
        deltaT *= 0.1f;
    }
Пример #7
0
    protected void SetAreaTexValue(Texture2D _tex, ref int[,] _intMap, Vector2Int _fromIndex, int _fromValue, bool flipX, bool flipY, bool clockRot90)
    {
        int h = _tex.height;
        int w = _tex.width;

        for (int y = 0; y < h; y++)
        {
            for (int x = 0; x < w; x++)
            {
                int          texX  = IndexFlipper(x, w - 1, flipX);
                int          texY  = IndexFlipper(y, h - 1, flipY);
                ColorMapping _cMap = GetTexColorMapping(_tex, texX, texY);

                Vector2Int intMapChangeIndexLot;
                if (!clockRot90)
                {
                    intMapChangeIndexLot = new Vector2Int(_fromIndex.x + x, _fromIndex.y + y);
                }
                else
                {
                    intMapChangeIndexLot = new Vector2Int(y + _fromIndex.x, h - x - 1 + _fromIndex.y);
                }
                // 0,0 > 0,h
                // w,0 > 0,0
                // w,h > w,0
                // 0,h > w,h

                if (_intMap[intMapChangeIndexLot.x, intMapChangeIndexLot.y] == _fromValue)
                {
                    if (_cMap != null)
                    {
                        _intMap[intMapChangeIndexLot.x, intMapChangeIndexLot.y] = _cMap.prefabID;
                    }
                    else
                    {
                        _intMap[intMapChangeIndexLot.x, intMapChangeIndexLot.y] = 0;
                    }
                }
            }
        }
    }
        public static int Save(ColorMappingDO colorMappingDO, int userID)
        {
            Repository<ColorMapping> repColor = new Repository<ColorMapping>(BeymenDataContextProvider.Instance);
            ColorMapping colorMapping;

            if (colorMappingDO.ID == 0)
            {
                colorMapping = new ColorMapping();
                ObjectMapper.MapObjects<ColorMappingDO, ColorMapping>(colorMappingDO, colorMapping);
                repColor.InsertOnSubmit(colorMapping);
            }
            else
            {
                colorMapping = repColor.GetAll().Where(x => x.ID == colorMappingDO.ID).SingleOrDefault();
                ObjectMapper.MapObjects<ColorMappingDO, ColorMapping>(colorMappingDO, colorMapping);
                repColor.UpdateByIdOnSubmit(colorMapping);
            }

            repColor.DCP.CommitChanges(userID);

            return colorMapping.ID;
        }
Пример #9
0
        public GameOfLife(int width, int height, int scale) : base(width, height, scale)
        {
            Name = "Conways Game of Life";

            ColorMapping.Add(NULL, Color.Black);
            ColorMapping.Add(ALIVE, Color.White);

            ActionMapping.Add(ALIVE, (x, y) => {
                int numNeighbors = GetNumNeightbors(x, y);
                if(numNeighbors < 2 || numNeighbors > 3)
                {
                    Write(x, y, NULL);
                }
            });
            ActionMapping.Add(NULL, (x, y) => { 
                if (GetNumNeightbors(x, y) == 3) 
                { 
                    Write(x, y, ALIVE); 
                } 
            });

            LeftPlace = ALIVE;
            Refreshrate = 30;
        }
Пример #10
0
        /// <summary>
        /// Returns the depth-to-color mapping table.
        /// </summary>
        /// <param name="minDepth">The minimum reliable depth value.</param>
        /// <param name="maxDepth">The maximum reliable depth value.</param>
        /// <param name="depthTreatment">The depth treatment to apply.</param>
        /// <returns>The color mapping table.</returns>
        private ColorMapping[] GetColorMappingTable(int minDepth, int maxDepth, KinectDepthTreatment depthTreatment)
        {
            if (initializeColorMappingTable ||
                minDepth != currentMinDepth ||
                maxDepth != currentMaxDepth ||
                depthTreatment != currentDepthTreatment)
            {
                initializeColorMappingTable = false;
                currentMinDepth = minDepth;
                currentMaxDepth = maxDepth;
                currentDepthTreatment = depthTreatment;

                // Initialize table to all zero (black)
                Array.Clear(colorMappingTable, 0, colorMappingTable.Length);

                // Fill in the color for an unknown depth value
                colorMappingTable[UnknownDepth] = UnknownDepthColor;

                switch (depthTreatment)
                {
                    case KinectDepthTreatment.ClampUnreliableDepths:

                        // Fill in the "near" portion of the table with solid color
                        for (int i = 1; i < minDepth; i++)
                        {
                            colorMappingTable[i] = TooNearColor;
                        }

                        // Fill in the "far" portion of the table with solid color
                        for (int i = maxDepth + 1; i < MaxMaxDepth; i++)
                        {
                            colorMappingTable[i] = TooFarColor;
                        }

                        break;

                    case KinectDepthTreatment.TintUnreliableDepths:

                        // Fill in the "near" portion of the table with a tinted gradient
                        for (int i = 1; i < minDepth; i++)
                        {
                            byte intensity = intensityTable[i];

                            // Apply cobalt tint
                            colorMappingTable[i] = new ColorMapping
                            {
                                R = (byte)(intensity >> 3),
                                G = (byte)(intensity >> 1),
                                B = intensity
                            };
                        }

                        // Fill in the "far" portion of the table with a tinted gradient
                        for (int i = maxDepth + 1; i < MaxMaxDepth; i++)
                        {
                            byte intensity = intensityTable[i];

                            // Apply cranberry tint
                            colorMappingTable[i] = new ColorMapping
                            {
                                R = intensity,
                                G = (byte)(intensity >> 3),
                                B = (byte)(intensity >> 1)
                            };
                        }

                        break;

                    case KinectDepthTreatment.DisplayAllDepths:

                        // Fill in the "nearer than near" values with solid white
                        for (int i = 1; i < MinMinDepth; i++)
                        {
                            colorMappingTable[i] = NearestDepthColor;
                        }

                        // Adjust minDepth and maxDepth to allow unreliable values to be rendered
                        minDepth = MinMinDepth;
                        maxDepth = MaxMaxDepth;    // anything more distant will be black
                        break;
                }

                // Fill in values that will be rendered normally with a gray gradient
                for (int i = minDepth; i < maxDepth; i++)
                {
                    byte intensity = intensityTable[i];
                    colorMappingTable[i] = new ColorMapping
                    {
                        R = intensity,
                        G = intensity,
                        B = intensity
                    };
                }
            }

            return colorMappingTable;
        }
Пример #11
0
        public SandBox(int width, int height, int scale) : base(width, height, scale)
        {
            Name      = "Sandbox Simulation";
            LeftPlace = SOLID;

            //define colours
            ColorMapping.Add(SAND, Color.Yellow);
            ColorMapping.Add(SOLID, Color.Gray);
            ColorMapping.Add(WATER, Color.Blue);
            ColorMapping.Add(ICE, Color.LightSkyBlue);
            ColorMapping.Add(SMOKE, Color.LightGray);
            //define callbacks
            ActionMapping.Add(SAND, (x, y) => {
                if (Read(x, y + 1) != NULL)
                {
                    if (Read(x, y + 1) == WATER)
                    {
                        Write(x, y + 1, SAND);
                        Write(x, y, WATER);
                        return;
                    }
                    if (Random.Chance(0.5f))
                    {
                        if (Read(x + 1, y + 1) == NULL)
                        {
                            //prevent clipping through diagonals
                            if (Read(x + 1, y) == NULL)
                            {
                                //move right down
                                Write(x + 1, y + 1, Read(x, y));
                                Write(x, y, NULL);
                            }
                        }
                    }
                    else
                    {
                        if (Read(x - 1, y + 1) == NULL)
                        {
                            //prevent clipping through diagonals
                            if (Read(x - 1, y) == NULL)
                            {
                                //move left down
                                Write(x - 1, y + 1, Read(x, y));
                                Write(x, y, NULL);
                            }
                        }
                    }
                }
                else
                {
                    //move downwards
                    Write(x, y + 1, Read(x, y));
                    Write(x, y, NULL);
                }
            });
            ActionMapping.Add(ICE, (x, y) => {
                if (Read(x, y + 1) != NULL)
                {
                    if (Read(x, y + 1) == WATER)
                    {
                        Write(x, y + 1, ICE);
                        Write(x, y, ICE);
                        return;
                    }
                    if (Random.Chance(0.5f))
                    {
                        if (Read(x + 1, y + 1) == NULL)
                        {
                            //prevent clipping through diagonals
                            if (Read(x + 1, y) == NULL)
                            {
                                //move right down
                                Write(x + 1, y + 1, Read(x, y));
                                Write(x, y, NULL);
                            }
                        }
                    }
                    else
                    {
                        if (Read(x - 1, y + 1) == NULL)
                        {
                            //prevent clipping through diagonals
                            if (Read(x - 1, y) == NULL)
                            {
                                //move left down
                                Write(x - 1, y + 1, Read(x, y));
                                Write(x, y, NULL);
                            }
                        }
                    }
                }
                else
                {
                    //move downwards
                    Write(x, y + 1, Read(x, y));
                    Write(x, y, NULL);
                }
            });
            ActionMapping.Add(WATER, (x, y) =>
            {
                if (Read(x, y + 1) != NULL)
                {
                    if (Read(x + 1, y + 1) == NULL)
                    {
                        //prevent clipping through diagonals
                        if (Read(x + 1, y) == NULL)
                        {
                            //move right down
                            Write(x + 1, y + 1, Read(x, y));
                            Write(x, y, NULL);
                        }
                    }
                    else
                    {
                        if (Random.Chance(0.5f))
                        {
                            if (Read(x + 1, y) == NULL)
                            {
                                //move right
                                Write(x + 1, y, Read(x, y));
                                Write(x, y, NULL);
                            }
                        }
                        else
                        {
                            if (Read(x - 1, y) == NULL)
                            {
                                //move left
                                Write(x - 1, y, Read(x, y));
                                Write(x, y, NULL);
                            }
                        }
                    }
                }
                else
                {
                    //move downwards
                    Write(x, y + 1, Read(x, y));
                    Write(x, y, NULL);
                }
            });
            ActionMapping.Add(SMOKE, (x, y) =>
            {
                if (Read(x, y - 1) != NULL)
                {
                    if (Random.Chance(0.5f))
                    {
                        if (Read(x + 1, y) == NULL)
                        {
                            //move right
                            Write(x + 1, y, Read(x, y));
                            Write(x, y, NULL);
                        }
                    }
                    else
                    {
                        if (Read(x - 1, y) == NULL)
                        {
                            //move left
                            Write(x - 1, y, Read(x, y));
                            Write(x, y, NULL);
                        }
                    }
                }
                else
                {
                    //move up
                    Write(x, y - 1, Read(x, y));
                    Write(x, y, NULL);
                }
            });

            FillBorder(SOLID);
        }
Пример #12
0
        public async Task InitializeData(StringProvider stringProvider, string dataPath)
        {
            _stringProvider = stringProvider;

            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(dataPath));

            string dataString = await FileIO.ReadTextAsync(file);

            JsonObject rootObject = JsonObject.Parse(dataString);

            _whiteColor = new ColorPaletteEntry(Colors.White, _stringProvider.GetString("DarkThemeTextContrastTitle"), null, FluentEditorShared.Utils.ColorStringFormat.PoundRGB, null);
            _blackColor = new ColorPaletteEntry(Colors.Black, _stringProvider.GetString("LightThemeTextContrastTitle"), null, FluentEditorShared.Utils.ColorStringFormat.PoundRGB, null);

            var lightRegionNode = rootObject["LightRegion"].GetObject();

            _lightRegion = ColorPaletteEntry.Parse(lightRegionNode, null);

            var darkRegionNode = rootObject["DarkRegion"].GetObject();

            _darkRegion = ColorPaletteEntry.Parse(darkRegionNode, null);

            var lightBaseNode = rootObject["LightBase"].GetObject();

            _lightBase = ColorPalette.Parse(lightBaseNode, null);

            var darkBaseNode = rootObject["DarkBase"].GetObject();

            _darkBase = ColorPalette.Parse(darkBaseNode, null);

            var lightPrimaryNode = rootObject["LightPrimary"].GetObject();

            _lightPrimary = ColorPalette.Parse(lightPrimaryNode, null);

            var darkPrimaryNode = rootObject["DarkPrimary"].GetObject();

            _darkPrimary = ColorPalette.Parse(darkPrimaryNode, null);

            _presets = new ObservableList <Preset>();
            if (rootObject.ContainsKey("Presets"))
            {
                var presetsNode = rootObject["Presets"].GetArray();
                foreach (var presetNode in presetsNode)
                {
                    _presets.Add(Preset.Parse(presetNode.GetObject()));
                }
            }
            if (_presets.Count >= 1)
            {
                ApplyPreset(_presets[0]);
            }

            UpdateActivePreset();

            _lightRegion.ContrastColors = new List <ContrastColorWrapper>()
            {
                new ContrastColorWrapper(_whiteColor, false, false), new ContrastColorWrapper(_blackColor, true, true), new ContrastColorWrapper(_lightBase.BaseColor, true, false), new ContrastColorWrapper(_lightPrimary.BaseColor, true, false)
            };
            _darkRegion.ContrastColors = new List <ContrastColorWrapper>()
            {
                new ContrastColorWrapper(_whiteColor, true, true), new ContrastColorWrapper(_blackColor, false, false), new ContrastColorWrapper(_darkBase.BaseColor, true, false), new ContrastColorWrapper(_darkPrimary.BaseColor, true, false)
            };
            _lightBase.ContrastColors = new List <ContrastColorWrapper>()
            {
                new ContrastColorWrapper(_whiteColor, false, false), new ContrastColorWrapper(_blackColor, true, true), new ContrastColorWrapper(_lightRegion, true, false), new ContrastColorWrapper(_lightPrimary.BaseColor, true, false)
            };
            _darkBase.ContrastColors = new List <ContrastColorWrapper>()
            {
                new ContrastColorWrapper(_whiteColor, true, true), new ContrastColorWrapper(_blackColor, false, false), new ContrastColorWrapper(_darkRegion, true, false), new ContrastColorWrapper(_darkPrimary.BaseColor, true, false)
            };
            _lightPrimary.ContrastColors = new List <ContrastColorWrapper>()
            {
                new ContrastColorWrapper(_whiteColor, true, true), new ContrastColorWrapper(_blackColor, false, false), new ContrastColorWrapper(_lightRegion, true, false), new ContrastColorWrapper(_lightBase.BaseColor, true, false)
            };
            _darkPrimary.ContrastColors = new List <ContrastColorWrapper>()
            {
                new ContrastColorWrapper(_whiteColor, true, true), new ContrastColorWrapper(_blackColor, false, false), new ContrastColorWrapper(_darkRegion, true, false), new ContrastColorWrapper(_darkBase.BaseColor, true, false)
            };

            _lightColorMappings = ColorMapping.ParseList(rootObject["LightPaletteMapping"].GetArray(), _lightRegion, _darkRegion, _lightBase, _darkBase, _lightPrimary, _darkPrimary, _whiteColor, _blackColor);
            _lightColorMappings.Sort((a, b) =>
            {
                return(a.Target.ToString().CompareTo(b.Target.ToString()));
            });

            _darkColorMappings = ColorMapping.ParseList(rootObject["DarkPaletteMapping"].GetArray(), _lightRegion, _darkRegion, _lightBase, _darkBase, _lightPrimary, _darkPrimary, _whiteColor, _blackColor);
            _darkColorMappings.Sort((a, b) =>
            {
                return(a.Target.ToString().CompareTo(b.Target.ToString()));
            });

            _lightRegion.ActiveColorChanged            += PaletteEntry_ActiveColorChanged;
            _darkRegion.ActiveColorChanged             += PaletteEntry_ActiveColorChanged;
            _lightBase.BaseColor.ActiveColorChanged    += PaletteEntry_ActiveColorChanged;
            _darkBase.BaseColor.ActiveColorChanged     += PaletteEntry_ActiveColorChanged;
            _lightPrimary.BaseColor.ActiveColorChanged += PaletteEntry_ActiveColorChanged;
            _darkPrimary.BaseColor.ActiveColorChanged  += PaletteEntry_ActiveColorChanged;
            foreach (var entry in _lightBase.Palette)
            {
                entry.ActiveColorChanged += PaletteEntry_ActiveColorChanged;
            }
            foreach (var entry in _darkBase.Palette)
            {
                entry.ActiveColorChanged += PaletteEntry_ActiveColorChanged;
            }
            foreach (var entry in _lightPrimary.Palette)
            {
                entry.ActiveColorChanged += PaletteEntry_ActiveColorChanged;
            }
            foreach (var entry in _darkPrimary.Palette)
            {
                entry.ActiveColorChanged += PaletteEntry_ActiveColorChanged;
            }

            if (_lightRegion.Description == null)
            {
                _lightRegion.Description = GenerateMappingDescription(_lightRegion, _lightColorMappings);
            }
            if (_darkRegion.Description == null)
            {
                _darkRegion.Description = GenerateMappingDescription(_darkRegion, _darkColorMappings);
            }
            foreach (var entry in _lightBase.Palette)
            {
                if (entry.Description == null)
                {
                    entry.Description = GenerateMappingDescription(entry, _lightColorMappings);
                }
            }
            foreach (var entry in _darkBase.Palette)
            {
                if (entry.Description == null)
                {
                    entry.Description = GenerateMappingDescription(entry, _darkColorMappings);
                }
            }
            foreach (var entry in _lightPrimary.Palette)
            {
                if (entry.Description == null)
                {
                    entry.Description = GenerateMappingDescription(entry, _lightColorMappings);
                }
            }
            foreach (var entry in _darkPrimary.Palette)
            {
                if (entry.Description == null)
                {
                    entry.Description = GenerateMappingDescription(entry, _darkColorMappings);
                }
            }
        }
Пример #13
0
        /// <summary>
        /// 创建Sheet
        /// </summary>
        /// <param name="fileId">文件标识</param>
        /// <param name="sheetName">Sheet名称</param>
        /// <param name="headers">表头行字段信息,key:表头列名称   value:列对应的Converter</param>
        //[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.Synchronized)]
        public static ISheet CreteSheet(string fileId, string sheetName, List <ExcelKitAttribute> headers)
        {
            Inspector.Validation(!_workbooks.ContainsKey(fileId), "导出文件标识不存在");
            Inspector.Validation(headers == null, "Sheet表头信息不能为空");

            try
            {
                _semaphores[SemaphoreKeyConst.CreateSheet].Wait();

                headers = headers.OrderBy(t => t.Sort).ToList();

                //1.首次出现的Sheet记录下来(后面自动拆分Sheet要引用最初Sheet的信息)
                if (!_workbooks[fileId].SheetInfo.Exists(t => t.OriginSheetName == sheetName) && !sheetName.Contains(INNER_SHEET_CHAR))
                {
                    _workbooks[fileId].SheetInfo.Add(new InnerSheetInfo()
                    {
                        SheetIndex      = 0,
                        PropAttr        = headers,
                        OriginSheetName = sheetName,
                    });
                }
                else
                {
                    sheetName = sheetName.Replace(INNER_SHEET_CHAR, "");
                }

                sheetName = SafeSheetName(sheetName);
                Inspector.NotNullOrWhiteSpace(sheetName, "Sheet名称为空或无效");

                //2.创建Workbook
                _workbooks[fileId].Workbook = _workbooks[fileId].Workbook ?? new NPOI.XSSF.Streaming.SXSSFWorkbook();

                //3.获取或创建Sheet
                var sheet = GetSheet(fileId, sheetName);
                if (sheet == null)
                {
                    var cellCount = 0;
                    sheet = _workbooks[fileId].Workbook.CreateSheet(sheetName);

                    var headerRow = sheet.CreateRow(0);
                    foreach (var head in headers)
                    {
                        //忽略的字段
                        if (head.IsIgnore)
                        {
                            continue;
                        }
                        //列宽设置
                        if (head.Width > 0)
                        {
                            sheet.SetColumnWidth(cellCount, head.Width * 256);
                        }
                        //首行冻结
                        if (head.HeadRowFrozen)
                        {
                            sheet.CreateFreezePane(headers.Count, 1);
                        }
                        //首行筛选
                        if (head.HeadRowFilter)
                        {
                            sheet.SetAutoFilter(new CellRangeAddress(0, 0, 0, headers.Count - 1));
                        }
                        //单元格样式
                        var cell = headerRow.CreateCell(cellCount++);
                        {
                            ICellStyle cellStyle = _workbooks[fileId].Workbook.CreateCellStyle();
                            cellStyle.Alignment = TextAlignMapping.MapAlign(head.Align);

                            //前景色
                            if (head.ForegroundColor != Constraint.Enums.DefineColor.None)
                            {
                                cellStyle.FillPattern         = FillPattern.SolidForeground;
                                cellStyle.FillForegroundColor = ColorMapping.GetColorIndex(head.ForegroundColor);
                            }

                            //字体颜色
                            var font = _workbooks[fileId].Workbook.CreateFont();
                            font.FontHeightInPoints = 12;
                            font.FontName           = "Calibri";
                            font.Color = ColorMapping.GetColorIndex(head.FontColor);
                            cellStyle.SetFont(font);

                            //记录单元格样式
                            if (_workbooks[fileId].SheetInfo.Exists(t => t.OriginSheetName == sheetName) && !sheetName.Contains(INNER_SHEET_CHAR))
                            {
                                _workbooks[fileId].SheetInfo.FirstOrDefault(t => t.OriginSheetName == sheetName).CellStyles.Add(head.Code, cellStyle);
                            }

                            cell.CellStyle = cellStyle;                            //为单元格设置显示样式
                        }
                        cell.SetCellValue(head.Desc);
                    }
                    _workbooks[fileId].SheetCount = _workbooks[fileId].Workbook.NumberOfSheets;
                }
                return(sheet);
            }
            finally
            {
                _semaphores[SemaphoreKeyConst.CreateSheet].Release();
            }
        }
Пример #14
0
        public AnimationSet ToAnimationSet()
        {
            AnimationSet set = new AnimationSet();

            // Collect all colors used and stuff them in the palette
            var colors = new Dictionary <Color32, int>();
            int index  = 0;

            foreach (var anim in animations)
            {
                foreach (var animTrack in anim.tracks)
                {
                    foreach (var keyframe in animTrack.keyframes)
                    {
                        var color = keyframe.color;
                        if (color.a != 0)
                        {
                            int ignore = 0;
                            if (!colors.TryGetValue(keyframe.color, out ignore))
                            {
                                colors.Add(keyframe.color, index);
                                index++;
                            }
                        }
                        // else its a special color
                    }
                }
            }

            // Add the colors to the palette
            set.palette = new byte[colors.Count * 3];
            foreach (var ci in colors)
            {
                Color32 color = ColorMapping.RemapColor(ci.Key);
                int     i     = ci.Value;
                set.palette[i * 3 + 0] = color.r;
                set.palette[i * 3 + 1] = color.g;
                set.palette[i * 3 + 2] = color.b;
            }

            int currentTrackOffset    = 0;
            int currentKeyframeOffset = 0;

            var anims     = new List <Animation>();
            var tracks    = new List <AnimationTrack>();
            var rgbTracks = new List <RGBTrack>();
            var keyframes = new List <RGBKeyframe>();

            // Add animations
            for (int animIndex = 0; animIndex < animations.Count; ++animIndex)
            {
                var editAnim = animations[animIndex];
                var anim     = new Animation();
                anim.duration         = (ushort)(editAnim.duration * 1000.0f);
                anim.tracksOffset     = (ushort)currentTrackOffset;
                anim.trackCount       = (ushort)editAnim.tracks.Sum(t => t.ledIndices.Count);
                anim.animationEvent   = (byte)editAnim.@event;
                anim.specialColorType = (byte)editAnim.@specialColorType;
                anims.Add(anim);

                // Now add tracks
                for (int j = 0; j < editAnim.tracks.Count; ++j)
                {
                    var editTrack = editAnim.tracks[j];

                    foreach (var led in editTrack.ledIndices)
                    {
                        var track = new AnimationTrack();

                        var rgbTrack = new RGBTrack();
                        rgbTrack.keyframesOffset = (ushort)currentKeyframeOffset;
                        rgbTrack.keyFrameCount   = (byte)editTrack.keyframes.Count;
                        track.trackOffset        = (ushort)rgbTracks.Count;
                        rgbTracks.Add(rgbTrack);

                        track.ledIndex = (byte)led;

                        // Now add keyframes
                        for (int k = 0; k < editTrack.keyframes.Count; ++k)
                        {
                            var editKeyframe = editTrack.keyframes[k];
                            int colorIndex   = AnimationSet.SPECIAL_COLOR_INDEX;
                            if (editKeyframe.color.a != 0)
                            {
                                colorIndex = colors[editKeyframe.color];
                            }
                            var keyframe = new RGBKeyframe();
                            keyframe.setTimeAndColorIndex((ushort)(editKeyframe.time * 1000.0f), (ushort)colorIndex);
                            keyframes.Add(keyframe);
                        }
                        currentKeyframeOffset += editTrack.keyframes.Count;

                        tracks.Add(track);
                    }
                }
                currentTrackOffset += editAnim.tracks.Sum(t => t.ledIndices.Count);
            }

            set.keyframes  = keyframes.ToArray();
            set.rgbTracks  = rgbTracks.ToArray();
            set.tracks     = tracks.ToArray();
            set.animations = anims.ToArray();

            set.Compress();
            return(set);
        }
Пример #15
0
        /// <summary>
        /// Returns the depth-to-color mapping table.
        /// </summary>
        /// <param name="minDepth">The minimum reliable depth value.</param>
        /// <param name="maxDepth">The maximum reliable depth value.</param>
        /// <param name="depthTreatment">The depth treatment to apply.</param>
        /// <returns>The color mapping table.</returns>
        private ColorMapping[] GetColorMappingTable(int minDepth, int maxDepth, KinectDepthTreatment depthTreatment)
        {
            if (initializeColorMappingTable ||
                minDepth != currentMinDepth ||
                maxDepth != currentMaxDepth ||
                depthTreatment != currentDepthTreatment)
            {
                initializeColorMappingTable = false;
                currentMinDepth             = minDepth;
                currentMaxDepth             = maxDepth;
                currentDepthTreatment       = depthTreatment;

                // Initialize table to all zero (black)
                Array.Clear(colorMappingTable, 0, colorMappingTable.Length);

                // Fill in the color for an unknown depth value
                colorMappingTable[UnknownDepth] = UnknownDepthColor;

                switch (depthTreatment)
                {
                case KinectDepthTreatment.ClampUnreliableDepths:

                    // Fill in the "near" portion of the table with solid color
                    for (int i = 1; i < minDepth; i++)
                    {
                        colorMappingTable[i] = TooNearColor;
                    }

                    // Fill in the "far" portion of the table with solid color
                    for (int i = maxDepth + 1; i < MaxMaxDepth; i++)
                    {
                        colorMappingTable[i] = TooFarColor;
                    }

                    break;

                case KinectDepthTreatment.TintUnreliableDepths:

                    // Fill in the "near" portion of the table with a tinted gradient
                    for (int i = 1; i < minDepth; i++)
                    {
                        byte intensity = intensityTable[i];

                        // Apply cobalt tint
                        colorMappingTable[i] = new ColorMapping
                        {
                            R = (byte)(intensity >> 3),
                            G = (byte)(intensity >> 1),
                            B = intensity
                        };
                    }

                    // Fill in the "far" portion of the table with a tinted gradient
                    for (int i = maxDepth + 1; i < MaxMaxDepth; i++)
                    {
                        byte intensity = intensityTable[i];

                        // Apply cranberry tint
                        colorMappingTable[i] = new ColorMapping
                        {
                            R = intensity,
                            G = (byte)(intensity >> 3),
                            B = (byte)(intensity >> 1)
                        };
                    }

                    break;

                case KinectDepthTreatment.DisplayAllDepths:

                    // Fill in the "nearer than near" values with solid white
                    for (int i = 1; i < MinMinDepth; i++)
                    {
                        colorMappingTable[i] = NearestDepthColor;
                    }

                    // Adjust minDepth and maxDepth to allow unreliable values to be rendered
                    minDepth = MinMinDepth;
                    maxDepth = MaxMaxDepth;        // anything more distant will be black
                    break;
                }

                // Fill in values that will be rendered normally with a gray gradient
                for (int i = minDepth; i < maxDepth; i++)
                {
                    byte intensity = intensityTable[i];
                    colorMappingTable[i] = new ColorMapping
                    {
                        R = intensity,
                        G = intensity,
                        B = intensity
                    };
                }
            }

            return(colorMappingTable);
        }
Пример #16
0
        public WirererWorlder(int width, int height, int scale) : base(width, height, scale)
        {
            Name = "Wire World";

            ColorMapping.Add(WIRE, Color.Yellow);
            ColorMapping.Add(POSITIVE, Color.Red);
            ColorMapping.Add(NEGATIVE, Color.Blue);
            ColorMapping.Add(DEADWIRE, Color.DarkOrange);
            ColorMapping.Add(WIRECUTTER, Color.Green);
            ColorMapping.Add(BRIDGE, Color.Gray);
            ColorMapping.Add(PULSAR, Color.LightCoral);

            ActionMapping.Add(POSITIVE, (x, y) => {
                Write(x, y, NEGATIVE);
            });
            ActionMapping.Add(NEGATIVE, (x, y) => { Write(x, y, WIRE); });
            ActionMapping.Add(WIRE, (x, y) =>
            {
                int numPositive = GetNumNeightbors(x, y, POSITIVE);
                if (numPositive == 1 || numPositive == 2)
                {
                    Write(x, y, POSITIVE);
                }
            });
            ActionMapping.Add(BRIDGE, (x, y) =>
            {
                List <Tuple <Point, Point> > tuples = new List <Tuple <Point, Point> >();
                Point top    = new Point(x, y - 1);
                Point bottom = new Point(x, y + 1);
                Point left   = new Point(x - 1, y);
                Point right  = new Point(x + 1, y);
                tuples.Add(new Tuple <Point, Point>(top, bottom));
                tuples.Add(new Tuple <Point, Point>(bottom, top));
                tuples.Add(new Tuple <Point, Point>(left, right));
                tuples.Add(new Tuple <Point, Point>(right, left));

                foreach (Tuple <Point, Point> tuple in tuples)
                {
                    if (Read(tuple.Item1) == POSITIVE)
                    {
                        Point delta    = tuple.Item2 - tuple.Item1;
                        delta.X       /= 2;
                        delta.Y       /= 2;
                        Point newPoint = tuple.Item1 + delta;

                        while (Read(newPoint) == BRIDGE)
                        {
                            newPoint += delta;
                        }
                        if (Read(newPoint) == WIRE)
                        {
                            Write(newPoint, POSITIVE);
                        }
                    }
                }
            });
            ActionMapping.Add(WIRECUTTER, (x, y) =>
            {
                List <Tuple <Point, Point> > tuples = new List <Tuple <Point, Point> >();
                Point top    = new Point(x, y - 1);
                Point bottom = new Point(x, y + 1);
                Point left   = new Point(x - 1, y);
                Point right  = new Point(x + 1, y);
                tuples.Add(new Tuple <Point, Point>(top, bottom));
                tuples.Add(new Tuple <Point, Point>(bottom, top));
                tuples.Add(new Tuple <Point, Point>(left, right));
                tuples.Add(new Tuple <Point, Point>(right, left));

                foreach (Tuple <Point, Point> tuple in tuples)
                {
                    if (Read(tuple.Item1) == POSITIVE)
                    {
                        if (Read(tuple.Item2) == WIRE)
                        {
                            Write(tuple.Item2, DEADWIRE);
                        }
                        else if (Read(tuple.Item2) == DEADWIRE)
                        {
                            Write(tuple.Item2, WIRE);
                        }
                    }
                }
            });
            ActionMapping.Add(PULSAR, (x, y) => {
                if (Read(x + 1, y) == WIRE)
                {
                    Write(x + 1, y, POSITIVE);
                }
                if (Read(x - 1, y) == WIRE)
                {
                    Write(x - 1, y, POSITIVE);
                }
                if (Read(x, y + 1) == WIRE)
                {
                    Write(x, y + 1, POSITIVE);
                }
                if (Read(x, y - 1) == WIRE)
                {
                    Write(x, y - 1, POSITIVE);
                }
            });

            LeftPlace   = WIRE;
            Refreshrate = 6;
        }