V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
nealot
V2EX  ›  程序员

如何使用 gnuplot 绘制一系列带 RGBA 填充的三角形

  •  
  •   nealot · 2020-07-27 16:42:53 +08:00 · 729 次点击
    这是一个创建于 1368 天前的主题,其中的信息可能已经有所发展或是发生改变。

    输入数据的格式大概是这样的 (可调整), 其中 rgba 是三角形的填充颜色

    x1 y1 x2 y2 x3 y3 rgba # 1st triangle
    x1 y1 x2 y2 x3 y3 rgba # 2nd triangle
    ...
    

    希望有一个现成的工具 (不限于 gnuplot) 能把这些三角形依次画出来,实现类似图层叠加的效果,输出到文件

    第 1 条附言  ·  2020-07-27 17:45:40 +08:00

    在等到答案前我已经用其它方法手动实现了,C# 写这种程序真顺手啊

    using System;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.IO;
    
    class Program
    {
        static void Main(string[] args)
        {
            // check argument
            if (args.Length != 1) {
                Console.WriteLine("Usage: ImagePainter {filename}");
                return;
            }
            string filename = args[0];
    
            // open data file
            StreamReader file = new StreamReader(filename);
    
            // init bitmap
            Bitmap bitmap = new Bitmap(800, 800);
            Graphics g = Graphics.FromImage(bitmap);
    
            // read file
            string line;
    
            // draw triangles
            while ((line = file.ReadLine()) != null) {
                string[] fields = line.Trim().Split('\t');
                double x1 = Convert.ToDouble(fields[0]);
                double y1 = Convert.ToDouble(fields[1]);
                double x2 = Convert.ToDouble(fields[2]);
                double y2 = Convert.ToDouble(fields[3]);
                double x3 = Convert.ToDouble(fields[4]);
                double y3 = Convert.ToDouble(fields[5]);
                double red = Convert.ToDouble(fields[6]);
                double green = Convert.ToDouble(fields[7]);
                double blue = Convert.ToDouble(fields[8]);
                double alpha = Convert.ToDouble(fields[9]);
    
                PointF[] points = {
                    new PointF(800 * (float)x1, 800 * (float)y1),
                    new PointF(800 * (float)x2, 800 * (float)y2),
                    new PointF(800 * (float)x3, 800 * (float)y3)
                };
                Color color = Color.FromArgb(
                    (int)(255 * alpha),
                    (int)(255 * red),
                    (int)(255 * green),
                    (int)(255 * blue);
                g.FillPolygon(new SolidBrush(color), points);
            }
    
            bitmap.Save(filename + ".bmp");
        }
    }
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5413 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 03:38 · PVG 11:38 · LAX 20:38 · JFK 23:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.