1 / 17

Computer Graphics and Animation Sabin Tabirca

Computer Graphics and Animation Sabin Tabirca Email: s.tabirca@cs.ucc.ie Phone: (490) 3662 Office: Brighton Villas, Multimedia Building, Second Floor Contact Hours: Monday 11-13. Aim of the Course: To introduce some Computer Graphics concepts using Java. Objectives of the Course:

emily
Download Presentation

Computer Graphics and Animation Sabin Tabirca

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Graphics and AnimationSabin Tabirca Email: s.tabirca@cs.ucc.ie Phone: (490) 3662 Office: Brighton Villas, Multimedia Building, Second Floor Contact Hours: Monday 11-13. Aim of the Course: To introduce someComputer Graphicsconcepts using Java. Objectives of the Course: - To give some minimal Java skills for Multimedia Programming. - To introduce some Computer Graphics elements. Computer Graphics - Course 1.

  2. Structure of the Course Introduction to Java Programming - Java basics: data types, statements, methods, classes, … - The Java classes for Graphics: Graphics, Graphics2D, … - Elements of GUI design: awt / swing … Computer Graphics - Turtle Graphics and fractals - 2D Graphics: Transformations, 2D curves, … Animation and Games in Java Multimedia for Mobile devices Computer Graphics - Course 1.

  3. References Java: Dietel & Dietel, Advanced / Java: How to Program, Prentince Hall, 2001. Steve Holzner, The Java Black Book, Coriolis Press, 2000. Chuck Cavaness et. al, Using Java 2 Standard Edition,QUE Press, 2001 Graphics: V.D. Foley, Introduction to Computer Graphics, Addison-Wesley Publ. Peter Cooley, The essence of Computer Graphics, Prentice Hall Java + Graphics: J. Knudsen, Java 2D Graphics, O’Reilly Publ, 2000. Computer Graphics - Course 1.

  4. Introduction to Java What is Java? It is more than a programming language. History: James Gosling 1990 - Green Project, Oak language 1993 - HotJava browser Sun Microsystems: 1995 - Java 1.0, 1997 - Java 1.1, 1998 – Java 1.2, 2002? Advantages [according to Sun Microsystems]: simple, object-oriented, WEB oriented, compiled, architecture neutral, multi-threaded, garbage collected, robust, secure, and extensible. Computer Graphics - Course 1.

  5. JDK – Java Developers Kit JDK is a collection of libraries and tools. The Main Libraries: java.awt – graphic interfaces [java.awt.Graphics; java.awt.image, …] java.applet – applet java.io – input/output java.math – mathematics java.net – network java.sql – databases … Rule: Import the packages you need. import java.awt.*; import java.applet.Applet; The main tools: javac – compiler java – interpreter jre – runtime interpreter jdb – debuggerjavadoc – help generating appletviewer – execute an applet Computer Graphics - Course 1.

  6. The First Java Application Steps: Editing >> Compiling >> (Correcting Errors) >> Executing Step 1. Edit the java program FirstApplication (Notepad, Wordpad, Simple Text, …) Step 2. Compile the file FirstApplication.java (javac FirstApplication.java) Step 3. Execute the program (java FirstApplication.java) public class L1App1{ public static void main( String args[] ){ System.out.println(“This is our first Java Application”) } } Rule: The file name (L1App1.java) and the class name (L1App1) must be identical. Computer Graphics - Course 1.

  7. Computer Graphics - Course 1.

  8. The First Java Applet Steps: Editing >> Compiling >> (Correcting Errors) Editing the html file >> Executing the applet via a browser(Internet Explorer …) Step 1. Edit the java applet FirstApplet.java (Notepad, Wordpad, Simple Text, …) Step 2. Compile the file FirstApplet.java (javac FirstApplet.java) Step 3. Edit the HTML file FirstApplet.html Step 4. Run the applet either via a browser of appletviewer Important: The Java file name (L1Appl1.java) and the class name (L1Appl1) must be identical. Golden Rule: Keep the same name for the HTML file. Computer Graphics - Course 1.

  9. Computer Graphics - Course 1.

  10. The file L1Appl1.java import java.applet.Applet; import java.awt.Graphics; public class L1Appl1 extends Applet{ public void paint( Graphics g){ g.drawString(“This is our first Java applet”, 30, 30); } } The file L1Appl1.html <HTLM> <BODY> <APPLET CODE=L1Appl1.class, WIDTH=200, HEIGHT=200> </APPLET> </BODY> </HTLM> Computer Graphics - Course 1.

  11. The Structure of a Java Applet 1. Import declaration; import java.package.*;  import all the classes of package import java.package.Class;  import only the class Class of package Golden Rule: Import all the packages that the applet needs. 2. Construct the body of MyApplet public classMyApplet extends Applet{ public void paint( Graphics g){ … the body of method paint } } Golden Rule of Names: classes  the first digit of words is cap (e.g. MyApplet, Graphics, Applet, ..) variables, methods  the first digit of words is cap excepting the first word (e.g. paint, myOwnVariable, myOwnMethod,…) Computer Graphics - Course 1.

  12. Applet 1. Draw a line Draw a line between (xInitial, yInitial) and (xFinal, yFinal). import java.applet.Applet; import java.awt.Graphics; public class L1Appl2 extends Applet { public void paint(Graphics g) { // declare and initialise the variables int xInitial,yInitial,xFinal,yFinal; xInitial=100;yInitial=100;xFinal=200;yFinal=200; g.drawString(“This is a line: “, 50, 50); // draw the line g.drawLine(xInitial,yInitial,xFinal,yFinal); // draw the line } }  Remarks: drawString, drawLine are methods of class Graphics. Computer Graphics - Course 1.

  13. Program 1. Sum of 2 numbers. Find the sum of two integer numbers firstNr, secondNr. class SumTwoNum{ public static void main( String args[] ){ int firstNr, secondNr, sumNrs; // declare the numbers and sum firstNr=1; secondNr=2; // initialization of the numbers sumNrs=firstNr+secondNr; // find the sum System.out.println(“ sum = “ + sum); } } Remarks: String everything in “ ” is a string. String + Number = String System.out.println(str ) write the string str and jump a new line. System.out.print(str ) write the string str. Rule: Declare and Initialise each variable of the applet. Computer Graphics - Course 1.

  14. Class Graphics is part of the package awt (abstract window toolkit). Graphics contains methods: - to draw objects: drawString, drawRect, drawLine, drawOval, drawImage, … - to fill objects: fillRect, fillOval, fillPolygon. - get/set element of current Graphics: color, font, … Find more information at http://java.sun.com/j2se/1.3/docs/api/index.html. Go to awt + Graphics. In method paint: - Declare the variables of the applet. - Compute the elements of the applet. - Draw the objects of your applet. Class Graphics Computer Graphics - Course 1.

  15. Applet 2. Draw a rectangle from (xInitial, yInitial) with (widthRect, heightRect) and find information about its square and perimeter. import java.applet.Applet; import java.awt.Graphics; public class L1Appl3 extends Applet { public void paint(Graphics g) { int xInitial,yInitial,widthRect,heightRect; // declare and initialize the variables xInitial=100;yInitial=100;widthRect=200;heightRect=100; int perRect=2*widthRect+2*heightRect; // calculate the perimeter and square int squareRect=widthRect*heightRect; g.drawString("The perimeter is: "+perRect, 50, 50); g.drawString("The square is: "+squareRect, 50, 70); g.drawRect(xInitial,yInitial,widthRect,heightRect); // draw the rectangle } } Draw a Rectangle Computer Graphics - Course 1.

  16. Computer Graphics - Course 1.

  17. Problems to Read: 1. Java Tutorial: The first coupe of Java. 2. Java by Example: Java Overview • Applets to Write: Applet 1. Write an applet to draw a String three times at (50,50), (50,100), (50, 150). Applet 2. Write an applet to draw a triangle ABC with A(xA,yA), B(xB,yB) and C(xC, yC). Computer Graphics - Course 1.

More Related