Ejemplo n.º 1
0
    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));
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    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);
    }
Ejemplo n.º 3
0
    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();
    }
Ejemplo n.º 4
0
    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();
    }
Ejemplo n.º 5
0
    void Start()
    {
        ScreenImage.texture = new Texture2D(240, 136);
        texture             = ScreenImage.texture as Texture2D;

        // draw back
        var clearColors = new Color32[texture.width * texture.height];

        texture.PixClear(ref clearColors, Color.grey);
        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);
        }

        // get back colors
        backColors = texture.GetPixels();
    }
Ejemplo n.º 6
0
    void Update()
    {
        texture.PixClear(ref clearColors, Color.black);

        foreach (var b in balls)
        {
            //move the ball
            b.x = b.x + b.dx;
            b.y = b.y + b.dy;
            //check right/left walls
            if (b.x >= 240 - b.r)
            {
                b.x  = 240 - b.r - 1; //constraints inside the wall
                b.dx = -b.dx;         //reverse direction
            }
            else if (b.x < b.r)
            {
                b.x  = b.r;
                b.dx = -b.dx;
            }
            //check bottom/top walls
            if (b.y >= 136 - b.r)
            {
                b.y  = 136 - b.r - 1;
                b.dy = -b.dy;
            }
            else if (b.y < b.r)
            {
                b.y  = b.r;
                b.dy = -b.dy;
            }
            //draw balls
            texture.PixCircle(b.x, b.y, b.r, Palettes.GetColor(b.c, Palettes.Palette.DB16), true);
            texture.PixCircle(b.x + b.r / 4, b.y - b.r / 4, b.r / 4, Palettes.GetColor(b.c + 7, Palettes.Palette.DB16), true);
        }
        texture.Apply();
    }
Ejemplo n.º 7
0
    private void border(int colorIx)
    {
        texture.PixRectangle(0, 0, FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT, getColor(colorIx), true, borderMask, FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);

        var color = Palettes.GetColor(UnityEngine.Random.Range(8, 16), Palettes.Palette.ZX_Spectrum_Orthodox);
        var y     = UnityEngine.Random.Range(0, 192);

        texture.PixLine(0, y, FULL_SCREEN_WIDTH, y, color, borderMask, FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);

        var x = UnityEngine.Random.Range(0, 256);
        var r = UnityEngine.Random.Range(0, 50);

        texture.PixCircle(x, y, r, color, true, borderMask, FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);

        x += 30;
        y += 30;
        texture.PixEllipseFilled(x, y, 50, 25, 45, color, borderMask, FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);

        x += 30;
        y += 30;
        texture.PixEllipseRect(x, y, x + 50, y + 25, color, borderMask, FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);

        var X0 = 50;
        var Y0 = 0;
        var X1 = 30;
        var Y1 = 0;
        var X2 = 30;
        var Y2 = 20;

        texture.PixQuadBezier(x + X0, y + Y0, x + X1, y + Y1, x + X2, y + Y2, color, borderMask, FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);

        x += 30;
        y += 30;

        texture.PixTriangle(x + X0, y + Y0, x + X1, y + Y1, x + X2, y + Y2, color, true, borderMask, FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);
        // texture.PixTriangle (x + X0, y + Y0, x + X1, y + Y1, x + X2, y + Y2, color, true);
    }
Ejemplo n.º 8
0
 private Color32 GetColor(int colorIx)
 {
     return(Palettes.GetColor(colorIx, tic80Config.Palette));
 }
Ejemplo n.º 9
0
 private Color32 getColor(int colorIx)
 {
     return(Palettes.GetColor(colorIx, Palettes.Palette.ZX_Spectrum_Orthodox));
 }