Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPT 450 Computer Graphics 3rd Lecture.

Similar presentations


Presentation on theme: "CPT 450 Computer Graphics 3rd Lecture."— Presentation transcript:

1 CPT 450 Computer Graphics 3rd Lecture

2 GDI+ Vector Graphics Require
Drawing Surface Represented as a Graphics Object Form, Control (Picture Box), Printer, Bitmap) Pen or Brush Process Drawing (or Filling) method

3 Creating a Graphics Object
Dim g as Graphics = new Graphics ‘ won’t work! In the Paint Event of a form Form1_paint(sender as object, e as PaintEventArgs) Dim g as Graphics = e.Graphics Elsewhere Dim g as Graphics = me.createGraphics

4 Project 1 – Drawing Program
This project requires you to keep track of the mouse clicks and the state of the program. Drawing different types of shapes required different numbers of mouse clicks. 1 click - Points and text 2 clicks - Line segments, ellipses and rectangles 3 clicks – Arcs 4 clicks – Beziers N>=4 clicks - Curves

5 Mouse Events Use these events to know where the user has clicked the mouse button. Note: The form and a control on the form such as a picture box each have their own separate events, depending on if the user clicks on the control or the background of the form. Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown ‘ Your code here End Sub Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

6 Mouse Events Use the returned value e (of type MouseEventArgs) to determine the position and type of the mouse event. e.x e.y e.button

7 Finite State Machines Computer programs can be thought of as machines that have finite states (or modes) Our project 1 will have different states depending on the clickNumber. FSA can be modeled as computer graphs, with states represented as vertices and transitions represented as edges of the graph. State1 transition State2

8 ATAN versus ATAN2 Located in Math namespace ATAN ATAN2
Input: y/x Output: angle (in radians) [-pi/2, pi/2] ATAN2 Inputs: y, x Output: angle (in radians) [-pi, pi] Angle (in Deg) = Angle (in Radian)*180/PI Error handling: division by zero, when x = 0

9 Pens Solid Pens Color property Width property DashStyle property
Constructor sets color and line width Dim myPen As New Pen(Color.Black, 1) Color property Controls pen color Width property Controls the pen’s line width DashStyle property Controls the line style (solid, dashed, dotted, etc.)

10 Brushes Programmer can only instantiate descendants of brush class. No constructor for a brush – it is called an abstract base class. solidBrush Constructor sets color Dim myBrush As Brush = New SolidBrush(Color.Black) HatchBrush Constructor sets color and HatchStyle And many other types of brushes

11 Fonts Contructor initializes the font family and size
Dim myFont As New Font("Times New Roman", 10) Bold, Italics, size properties


Download ppt "CPT 450 Computer Graphics 3rd Lecture."

Similar presentations


Ads by Google