计算机图形学设计报告(黄轩)_第1页
计算机图形学设计报告(黄轩)_第2页
计算机图形学设计报告(黄轩)_第3页
计算机图形学设计报告(黄轩)_第4页
计算机图形学设计报告(黄轩)_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、计计算算机机图图形形学学 设设 计计 报报 告告 专业班级:专业班级: 软工软工.NET101.NET101 学学 号:号: 200907082116200907082116 姓姓 名:名: 黄轩黄轩 指导老师:指导老师: 杜俊俐杜俊俐 中原工学院软件学院中原工学院软件学院 20112011 年年 6 6 月月 2020 日日 目录 项目一:国旗的绘制.2 一、设计目的.2 二、设计内容.2 三、设计方案与实现.2 四、设计结果.4 五、设计总结.4 六、附录.5 项目二:交通灯的绘制.10 一、设计目的.10 二、设计内容.10 三、设计方案与实现.10 四、设计结果.12 五、设计总结.1

2、2 六、附录.12 项目三:自创图形的绘制.16 一、设计目的.16 二、设计内容.16 三、设计方案与实现.16 四、设计结果.17 五、设计总结.17 六、附录.17 项目四:画图工具的绘 制23 一、设计目的.23 二、设计内容.23 三、设计方案与实现.23 四、设计结果.24 五、设计总结.24 六、附录.24 项目一:国旗的绘制项目一:国旗的绘制 一、一、设计目的 1、 练习 2D 图形的绘制技术; 2、 练习 2D 图形的几何变换技术 3、 练习 2D 图形的填充技术 二、二、设计内容 编程使用 c#语言,实现五星红旗的绘制。 三、三、设计方案与实现 1、设计中的基本绘图功能及绘

3、图函数,设计的总体安排 基本绘图功能:实现五星红旗的绘制。 绘图函数: initialize()方法初始化了红旗,paint()方法实现了红旗的绘制。 设计的总体安排:在 pictureBox 确定大五角星的位置, ,并根据大五角星 的位置确定五个小五角星的位置,并画出图形。 2、图形数据及确定 五角星:五个五角星,位置由 initialize()方法中坐标来控制。 3、 设计流程 确定大五角星的位置以及大小 确定五小角星的位置以及大小 四、四、设计结果 五、设计总结 在红旗的绘制中,主要问题就是五个五角星的绘制,程序中采用坐标画直 线的方法画出五个五角星,程序使用 c#语言编程,利用编程语言

4、画图实现红旗 的绘制,以及对图形颜色的填充。 六、附录 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Drawing.Imaging; using System.Drawing.Drawing2D; namespace WindowsApplication1 public partial

5、class Form1 : Form public Form1() InitializeComponent(); private void pbxCanvas_Paint(object sender, PaintEventArgs e) INationFlag chinaFlag = new ChinaFlag(pbxCanvas.Width); e.Graphics.DrawImage(chinaFlag.GetFlagImage(), 0, 0); private void pbxCanvas_Resize(object sender, EventArgs e) pbxCanvas.Inv

6、alidate(); private void Form1_Load(object sender, EventArgs e) #region INationFlag public interface INationFlag float WidthProportion get; float HeightProportion get; SizeF Size get; set; void AdjustFlagSizeF(int width); Image GetFlagImage(); #endregion #region ChinaFlag class ChinaFlag : INationFla

7、g #region - INationFlag Members - public float WidthProportion get return 3F; public float HeightProportion get return 2F; SizeF size = SizeF.Empty; public SizeF Size get return size; set if (size != value) size = value; public void AdjustFlagSizeF(int w) int width = w + w % (int)WidthProportion; in

8、t height = (int)(HeightProportion * width / WidthProportion); Size = new SizeF(width, height); public Image GetFlagImage() Bitmap flag = new Bitmap(int)size.Width, (int)size.Height); float piece = size.Width / 30; int bigStarRadius = (int)(piece * 3); int smlStarRadius = (int)piece; using (Graphics

9、g = Graphics.FromImage(flag) g.SmoothingMode = SmoothingMode.AntiAlias; g.FillRectangle(Brushes.Red, 0, 0, size.Width, size.Height); g.DrawImage(GetStarImage(bigStarRadius), piece * 2, piece * 2); g.DrawImage(GetStarImage(smlStarRadius, -(int)(Math.Atan(3.0 / 5.0) * 180.0 / Math.PI) - 18), piece * 9

10、, piece); g.DrawImage(GetStarImage(smlStarRadius, -(int)(Math.Atan(1.0 / 7.0) * 180.0 / Math.PI) - 18), piece * 11, piece * 3); g.DrawImage(GetStarImage(smlStarRadius, 0), piece * 11, piece * 6); g.DrawImage(GetStarImage(smlStarRadius, (int)(Math.Atan(4.0 / 5.0) * 180.0 / Math.PI) - 18), piece * 9,

11、piece * 8); return flag; #endregion #region - Private Members - public Image GetStarImage(int radius) Bitmap bigStar = new Bitmap(radius * 2, radius * 2); using (Graphics g = Graphics.FromImage(bigStar) g.SmoothingMode = SmoothingMode.AntiAlias; Point pc = new Point(radius, radius); PointF p0 = new

12、PointF(pc.X, pc.Y - radius); PointF p1 = new PointF(float)(pc.X + radius * Math.Sin(72 * Math.PI / 180), (float)(pc.Y - radius * Math.Cos(72 * Math.PI / 180); PointF p2 = new PointF(float)(pc.X + radius * Math.Sin(36 * Math.PI / 180), (float)(pc.Y + radius * Math.Cos(36 * Math.PI / 180); PointF p3 =

13、 new PointF(float)(pc.X - radius * Math.Sin(36 * Math.PI / 180), (float)(pc.Y + radius * Math.Cos(36 * Math.PI / 180); PointF p4 = new PointF(float)(pc.X - radius * Math.Sin(72 * Math.PI / 180), (float)(pc.Y - radius * Math.Cos(72 * Math.PI / 180); using (GraphicsPath path = new GraphicsPath(FillMod

14、e.Winding) path.AddLine(p0, p2); path.AddLine(p2, p4); path.AddLine(p4, p1); path.AddLine(p1, p3); path.AddLine(p3, p0); path.CloseFigure(); g.FillPath(Brushes.Yellow, path); return bigStar; public Image GetStarImage(int radius, int angle) return RotateImage(GetStarImage(radius), angle); public Imag

15、e RotateImage(Image b, int angle) angle = angle % 360; / 弧度转换 double radian = angle * Math.PI / 180.0; double cos = Math.Cos(radian); double sin = Math.Sin(radian); / 原图的宽和高 int w = b.Width; int h = b.Height; int W = (int)(Math.Max(Math.Abs(w * cos - h * sin), Math.Abs(w * cos + h * sin); int H = (i

16、nt)(Math.Max(Math.Abs(w * sin - h * cos), Math.Abs(w * sin + h * cos); / 目标位图 Bitmap dsImage = new Bitmap(W, H); using (Graphics g = Graphics.FromImage(dsImage) g.InterpolationMode = InterpolationMode.Bilinear; g.SmoothingMode = SmoothingMode.AntiAlias; / 计算偏移量 Point Offset = new Point(W - w) / 2, (

17、H - h) / 2); / 构造图像显示区域:让图像的中心与窗口的中心点一致 Rectangle rect = new Rectangle(Offset.X, Offset.Y, w, h); Point center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2); g.TranslateTransform(center.X, center.Y); g.RotateTransform(angle - 360); / 恢复图像在水平和垂直方向的平移 g.TranslateTransform(-center.X, -

18、center.Y); g.DrawImage(b, rect); / 重至绘图的所有变换 g.ResetTransform(); g.Save(); return dsImage.Clone(new Rectangle(W - w) / 2, (H - h) / 2, w, h), PixelFormat.DontCare); #endregion #region - Constructor - public ChinaFlag(int w) AdjustFlagSizeF(w); #endregion #endregion private void button1_Click(object

19、sender, EventArgs e) private void button2_Click(object sender, EventArgs e) private void button1_Click_1(object sender, EventArgs e) timer1.Enabled = false; timer2.Enabled = false; pictureBox2.Visible = false; pbxCanvas.Visible = true; pictureBox1.Visible = true; bool lightgreen = true; private void

20、 light() Graphics g = pictureBox2.CreateGraphics(); g.SmoothingMode = SmoothingMode.AntiAlias; if (lightgreen) g.FillEllipse(new SolidBrush(Color.Green), 5, 5, 40, 40); g.FillEllipse(new SolidBrush(Color.White), 50, 5, 40, 40); else g.FillEllipse(new SolidBrush(Color.White), 5, 5, 40, 40); g.FillEll

21、ipse(new SolidBrush(Color.Red), 50, 5, 40, 40); private void pain() Graphics g = pictureBox2.CreateGraphics(); g.Clear(Color.White); g.SmoothingMode = SmoothingMode.AntiAlias; g.FillRectangle(new SolidBrush(Color.Blue), 0, 0, 100, 50); light(); g.FillEllipse(new SolidBrush(Color.Black), 136, 20, 70,

22、 70); g.FillRectangle(new SolidBrush(Color.Black), 166, 90, 10, 100); g.TranslateTransform(166, 100); g.RotateTransform(-10*i); g.FillRectangle(new SolidBrush(Color.Black), 0, 0, 7, 90); g.ResetTransform(); g.TranslateTransform(166, 100); g.RotateTransform(10*i); g.FillRectangle(new SolidBrush(Color

23、.Black), 0, 0, 7, 90); g.ResetTransform(); g.TranslateTransform(166, 190); g.RotateTransform(-10*i); g.FillRectangle(new SolidBrush(Color.Black), 0, 0, 9, 90); g.ResetTransform(); g.TranslateTransform(166, 190); g.RotateTransform(10*i); g.FillRectangle(new SolidBrush(Color.Black), 0, 0, 9, 90); g.Re

24、setTransform(); int i = 1; bool shunshizhen = true; private void button2_Click_1(object sender, EventArgs e) lightgreen = true; timer2.Enabled = true; timer1.Enabled = true; pbxCanvas.Visible = false; pictureBox1.Visible = false; pictureBox2.Visible = true; pain(); private void timer1_Tick(object se

25、nder, EventArgs e) if (i = 0 else if (i = 0 if (i = 4) shunshizhen = false; else if (i = -4) shunshizhen = true; if (shunshizhen) i+; else i-; pain(); private void timer2_Tick(object sender, EventArgs e) if (lightgreen = true) lightgreen = false; timer1.Enabled = false; else timer1.Enabled = true; l

26、ightgreen = true; light(); 项目二:交通灯的绘制项目二:交通灯的绘制 一、一、设计目的 1、 练习 2D 图形的绘制技术; 2、 练习 2D 图形的几何变换技术 3、 练习 2D 图形的填充技术 二、二、设计内容 编程使用 c#语言,实现交通灯的绘制,并根据时间的不同,闪现不同颜色 的灯。 三、三、设计方案与实现 1、设计中的基本绘图功能及绘图函数,设计的总体安排 基本绘图功能:实现红绿灯的绘制,根据时间的不同,显示不同颜色的灯。 绘图函数: pause(int time),start(),paintComponent(Graphics arg0),run(), ch

27、angeColor(int Ystop,int Bstop,int Rstop), 设计的总体安排:先确定红绿灯的大小,颜色以及位置,再使用多线程使 其互不干扰闪烁,最后完成绘制。 2、图形数据及确定 不同颜色的灯三个:paintComponent()确定了灯的大小,颜色和位置。 3、 设计流程 确定三个灯的大小,颜色,位置 确定三个灯的相对位置 不同时间显示不同颜色的灯 交通灯绘制结束 四、四、设计结果 五、设计总结 通过这次的红绿灯编写,我更加熟练使用多线程的知识。不过也还有很多 需要改进的地方,日后应该更加努力。 六、附录 namespace national_flag public p

28、artial class Form1 : Form public Form1() InitializeComponent(); public int intTime = 0;/声明一个公共变量,用于记录灯的显示时间 public int intFalg = 0;/控制灯的显示 /通过重写填充颜色的方法,实现灯循环显示 protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) getFillColor(); /自定义绘制红绿黄灯方法 public void getFillColor() Graphics g =

29、this.CreateGraphics();/实例一个 Graphics对像 switch (intFalg) case 0: g.FillEllipse(Brushes.DarkBlue, 20, 8, 60, 60); g.FillEllipse(Brushes.DarkBlue, 110, 8, 60, 60); g.FillEllipse(Brushes.DarkBlue, 200, 8, 60, 60); break; case 1:/ /红灯 g.FillEllipse(Brushes.Red, 20, 8, 60, 60); g.FillEllipse(Brushes.DarkB

30、lue, 110, 8, 60, 60); g.FillEllipse(Brushes.DarkBlue, 200, 8, 60, 60); break; case 2: /绿灯 g.FillEllipse(Brushes.DarkBlue, 20, 8, 60, 60); g.FillEllipse(Brushes.DarkBlue, 110, 8, 60, 60); g.FillEllipse(Brushes.Green, 200, 8, 60, 60); break;/ case 3: g.FillEllipse(Brushes.DarkBlue, 20, 8, 60, 60); g.F

31、illEllipse(Brushes.Yellow, 110, 8, 60, 60); g.FillEllipse(Brushes.DarkBlue, 200, 8, 60, 60); break;/黄灯 /end switch / private void Form1_Load(object sender, EventArgs e) intTime = 5; label1.Text = intTime.ToString(); label1.ForeColor = Color.Red; timer1.Enabled = true; / 红灯控制 private void timer1_Tick

32、_1(object sender, EventArgs e) Graphics g = this.CreateGraphics(); if (intTime != 0) if (intTime 10) /时间小于十秒时 label1.Text = 0 + intTime.ToString();/为了显示两位数字,所以在前面多 加一个0 label1.ForeColor = Color.Red; /字体颜色对应改变成红色 else label1.Text = intTime.ToString(); label1.ForeColor = Color.Red; intTime-; intFalg =

33、 1;/绘制红灯 getFillColor();/调用填冲函数 else label1.Text = 0 + intTime.ToString(); timer1.Enabled = false; intFalg = 0; intTime = 3;/时间计时数 timer1.Enabled = false; timer3.Enabled = true; /红灯过后,亮黄灯 /绿灯控制 private void timer2_Tick_1(object sender, EventArgs e) Graphics g = this.CreateGraphics(); if (intTime !=

34、0) if (intTime 10) label1.Text = 0 + intTime.ToString(); label1.ForeColor = Color.Green; else label1.Text = intTime.ToString(); label1.ForeColor = Color.Green; intFalg = 2;/绘制绿灯 getFillColor();/调用填冲函数 intTime-; else label1.Text = intTime.ToString(); timer1.Enabled = false; intFalg = 0; intTime = 5;

35、timer2.Enabled = false; timer1.Enabled = true; private void timer3_Tick_1(object sender, EventArgs e) Graphics g = this.CreateGraphics(); if (intTime != 0) if (intTime 0) picImage.Left = picImage.Left - 10; else picImage.Left =Width; 项目四:画图工具的绘制项目四:画图工具的绘制 一、一、设计目的 1、 练习 2D 图形的绘制技术; 2、 练习 2D 图形的几何变换

36、技术 3、 练习 2D 图形的填充技术 二、二、设计内容 编程使用 c#语言,实现画图工具的绘制,可以通过按钮的点击,在面板上 绘制多边形,椭圆形,弧形,饼形等图形。 三、三、设计方案与实现 1、设计中的基本绘图功能及绘图函数,设计的总体安排 基本绘图功能:实现画图工具的绘制,可以通过按钮的点击,在面板上绘 制出多边形,椭圆形,弧形,饼形等图形 。 绘图函数:actionPerformed(ActionEvent e),mousePressed(MouseEvent e), mouseReleased(MouseEvent e), itemStateChanged(ItemEvent e) 设

37、计的总体安排:先进行界面的编写,然后实现各个按钮的功能,实现各 个功能,进而完成整个画图工具。 2、图形数据及确定 该项目有七个按钮,在 paintboard()中确定,实现了画不同图形的功能, 。 3、 设计流程 对界面进行布局 对各个组件添加,实现各个功能 画图工具绘制结束 四、四、设计结果设计结果 五、设计总结 画图工具的绘制使用的是 c#编程语言,在实现了画图工具的绘制,让我感 觉到编程内容的广泛,我们应用的简单的软件都可以自己尝试着去实现,随着 日后学习的深入,和对知识的进一步掌握和理解,我们一定能做出更优秀的设 计,编程是一个艰苦,长期奋战的过程,只要在这个过程中能不骄不躁,那么

38、好的设计也就离我们不远了。 六、附录 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D; namespace class12_2_2 public partial class Form1 : Form public Form1() InitializeCom

39、ponent(); private void button1_Click(object sender, EventArgs e) Point p = new Point5; p0 = new Point(20, 20); p1 = new Point(20, 100); p2 = new Point(50, 120); p3 = new Point(70, 80); p4 = new Point(40, 30); Graphics g = panel1.CreateGraphics(); g.DrawPolygon(new Pen(Color.Red), p); private void button2_Click(object sender, Ev

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论