private byte[] GetSprColorsIxs(Sprite x) { var colors = GetSprColors(x); var colorsIxs = colors.Select(c => Palettes.GetColorIx(c, Tic80Config.DEFAULT_PALETTE)); return(colorsIxs.ToArray()); }
public void Initialize(MapEditorPalettesToolVM vm) { _vm = vm; Palettes.Initialize(vm); //PaletteEditor.Initialize(vm.Parent.Root.PaletteEditor); }
private void TestGetBytes(byte[] data) { Palettes palettes = new Palettes(data); byte[] data2 = palettes.GetBytes(); Assert.AreEqual(data, data2); }
public Engine() { kbHandler = new KeyboardHandler(); //gpHandler = new PS4GamePadHandler(0); //TODO: Add support for PS4 controller reqHandler = new RequestHandler(); RenderState.activeGamepad = gpHandler; //Assign new palette to GLControl palette = Palettes.createPalettefromBasePalettes(); renderMgr = new renderManager(); //Init renderManager of the engine //Input Polling Timer inputPollTimer = new System.Timers.Timer(); inputPollTimer.Elapsed += new ElapsedEventHandler(input_poller); inputPollTimer.Interval = 1; //Camera Movement Timer cameraMovementTimer = new System.Timers.Timer(); cameraMovementTimer.Elapsed += new ElapsedEventHandler(camera_timer); cameraMovementTimer.Interval = 20; //cameraMovementTimer.Start(); Start in the main function //Systems Init actionSys = new ActionSystem(); animationSys = new AnimationSystem(); actionSys.SetEngine(this); animationSys.SetEngine(this); }
private void updateScreenByPalette(Palettes.Palette oldPal, Palettes.Palette pal) { var indexes = screenTexture.GetPixels32().Select(c => Palettes.GetColorIx(c, oldPal)); var newColors = indexes.ToList().Select(ix => Palettes.GetColor(ix, pal)).ToArray(); screenTexture.SetPixels32(newColors); }
public void DrawPixels(float x, float y, byte [] colorsIx, float width, int alphaColorIx, int colorIx = -1, int scale = 1) { int _x = (int)x; int _y = screenTexture.TransformY(y); int height = colorsIx.Length / (int)width; int i = 0; var pal = Tic80Config.Instance.Palette; var alphaColor = Palettes.GetColor(alphaColorIx, pal); for (int yy = 0; yy < height * scale; yy += scale) { for (int xx = 0; xx < width * scale; xx += scale) { var color = Palettes.GetColor(colorsIx[i++], pal); if (!System.Object.Equals(color, alphaColor)) { for (int n = 0; n < scale * scale; n++) { var posX = _x + xx + n % scale; var posY = _y + yy + n / scale; if (posX < 0 || posX >= screenTexture.width || posY < 0 || posY >= screenTexture.height) { continue; } screenTexture.SetPixel(posX, posY, colorIx < 0 ? color: Palettes.GetColor(colorIx, pal)); } } } } }
public ChassisVisuals( ) { Decals.Add(new Decal { ID = 10000, Usage = 0xff, Color = 0xffffffff, Transform = new Half[] { (Half)0.052460, (Half)0.019623, (Half)0, (Half)0.007484, (Half)(-0.020020), (Half)(-0.051758), (Half)0.018127, (Half)(-0.048492), (Half)0.021362, (Half)0.108154, (Half)(-0.105469), (Half)1.495117, } }); Colors.Add(0x10000020u); Colors.Add(0xc8000000u); Colors.Add(0xfe206281u); Colors.Add(0xc8000000u); Colors.Add(0xc8000000u); Colors.Add(0xf5621861u); Colors.Add(0xf5621861u); Palettes.Add(new Palette { ID = 85163, Type = Enums.Visuals.PaletteType.FullBody }); Patterns.Add(new Pattern { ID = 10022, Usage = 0x0, Transform = new Half[] { 0, Half.ToHalf((ushort)16384u), 0, 0 } }); }
private byte[,] ResolvePalette(bool showMsg = false) { if (AutoLoadPalette.Checked) // checkbox checked: try to load palette from file { if (PalettePath.Text.Length > 0) { var palette = new HawkFile(PalettePath.Text); if (palette.Exists) { var data = Palettes.Load_FCEUX_Palette(palette.ReadAllBytes()); if (showMsg) { _mainForm.AddOnScreenMessage($"Palette file loaded: {palette.Name}"); } return(data); } return(_settings.Palette); } // no filename: interpret this as "reset to default" if (showMsg) { _mainForm.AddOnScreenMessage("Standard Palette set"); } return((byte[, ])Palettes.QuickNESPalette.Clone()); } // checkbox unchecked: we're reusing whatever palette was set return(_settings.Palette); }
public PaletteColorPicker() { RobustXamlLoader.Load(this); IoCManager.InjectDependencies(this); _tex = _resourceCache.GetResource <TextureResource>("/Textures/Interface/Nano/button.svg.96dpi.png"); var i = 0; foreach (var palette in _prototypeManager.EnumeratePrototypes <ColorPalettePrototype>()) { Palettes.AddItem(palette.Name); Palettes.SetItemMetadata(i, palette); // ew i += 1; } Palettes.OnItemSelected += args => { Palettes.SelectId(args.Id); SetupList(); }; Palettes.Select(0); SetupList(); }
private void applyStyleRules(Style style, Entity entity, bool size) { if (style != null) { foreach (var rule in entity.Rules) { var property = style.propertyValuesMap.SingleOrDefault(e => (e.property == rule.Property)); if ((!size) && (property != null)) { if ((property.property == "Height") || (property.property == "Width")) { property = null; } } if ((property != null) && (property.value != "Default") && (property.value != "%Palette.Default%")) { var palette = Palettes.SingleOrDefault(e => e.name == property.value.Replace("%", "").Replace("Palette.", "")); if (palette != null) { rule.InvariantScript = palette.value.Replace(".RESERVED", "").Replace("%", ""); } if (rule.InvariantScript.Contains(".RESERVED")) { rule.InvariantScript = property.value.Replace(".RESERVED", "").Replace("%", ""); } } } } }
// Sets the palette to the right palette when selected - simple problem as the enum is reset, so I've added a float to the material which saves said info private void SetPalette() { int Palette = (int)Mat.GetFloat("_PaletteSelected"); switch (Palette) { case 1: Pal = Palettes.Palette1; break; case 2: Pal = Palettes.Palette2; break; case 3: Pal = Palettes.Palette3; break; case 4: Pal = Palettes.Palette4; break; default: break; } }
private void InitColors() { for (var i = 0; i < 12; i++) { var palette = new ColorPickerPaletteViewModel { Index = i }; var hue = (i * 30f / 360f); for (var j = 0; j < ColorCount; j++) { var row = j / 4; var column = j % 4; var saturation = column * 0.25f + 0.25f; var brightness = 1f - row * 0.12f; var color = Color.FromHsb(hue, saturation, brightness); palette.Colors.Add(color); } Palettes.Add(palette); } }
/// <summary> /// Set the default values of the shader. /// </summary> public override void ResetDefaultValues() { palette = Palettes.One; pixelSize = 4; threshold = 1.0f; base.ResetDefaultValues(); }
private void rt_addRootScene(string filename) { //Once the new scene has been loaded, //Initialize Palettes Palettes.set_palleteColors(); //Clear Systems actionSys.CleanUp(); animationSys.CleanUp(); //Clear Resources resMgr.Cleanup(); resMgr.Init(); RenderState.activeResMgr = resMgr; ModelProcGen.procDecisions.Clear(); RenderState.rootObject = null; RenderState.activeModel = null; //Clear Gizmos RenderState.activeGizmo = null; //Clear RenderStats RenderStats.ClearStats(); //Stop animation if on bool animToggleStatus = RenderState.renderSettings.ToggleAnimations; RenderState.renderSettings.ToggleAnimations = false; //Setup new object Model root = GEOMMBIN.LoadObjects(filename); //Explicitly add default light to the rootObject root.children.Add(resMgr.GLlights[0]); root.updateLODDistances(); root.update(); //Refresh all transforms root.setupSkinMatrixArrays(); //Populate RenderManager renderMgr.populate(root); //Clear Instances renderMgr.clearInstances(); root.updateMeshInfo(); //Update all mesh info root.selected = 1; RenderState.rootObject = root; //RenderState.activeModel = root; //Set the new scene as the new activeModel //Reinitialize gizmos RenderState.activeGizmo = new TranslationGizmo(); //Restart anim worker if it was active RenderState.renderSettings.ToggleAnimations = animToggleStatus; }
private void TestGetColorIndexAt(byte[] gfx, byte[] palData, byte properties) { Palettes palettes = new Palettes(palData); Tile2bpp tile = new Tile2bpp(gfx, palettes, properties); Palette palette = new Palette(null, 0, palData); TileTests.TestGetColorIndexAt(tile, palette, false); }
public static void Paint(Palettes palette, Coordinate coordinate, string symbol) { var retrievedColors = PaletteDictionary[palette]; if(retrievedColors != null) SetColor(retrievedColors.Foreground, retrievedColors.Background); Console.SetCursorPosition(coordinate.X, coordinate.Y); Console.Write(symbol); ResetPalette(); }
private byte[] GetSpritesFromSpec(string spec) { var bytes = new List <byte>(); bytes.AddRange(Enumerable.Repeat((byte)0, 16)); var spriteConfig = SpriteConfig.Read(spec, Palettes.Read(this.palettesTextBox.Text)); for (var i = 1; i < 256; i++) { var sprite = spriteConfig.Sprites.FirstOrDefault(s => s.Id == i); if (sprite != null) { var lowBits = new List <byte>(); var highBits = new List <byte>(); var image = sprite.GetSprite(); for (var y = 0; y < Constants.SpriteHeight; y++) { byte lowBit = 0; byte highBit = 0; for (var x = 0; x < Constants.SpriteWidth; x++) { lowBit = (byte)(lowBit << 1); highBit = (byte)(highBit << 1); var pixel = spriteConfig.PaletteMappings[sprite.Mapping].ColorMappings.First(c => c.Color == image.GetPixel(x, y)).To; if (pixel == 1 || pixel == 3) { // low bit set lowBit |= 1; } if (pixel == 2 || pixel == 3) { // high bit set highBit |= 1; } } lowBits.Add(lowBit); highBits.Add(highBit); } bytes.AddRange(lowBits); bytes.AddRange(highBits); } else { bytes.AddRange(Enumerable.Repeat((byte)0, 16)); } } return(bytes.ToArray()); }
public static void SetPalette(Palettes palette) { var retrievedPalette = PaletteDictionary[palette]; if (retrievedPalette == null) throw new ConfigurationErrorsException("Palette is not set"); Console.ForegroundColor = retrievedPalette.Foreground; Console.BackgroundColor = retrievedPalette.Background; }
void Update() { for (int i = 0; i < 1024; i++) { var color = Palettes.GetColor(Random.Range(8, 16), Palettes.Palette.DB16); texture.PixSetPixel(Random.Range(0, 240), Random.Range(0, 136), color, mask: mainMask, maskWidth: texture.width, maskHeight: texture.height); } texture.Apply(); }
/** * Используется для получения значения цвета пикселя на экране. * * https://nesbox.gitbooks.io/tic-80-rus/content/api/draw/pix.html * * The function can be used also to interrogate the color of a pixel in the screen. * https://github.com/nesbox/TIC-80/wiki/pix */ public int pix(float x, float y) { if (IsOffScreen(x, y)) { return(0); } var color = screenTexture.TakePixel(x, y); return(Palettes.GetColorIx(color, tic80Config.Palette)); }
/// <summary> /// Fill the palette combobox with the available palette representations. /// </summary> public void FillPaletteComboBox() { try { Palettes palettes = AppContext.Palettes; PixelFormat pixelFormat = PixelFormats.Indexed8; int width = (int)cbImageRepresentation.Width - 24; var height = (int)cbImageRepresentation.Height; int stride = width * (pixelFormat.BitsPerPixel / 8); for (int i = 0; i < palettes.Count; i++) { // get the palette data KeyValuePair <string, BitmapPalette> kvp = palettes.GetNamePalettePair(i); string paletteName = kvp.Key; var comboItem = new Image(); // the bitmapsource... // allocate the bitmap's bits var bits = new byte[height * stride]; // fill the bits with colorinformation for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { bits[x + (y * stride)] = (byte)((x * 256) / width); } } // finally create the BitmapSource object BitmapSource bitmap = BitmapSource.Create(width, height, 96.0, 96.0, PixelFormats.Indexed8, kvp.Value, bits, stride); comboItem.Source = bitmap; comboItem.ToolTip = paletteName; comboItem.Stretch = Stretch.Fill; comboItem.VerticalAlignment = VerticalAlignment.Stretch; comboItem.HorizontalAlignment = HorizontalAlignment.Stretch; cbImageRepresentation.Items.Add(comboItem); cbImageRepresentation.Items.Add(paletteName); } this.cbImageRepresentation.SelectedIndex = this.paletteIndex; var currentImage = cbImageRepresentation.Items[cbImageRepresentation.SelectedIndex] as Image; if (currentImage != null) { this.paletteToolTip.Source = currentImage.Source; this.cbImageRepresentation.ToolTip = this.paletteToolTip; } } catch (Exception e) { Util.ReportException(e); } }
public Theme(TextItem nameItem, Palettes palettes, RoadTileset roadTileset, Background background) { this.NameItem = nameItem; this.Palettes = palettes; this.Palettes.Theme = this; this.RoadTileset = roadTileset; this.Background = background; this.Palettes.PropertyChanged += this.OnPropertyChanged; this.RoadTileset.PropertyChanged += this.OnPropertyChanged; this.Background.PropertyChanged += this.OnPropertyChanged; }
public void Reset() { this.palette = Palettes.RandomPalette(); this.palette = Palettes.StaryNight; this.palette.Randomize(); Camera.main.backgroundColor = this.palette.Item(0); if (this.brush != null) { this.brush.SetPalette(this.palette); } this.boidManager.Reset(); }
private static RoadTileset GetRoadTileset(Palettes palettes, byte[] tilePaletteIndexes, byte[][] tileGfx, RoadTileGenre[] tileGenres) { RoadTile[] tiles = new RoadTile[RoadTileset.TileCount]; Palette firstPalette = palettes[0]; for (int i = 0; i < tileGfx.Length; i++) { Palette palette = palettes[tilePaletteIndexes[i]]; tiles[i] = new RoadTile(tileGfx[i], palette, tileGenres[i], firstPalette); } return(new RoadTileset(tiles)); }
private void LoadFiles() { this.palettes = Palettes.Read(palettesTextBox.Text); this.config = SpriteConfig.Read(specTextBox.Text, this.palettes); this.framesListBox.Items.Clear(); this.animationListBox.Items.Clear(); foreach (var animation in config.Animations) { this.animationListBox.Items.Add(animation); } this.animationListBox.SelectedIndex = 0; }
private void WindowPalette(int i) { int j; i = i % 32; for (j = 0; j <= 5; j++) { Palettes.CopyPalette(1, 0xE0 + ((i + j) % 32)); } for (j = 6; j <= 31; j++) { Palettes.CopyPalette(16, 0xE0 + ((i + j) % 32)); } }
private void PillarPalette(int i) { const int ShadowPos = 28; const int ShadowEnd = 36; int j, k, l; byte c1, c2, c3, Base; Base = Buffers.Options.BackGrColor1; c1 = Palette [Base, 0] / 4; //Palette is a Unit used for manipulating any color in 256 color video mode c2 = Palette [Base, 1] / 4; //Going to need to use something to replace palette. c3 = Palette [Base, 2] / 4; i = i % 60; j = 0; k = 1; while (k < 15) { for (l = j; l <= k; l++) { Palettes.OutPalette(0xC0 + ((l + i) % 60), c1 + k, c2 + k, c3 + k); Palettes.OutPalette(0xC0 + ((ShadowPos + i - l) % 60), c1 + k, c2 + k, c3 + k); } j = k; k = k + 1; } for (j = ShadowPos; j <= ShadowEnd; j++) { if (c1 > 0) { c1--; } if (c2 > 0) { c2--; } if (c3 > 0) { c3--; } Palettes.OutPalette(0xC0 + ((j + i) % 60), c1, c2, c3); } Base = Buffers.Options.BackGrColor2; c1 = Palette [Base, 0] / 4; c2 = Palette [Base, 1] / 4; c3 = Palette [Base, 2] / 4; for (j = ShadowEnd + 1; j <= 59; j++) { Palettes.OutPalette(0xC0 + ((i + j) % 60), c1, c2, c3); } }
private void drawBack() { // draw back var column_width = 240 / 16; for (var i = 0; i < 16; ++i) { texture.PixRectangle(i * column_width, 0, column_width, 136, Palettes.GetColor(i, Palettes.Palette.DB16), true); } texture.PixCircle(50, 50, 30, Color.white, true); texture.Apply(); // get back colors backColors = texture.GetPixels32(); }
private void TestGenerateGraphics(byte[] palData, byte[] gfx, Tile2bppProperties properties) { byte[] palsData = new byte[512]; Buffer.BlockCopy(palData, 0, palsData, 0, palData.Length); Palettes pals = new Palettes(palsData); byte props = properties.GetByte(); Tile2bpp tile = new Tile2bpp(gfx, pals, props); Tile2bpp tile2 = new Tile2bpp(new byte[gfx.Length], pals, props); tile2.Bitmap = tile.Bitmap; // Trigger graphics update Assert.AreEqual(gfx, tile2.Graphics); }
private void LoadFiles() { this.palettes = Palettes.Read(palettesTextBox.Text); this.config = SpriteConfig.Read(specTextBox.Text, this.palettes); CreateCachedBitmaps(); this.bulletsListBox.Items.Clear(); foreach (var bullet in config.Bullets) { this.bulletsListBox.Items.Add(bullet); } this.bulletsListBox.SelectedIndex = 0; ValidateBullets(); }
/// <summary> /// Register a palette /// </summary> /// <param name="p"></param> /// <param name="doubleClick"></param> private Palette AddPalette(BitmapCollection collection, RoutedCommand doubleClick = null) { Palette p = new Palette(collection); if (doubleClick != null) { p.DefaultDoubleClick = doubleClick; } p.OnThumbnailSelected += event_ThumbnailSelected; if (Palettes == null) { Palettes = new ObservableCollection <Palette>(); } Palettes.Add(p); return(p); }
private static BackgroundTileset GetBackgroundTileset(Palettes palettes, byte[][] tileGfx) { BackgroundTile[] tiles = new BackgroundTile[BackgroundTileset.TileCount]; for (int i = 0; i < Math.Min(tileGfx.Length, tiles.Length); i++) { tiles[i] = new BackgroundTile(tileGfx[i], palettes); } // If the tileset isn't full, fill in the rest of the tileset with empty tiles for (int i = tileGfx.Length; i < BackgroundTileset.TileCount; i++) { tiles[i] = new BackgroundTile(new byte[16], palettes); } return(new BackgroundTileset(tiles)); }
/// <summary> /// Creates a new map /// </summary> /// <param name="mapWidth">Width</param> /// <param name="mapHeight">Height</param> /// <param name="percentWalls">Percent walls</param> /// <param name="randomBlocks">Randomblocks to include, default is null</param> /// <param name="mapPalette">Palette to use</param> /// <returns>Generated map</returns> public Map CreateMap(int mapWidth, int mapHeight, int percentWalls = 40, List<Block> randomBlocks = null, Palettes mapPalette = Palettes.Cave) { var map = new Map { Id = new Guid(), MapHeight = mapHeight, MapWidth = mapWidth, MapPalette = mapPalette, ActionBlocks = new List<BlockTile>() }; RandomFillMap(map, percentWalls); MakeCaverns(map); if (randomBlocks != null) { foreach (var randomBlock in randomBlocks) { PlaceRandomBlock(randomBlock, map); } } return map; }