コード例 #1
0
ファイル: ECPainting.cs プロジェクト: lindyw/imseCAVELauncher
 /* ============================== Line ============================== */
 public void Line(Vector2 start, Vector2 end, ECBrush brush)
 {
     if (start != end)
     {
         Draw(start, end, brush);
     }
 }
コード例 #2
0
ファイル: ECPainter.cs プロジェクト: lindyw/imseCAVELauncher
    // Use this for initialization
    void Start()
    {
        if (path == null)
        {
            path = "Paints/paing.png";
        }
        start        = none;
        end          = start;
        press        = start;
        currentStamp = stamp;
        boardSize    = gameObject.GetComponent <RectTransform>();
        SetBoard();
        brushSetting    = new ECBrush[6];
        brushSetting[0] = new ECBrush(ECBrush.Tool.Pen, 6, 0.75f, Color.black);
        brushSetting[1] = new ECBrush(ECBrush.Tool.Eraser, 12, 0.9f, Color.black);
        brushSetting[2] = new ECBrush(ECBrush.Tool.Line, 3, 0.9f, Color.black);
        brushSetting[3] = new ECBrush(ECBrush.Tool.Rectangle, 3, 0.75f, Color.black);
        brushSetting[4] = new ECBrush(ECBrush.Tool.Ellipse, 3, 0.75f, Color.black);
        if (stamp == null)
        {
            brushSetting[5] = new ECBrush(ECBrush.Tool.Stamp, 6, 0.75f, Color.white);
        }
        else
        {
            brushSetting[5] = new ECBrush(ECPainting.ScaleTexture(stamp, 10), 10, 0.75f, Color.white);
        }

        SetECBrush();
    }
コード例 #3
0
ファイル: ECPainting.cs プロジェクト: lindyw/imseCAVELauncher
    /* ============================== Stamp ============================== */
    public void FillStamp(Vector2 point, ECBrush brush)
    {
        if (point.x < 0 || point.y < 0 || point.x > width || point.y > height)
        {
            return;
        }
        point.x -= brush.width / 2;
        point.y -= brush.height / 2;
        Rect desRect  = new Rect(point.x, point.y, brush.width, brush.height);
        Rect sourRect = desRect;

        desRect  = DestRect(desRect, texture);
        sourRect = SourRect(sourRect, desRect);

        Color[] colors = brush.stamp.texture.GetPixels((int)sourRect.x, (int)sourRect.y, (int)sourRect.width, (int)sourRect.height);
        Map(desRect.x, desRect.y, desRect.width, desRect.height, colors, true);
    }
コード例 #4
0
ファイル: ECPainting.cs プロジェクト: lindyw/imseCAVELauncher
    /* ============================== Rect ============================== */
    public void StrokeRect(Rect rect, ECBrush brush)
    {
        if (brush.size <= 1)
        {
            StrokeRect(rect, brush.color);
            return;
        }
        int rx = (int)rect.x;
        int ry = (int)rect.y;
        int rw = (int)rect.width;
        int rh = (int)rect.height;

        if (rw < 1 || rh < 1)
        {
            return;
        }
        Draw(rx, ry, rx + rw, ry, brush);
        Draw(rx, ry + rh, rx + rw, ry + rh, brush);
        Draw(rx, ry, rx, ry + rh, brush);
        Draw(rx + rw, ry, rx + rw, ry + rh, brush);
    }
コード例 #5
0
ファイル: ECPainter.cs プロジェクト: lindyw/imseCAVELauncher
 public void SetECBrush(int tool)
 {
     if (tool == this.tool)
     {
         brushSetting[tool] = new ECBrush(brushSetting[tool].tool, brush.size, brush.hardness, brush.color);
     }
     if (stamp != currentStamp)
     {
         currentStamp    = stamp;
         brushSetting[5] = new ECBrush(ECPainting.ScaleTexture(stamp, brushSetting[5].size), brushSetting[5].size, brushSetting[5].hardness, brushSetting[5].color);
     }
     if (tool < 0)
     {
         tool = 0;
     }
     this.tool            = tool;
     brush                = brushSetting[tool];
     brushOutline.texture = brush.outline;
     brushOutline.GetComponent <RectTransform>().sizeDelta = new Vector2(brush.width, brush.height);
     Reset();
 }
コード例 #6
0
ファイル: ECPainting.cs プロジェクト: lindyw/imseCAVELauncher
    public void StrokeRect(Vector2 start, Vector2 end, ECBrush brush)
    {
        Rect rect = TwoPointRect(start, end);

        StrokeRect(rect, brush);
    }
コード例 #7
0
ファイル: ECPainting.cs プロジェクト: lindyw/imseCAVELauncher
    public void StrokeRect(Vector2 point, int size, ECBrush brush)
    {
        Rect rect = new Rect(point.x - size, point.y - size, size * 2, size * 2);

        StrokeRect(rect, brush);
    }
コード例 #8
0
ファイル: ECPainting.cs プロジェクト: lindyw/imseCAVELauncher
 public void Line(float xs, float ys, float xe, float ye, ECBrush brush)
 {
     Line(new Vector2(xs, ys), new Vector2(xe, ye), brush);
 }
コード例 #9
0
ファイル: ECPainting.cs プロジェクト: lindyw/imseCAVELauncher
 public void Draw(float x, float y, ECBrush brush)
 {
     Draw(new Vector2(x, y), new Vector2(x, y), brush);
 }
コード例 #10
0
ファイル: ECPainting.cs プロジェクト: lindyw/imseCAVELauncher
    public void StrokeEllipse(Vector2 start, Vector2 end, ECBrush brush)
    {
        Ellipse e = TwoPointEllipse(start, end);

        StrokeEllipse(e.center, (int)e.w, (int)e.h, brush);
    }
コード例 #11
0
ファイル: ECPainting.cs プロジェクト: lindyw/imseCAVELauncher
 public void Draw(Vector2 point, ECBrush brush)
 {
     Draw(point, point + new Vector2(0, 1), brush);
 }
コード例 #12
0
ファイル: ECPainting.cs プロジェクト: lindyw/imseCAVELauncher
    /* ============================== Draw ============================== */
    public void Draw(Vector2 start, Vector2 end, ECBrush brush)
    {
        if (brush.size <= 1)
        {
            Line(start, end, brush.color);
            return;
        }
        brush.size += 1;
        if (end == start)
        {
            end.y++;
        }
        Rect rect = new Rect(Mathf.Min(start.x, end.x) - brush.size, Mathf.Min(start.y, end.y) - brush.size, Mathf.Abs(start.x - end.x) + brush.size * 2, Mathf.Abs(start.y - end.y) + brush.size * 2);

        rect = DestRect(rect, texture);
        int rx = (int)rect.x;
        int ry = (int)rect.y;
        int rw = (int)rect.width;
        int rh = (int)rect.height;

        if (rx < 0 || ry < 0 || rw < 0 || rh < 0)
        {
            return;
        }
        //Color[] colors = preview.GetPixels(rx, ry, rw, rh);
        //Color[] colors = new Color[rw * rh];
        //for (int i = 0; i < colors.Length; i++) colors[i] = Color.clear;
        for (int y = ry; y < ry + rh; y++)
        {
            for (int x = rx; x < rx + rw; x++)
            {
                Vector2 p = new Vector2(x, y);
                float   d = StraightLine.Distance(p, start, end);
                if (d > brush.size)
                {
                    continue;
                }
                else if (d <= brush.size)
                {
                    int   i = (x - rx) + (y - ry) * rw;
                    float a = (brush.size - d) / (brush.size * (1 - brush.hardness));
                    a = d / (float)brush.size <= brush.hardness ? brush.color.a : a * brush.color.a;
                    if (preview.GetPixel(x, y).a < a) //colors[i].a < a)
                    {
                        Color c = brush.color;
                        if (brush.tool == ECBrush.Tool.Eraser)
                        {
                            c = origin[x + y * width];
                        }
                        if (d >= brush.size - 1)
                        {
                            c.a = 0;
                        }
                        else
                        {
                            c.a = a;
                        }
                        Map(x, y, c);
                        //colors[i] = c;
                        //Map(x, y, colors[i]);
                    }
                }
            }
        }
        //Map(rx, ry, rw, rh, colors);
    }
コード例 #13
0
ファイル: ECPainting.cs プロジェクト: lindyw/imseCAVELauncher
    public void StrokeCircle(Vector2 point, int size, ECBrush brush)
    {
        Circle c = new Circle(point.x, point.y, size);

        StrokeCircle(c, brush);
    }
コード例 #14
0
ファイル: ECPainting.cs プロジェクト: lindyw/imseCAVELauncher
    public void StrokeCircle(Vector2 start, Vector2 end, ECBrush brush)
    {
        Circle c = TwoPointCircle(start, end);

        StrokeCircle(c, brush);
    }
コード例 #15
0
ファイル: ECPainting.cs プロジェクト: lindyw/imseCAVELauncher
    /* ============================== Circle ============================== */
    public void StrokeCircle(Circle circle, ECBrush brush)
    {
        if (circle.r < 1)
        {
            return;
        }
        if (brush.size <= 1)
        {
            StrokeEllipse(circle.ellipse, brush.color);
            return;
        }
        brush.size += 1;
        //if (end == start) end.y++;
        Rect rect = new Rect(circle.x - circle.r - brush.size, circle.y - circle.r - brush.size, circle.r * 2 + brush.size * 2, circle.r * 2 + brush.size * 2);

        rect = DestRect(rect, texture);
        int rx = (int)rect.x;
        int ry = (int)rect.y;
        int rw = (int)rect.width;
        int rh = (int)rect.height;

        if (rx < 0 || ry < 0 || rw < 0 || rh < 0)
        {
            return;
        }
        //Color[] colors = preview.GetPixels(rx, ry, rw, rh);
        //Color[] colors = new Color[rw * rh];
        //for (int i = 0; i < colors.Length; i++) colors[i] = Color.clear;
        for (int y = ry; y < ry + rh; y++)
        {
            for (int x = rx; x < rx + rw; x++)
            {
                Vector2 p = new Vector2(x, y);
                float   d = Circle.Distance(circle, p);
                if (d > brush.size)
                {
                    continue;
                }
                else if (d <= brush.size)
                {
                    int   i = (x - rx) + (y - ry) * rw;
                    float a = (brush.size - d) / (brush.size * (1 - brush.hardness));
                    a = d / (float)brush.size <= brush.hardness ? brush.color.a : a * brush.color.a;
                    if (preview.GetPixel(x, y).a < a) //colors[i].a < a)
                    {
                        Color c = brush.color;
                        if (d >= brush.size - 1)
                        {
                            c.a = 0;
                        }
                        else
                        {
                            c.a = a;
                        }
                        Map(x, y, c);
                        //colors[i] = c;
                        //Map(x, y, colors[i]);
                    }
                }
            }
        }
        //Map(rx, ry, rw, rh, colors);
    }
コード例 #16
0
ファイル: ECPainting.cs プロジェクト: lindyw/imseCAVELauncher
 public void StrokeEllipse(Ellipse ellipse, ECBrush brush)
 {
     StrokeEllipse(ellipse.center, (int)ellipse.w, (int)ellipse.h, brush);
 }
コード例 #17
0
ファイル: ECPainting.cs プロジェクト: lindyw/imseCAVELauncher
 public void Draw(float xs, float ys, float xe, float ye, ECBrush brush)
 {
     Draw(new Vector2(xs, ys), new Vector2(xe, ye), brush);
 }
コード例 #18
0
ファイル: ECPainting.cs プロジェクト: lindyw/imseCAVELauncher
    /* ============================== Ellipse ============================== */
    //public void StrokeEllipse(Vector2 center, int width, int height, ECBrush brush)
    //{
    //    brush.size += 1;
    //    Rect rect = new Rect(center.x - width - brush.size, center.y - height - brush.size, width * 2 + brush.size * 2, height * 2 + brush.size * 2);

    //    int rx = (int)rect.x;
    //    int ry = (int)rect.y;
    //    int rw = (int)rect.width;
    //    int rh = (int)rect.height;
    //    int rm = Mathf.Max(rw, rh);
    //    int am = Mathf.Max(width, height);
    //    Vector2 rc = center - new Vector2(rw - rm, rh - rm) * 0.5f;
    //    if (rx < 0 || ry < 0 || rw < 0 || rh < 0) return;
    //    Color[] colors = texture.GetPixels(rx, ry, rm, rm);
    //    Color[] colors = new Color[rm * rm];
    //    for (int i = 0; i < colors.Length; i++) colors[i] = Color.clear;
    //    for (int y = ry; y < ry + rm; y++)
    //    {
    //        for (int x = rx; x < rx + rm; x++)
    //        {
    //            Vector2 p = new Vector2(x, y);
    //            float d = Mathf.Abs(Vector2.Distance(p, rc) - am);
    //            else d = ECUtility.MinDistance(p, ECUtility.VerticalPoints(p, center, width, height));
    //            if (d > brush.size)
    //            {
    //                continue;
    //            }
    //            else if (d <= brush.size)
    //            {
    //                int i = (x - rx) + (y - ry) * rm;
    //                float a = (brush.size - d) / (brush.size * (1 - brush.hardness));
    //                a = d / (float)brush.size <= brush.hardness ? brush.color.a : a * brush.color.a;
    //                if (colors[i].a < a)
    //                {
    //                    Color c = brush.color;
    //                    if (d >= brush.size - 1) c.a = 0;
    //                    else c.a = a;
    //                    colors[i] = c;
    //                }
    //            }
    //        }
    //    }
    //    Texture2D tmp = new Texture2D(rm, rm);
    //    tmp.SetPixels(colors);
    //    tmp.Apply();
    //    tmp = Painting.ResizeTexture(rw, rh, tmp);
    //    center.x -= rw / 2;
    //    center.y -= rh / 2;
    //    Rect desRect = new Rect(center.x, center.y, rw, rh);
    //    Rect sourRect = new Rect(center.x, center.y, rw, rh);

    //    desRect = DestRect(desRect, texture);
    //    sourRect = SourRect(sourRect, desRect);
    //    colors = tmp.GetPixels((int)sourRect.x, (int)sourRect.y, (int)sourRect.width, (int)sourRect.height);
    //    Map(desRect.x, desRect.y, desRect.width, desRect.height, colors);
    //}
    public void StrokeEllipse(Vector2 point, int width, int height, ECBrush brush)
    {
        if (width < 1 || height < 1)
        {
            return;
        }
        if (brush.size <= 1)
        {
            StrokeEllipse(point, width, height, brush.color);
            return;
        }
        int xc = (int)point.x;
        int yc = (int)point.y;
        int a  = width;
        int b  = height;

        if (a == 0)
        {
            a = 1;
        }
        if (b == 0)
        {
            b = 1;
        }
        int a2    = 2 * a * a;
        int b2    = 2 * b * b;
        int error = a * a * b;
        int x     = 0;
        int y     = b;
        int stopy = 0;
        int stopx = a2 * b;

        while (stopy <= stopx)
        {
            Draw(xc + x, yc + y, brush);
            Draw(xc - x, yc + y, brush);
            Draw(xc + x, yc - y, brush);
            Draw(xc - x, yc - y, brush);
            ++x;
            error -= b2 * (x - 1);
            stopy += b2;
            if (error <= 0)
            {
                error += a2 * (y - 1);
                --y;
                stopx -= a2;
            }
        }
        error = b * b * a;
        x     = a;
        y     = 0;
        stopy = b2 * a;
        stopx = 0;
        while (stopy >= stopx)
        {
            Draw(xc + x, yc + y, brush);
            Draw(xc - x, yc + y, brush);
            Draw(xc + x, yc - y, brush);
            Draw(xc - x, yc - y, brush);
            ++y;
            error -= a2 * (y - 1);
            stopx += a2;
            if (error < 0)
            {
                error += b2 * (x - 1);
                --x;
                stopy -= b2;
            }
        }
    }