VG101 RECITATION 5 By TAs. CONTENTS How to read Vg101Class.h Samples about graphics About assignment 5 Array.

Slides:



Advertisements
Similar presentations
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Advertisements

BGI graphics library And Visual Studio.
Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Constructor and New Fields // Don't synch draw() with vertical retrace of monitor graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = true;
Inheritance // A simple class hierarchy. // A class for two-dimensional objects. class TwoDShape { double width; double height; void showDim() { System.out.println("Width.
Revision.
Applets Graphical Java programs Run inside web browser Platform-neutral Easy deployment--loads when needed Secure.
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-2: Arrays as Parameters reading: , 3.3 self-checks: Ch. 7 #5, 8,
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Java Graphics Section 1 - Multi-File Graphics Programs Section 2 - The Coordinate System and Graphics Context g Section 3 - The Java Drawing and Painting.
This Time Pointers (declaration and operations) Passing Pointers to Functions Const Pointers Bubble Sort Using Pass-by-Reference Pointer Arithmetic Arrays.
Week 11 - Friday.  What did we talk about last time?  Object methods  Accessors  Mutators  Constructors  Defining classes.
Const Parameters & In Line Functions 04/15/11. Next Time  Quiz, Monday, 04/18/11  Over 5.2 and 5.3 void functions pass-by-reference  Read 7.1 about.
Engineering Problem Solving With C++ An Object Based Approach Chapter 6 One-Dimensional Arrays.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Topics  Applets  Classes used for graphics Graphics Point Dimension.
1 6/20/2015CS150 Introduction to Computer Science 1 Functions Chapter 6, 8.
COMP 110 Introduction to Programming Mr. Joshua Stough October 8, 2007.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Java Graphics Applets.
C++ Classes in Depth. Topics Designing Your Own Classes Attributes and Behaviors Writing Classes in C++ Creating and Using Objects.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
CS 117 Spring 2002 Review for Exam 3 arrays strings files classes.
CS 106 Introduction to Computer Science I 03 / 17 / 2008 Instructor: Michael Eckmann.
New Data Types in C++ Programs We can specify and implement new data types in C++ using classes  need specification as to how represent data objects of.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
UML Basics & Access Modifier
CS352-Week 2. Topics Heap allocation References Pointers.
Introduction to Computation and Problem Solving Class 9: Static Methods and Data Members Prof. Steven R. Lerman and Dr. V. Judson Harward.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 5 An Array Class Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
CSCI-383 Object-Oriented Programming & Design Lecture 5.
Week 14 - Monday.  What did we talk about last time?  Introduction to C++  Input and output  Functions  Overloadable  Default parameters  Pass.
Chapter 4: Subprograms Functions for Problem Solving Mr. Dave Clausen La Cañada High School.
VG101 RECITATION 1 By TAs. CONTENTS Intro to SAKAI Intro to APG Intro to Online Quiz System Installation of VS2005 and possible resources Some common.
10-Nov-15 Java Object Oriented Programming What is it?
Organizing Heterogeneous Data Arrays allow a programmer to organize lists of values that are all of the same type (homogeneous). But we are often faced.
11 Introduction to Object Oriented Programming (Continued) Cats.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
1 Original Source : and Problem and Problem Solving.ppt.
C++ Classes and Data Structures Jeffrey S. Childs
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
CS 106 Introduction to Computer Science I 10 / 29 / 2007 Instructor: Michael Eckmann.
Week 11 - Friday.  What did we talk about last time?  Object methods  Accessors  Mutators  Constructors  Defining classes.
Function 2. User-Defined Functions C++ programs usually have the following form: // include statements // function prototypes // main() function // function.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
Separating Class Specification tMyn1 Separating Class Specification from Implementation Usually class declarations are stored in their own header files.
CS 5JA Introduction to Java Graphics One of the powerful things about Java is that there is.
11 Introduction to Object Oriented Programming (Continued) Cats.
1 Reference Variables Chapter 8 Page Reference Variables Safer version of C/C++ pointer. "Refers to" a variable. Like a pointer. Effectively.
CS 106 Introduction to Computer Science I 03 / 22 / 2010 Instructor: Michael Eckmann.
Midterm: Question 1 (35%) (30 minutes) Write an assembly program to draw a rectangle. – (5%) Show a message to ask for information of the rectangle – (5%)
Constructors, Copy Constructors, constructor overloading, function overloading Lecture 04.
1 Introduction to Object Oriented Programming Chapter 10.
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Processing  Install Processing  Learn how to edit, run, save, export,
VG101 RECITATION 8 By TAs. CONTENTS Brief review of class Strategy for assignment 9 Questions about assignment 7, 8.
CS 115 Lecture 7 Graphics – coordinate systems, Text, Entry, aliases Taken from notes by Dr. Neil Moore.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Basic Elements of C++.
group work #hifiTeam
Basic Elements of C++ Chapter 2.
CS 115 Lecture Graphics II – coordinate systems, Text, Entry, aliases
Java Programming with BlueJ
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
PC02 Term 2 Test Recursion and Sorting. PC02 Term 2 Test Recursion and Sorting.
CS 115 Lecture Graphics II – coordinate systems, Text, Entry, aliases
SSEA Computer Science: Track A
Lab 1 Introduction to C++.
References, const and classes
Let’s Learn the Basic Colors
Presentation transcript:

VG101 RECITATION 5 By TAs

CONTENTS How to read Vg101Class.h Samples about graphics About assignment 5 Array

HOW TO READ VG101CLASS.H This file defines the following classes: ConsoleT GwindowsT: represent the graphics window GObjectT: base class for all geometric classes LineT TriangleT RectangleT ArcT: a circle is an arc with an angle of 360 degrees

HOW TO READ VG101CLASS.H RandomT: random numbers and colors PointT: represent a point using (x, y) PenT: record the current location and color of the pen MouseT: detect the click event of the mouse, get mouse current location TextT: set text color, style, font… when printing a message to the graphics window (not console window)

HOW TO READ VG101CLASS.H Let’s see what’s the general structure of a class definition

class RectangleT : public GObjectT { PointT llp, urp; void drawRect (); public: RectangleT (const double x0 = 0, const double y0 = 0, const double x1 = 0, const double y1 = 0, const string clr = "Blue", const double fill = 0); RectangleT (const PointT &p0, const PointT &p1, const string clr = "Blue", const double fill = 0); const PointT &getLocation () {return llp;} double getWidth () const; double getHeight () const; double getArea () const; void setLocation (const double x, const double y); void setLocation (const PointT p); void setWidth (const double w); void setHeight (const double h); void draw (); void draw (const string clr, const double density = 0); }; Base class Private member Public member constructor Get & Set Data members Function members

HOW TO READ VG101CLASS.H About constructors RectangleT (const double x0 = 0, const double y0 = 0, const double x1 = 0, const double y1 = 0, const string clr = "Blue", const double fill = 0); RectangleT (const PointT &p0, const PointT &p1, const string clr = "Blue", const double fill = 0); Note: 1. No return type, function name is just its class name. 2. You should declare an object using one of its constructors:

HOW TO READ VG101CLASS.H If the constructor gives the default value of a parameter, then you don’t need to give that parameter. useRectangleT myRec(); // default position, color, fill orRectangleT myRec(1, 1, 2, 3); // default color, fill or RectangleT myRec(1, 1, 2, 3, “red”, 0.5); // p1, p2 are two known PointT object orRectangleT myRec(p1, p2); // default color, fill orRectangleT myRec(p1, p2, “green”, 0.8);

HOW TO READ VG101CLASS.H What are useful to us Get and Set functions double getWidth () const; void setWidth (const double w); Other public functions void draw (); void draw (const string clr, const double density = 0); // overloaded function Note: 1. You can’t access private/protected data or use private/protected functions directly. 2. The get & set functions offer you access to some private data. 3. Read function comment carefully.

S AMPLES ABOUT GRAPHICS Draw a line from (2,1) to (5,3) in red

SAMPLES ABOUT GRAPHICS Draw an empty triangle specified by three points (1,1), (3, 1), (2.3, 3) in green

SAMPLES ABOUT GRAPHICS Draw a filled triangle specified by three points (1,1), (3, 1), (2.3, 3) in green with density of 0.4

SAMPLES ABOUT GRAPHICS Draw an empty rectangle whose lower left point is (0.5, 0.5) and upper right point is (1.5, 1.2) in yellow

SAMPLES ABOUT GRAPHICS Draw a filled rectangle whose lower left point is (0.5, 0.5) and upper right point is (1.5, 1.2) in yellow with density of 0.8

SAMPLES ABOUT GRAPHICS Draw an arc start from 0 degree and sweep 270 degree with radius 0.6 in purple, centered at (0.6, 0.6)

SAMPLES ABOUT GRAPHICS Draw an empty circle with radius 0.6 in purple, centered at (0.6, 0.6)

SAMPLES ABOUT GRAPHICS Draw a filled circle with radius 0.6 in purple, centered at (0.6, 0.6) with density of 0.9

ABOUT ASSIGNMENT 5 Where’s Tom Understand the pseudo code for function takeTomHome () Every step is a line with constant length (step size) in a random direction Check before taking the step if Tom is going out of the universe (the do-while loop in pseudo code) Check after taking the step if Tom is already at home

ABOUT ASSIGNMENT 5 Bouncing ball Check before taking the step if the ball is going to hit the wall When hitting the wall, adjust the location of the ball so that it just touch the wall (on the line of its original direction) Change color when change direction Don’t use magic numbers Give a good name for your variables

A RRAY An array is an ordered collection of data values of the same type Passing an array into a function void initArray(int array[], int n); void printArray(int array[], int n); Usually, n is the array length

ARRAY A sample on passing an array into a function #include using namespace std; void initArray ( int intArray[], int n); void printArray ( int intArray[], int n); void main() { int intArray[4]; initArray ( intArray, 4); printArray ( intArray, 4); }

ARRAY A sample on passing an array into a function void initArray(int intArray[], int n) { ConsoleT c; for ( int i = 0 ; i < n ; i++) { c.printLine ( "Enter a integer value for the ", i+1, " th element: "); intArray[i] = c.readInt ("");; } c.printLine ( endl ); }

ARRAY A sample on passing an array into a function void printArray(int intArray[], int n) { ConsoleT c; for ( int i = 0 ; i < n ; i++) { c.printLine ( "The ", i+1, " th element is ", intArray[i], endl ); }

ARRAY Here is the program’s output