Example: Card Game Create a class called “Card”

Slides:



Advertisements
Similar presentations
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Advertisements

Code Elements and Processing Coordinate System. Code elements: pages Comments: are documentation notes that are ignored by the computer but are.
Processing Lecture. 1 What is processing?
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
Copyright 2008 by Pearson Education Building Java Programs Graphics Reading: Supplement 3G.
©2004 Brooks/Cole Applets Graphics & GUIs. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Graphical Programs Most applications these days are.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
DrawingPaint What is DrawingPaint ? DrawingPaint operations. What are benefits of DrawingPaint ? Jason Hoang June 2, 2005.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
1 Graphical objects We will draw graphics in Java using 3 kinds of objects: DrawingPanel : A window on the screen. Not part of Java; provided by the authors.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Copyright 2010 by Pearson Education Building Java Programs Graphics reading: Supplement 3G.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
CPS Today’s topics Java Applications Graphics Upcoming Review for Midterm Exam Reading Great Ideas, Chapters 5.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
Classes Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Classes. Preparation Scene so far has been background material and experience –Computing systems and problem solving –Variables –Types –Input and output.
1 Introduction to Graphics b The last one or two sections of each chapter of the textbook focus on graphical issues b Most computer programs have graphical.
Introduction to Graphics. Graphical objects To draw pictures, we will use three classes of objects: –DrawingPanel : A window on the screen. –Graphics.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Object Oriented Programming Lecture 3: Things OO.
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
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.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
Chapter 7 Introduction to High-Level Language Programming.
Graphics JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin, and Skylight.
Monday 26th May Java Lecture 10 Overview
Contacts: Intro to game programming in Java (with almost-drawingpanel)
MOM! Phineas and Ferb are … Aims:
Pixels, Colors and Shapes
WITH PYGAME ON THE RASPBERRY PI
Object Oriented Programming
2D Graphics: Part 2.
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Python: Simple Graphics and Event-driven Programming
Building Java Programs
Java Programming: Guided Learning with Early Objects
Today’s topics Java Applications Upcoming Reading Graphics
Microprocessor and Assembly Language
Basic Graphics Drawing Shapes 1.
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Computer Graphics.
Code Elements and Processing Coordinate System
Topic 8 graphics "What makes the situation worse is that the highest level CS course I've ever taken is cs4, and quotes from the graphics group startup.
Building Java Programs
Chapter 2 Graphics Programming with C++ and the Dark GDK Library
Code Elements and Processing Coordinate System
Lecture 7: Introduction to Processing
Desktop Publishing Features
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Making a Smile Face Pepper.
Graphics Reading: Supplement 3G
Chapter 7 The Game Loop and Animation
Presentation transcript:

Example: Card Game Create a class called “Card” Has thirteen static variables for the possible values of a playing card Has four static variables, one for each suit Has two instance attributes: value and suit Create a class called “Deck” Has an array of 52 cards Initialize the deck to one card of each value and of each suit Write a main function that plays “war”: Draw two cards from a deck and compare their value to see which one wins

Re-using Code Recall the purpose of classes and objects Model the real-world Encapsulate the attributes and behaviors of concepts Writing classes in a “black-box” fashion allows programmers to share and re- use code for many purposes! Now that we have Card and Deck, we can use them for basically any card game that uses a standard deck of cards The game logic will be different, but in some driver class! This (huge) benefit of object-oriented programming is what motivates the maintenance of the open source software libraries

Graphical Programming (Obviously) hugely important development in history of computers Allow much more logical and accessible presentation and manipulation of data Requires much different programming and problem-solving techniques Program efficiency becomes much more important Many more approaches to similar problems Much more hardware dependent

Graphics Basics A screen is broken down into small light-emitting diodes, forming “pixels” To display an image or text, the right ones need to be lit up or turned off For colors, there are three different hues of pixels that are adjusted to different intensities

Screen layout Screens are rendered using an x-y axis, where the origin is in the top- left Similar to how text-only terminals operated (see the terminal in Eclipse) Java will abstract away many of the finer details, giving more logical access to the viewport of your program The OS will also take care of placement, dragging, etc. of your graphics window

Getting starting with Graphics No user-interaction (buttons, text input, etc.) yet Only “output” graphics: shapes and text Requires some initial setup to prepare the graphics and window Starter file with comments: http://faculty.salisbury.edu/~jtanderson/teaching/cosc117/files/SimpleAnimationStarter.j ava Download and change the three occurrences of “SimpleAnimationStarter” to whatever class name you need

Creating a graphic Similar to the Scanner, we will get an graphics context from Java: Graphics g; The Graphics class has many methods that let us choose to display primitive graphical elements: Text rendering Rectangles Circles Full list: https://docs.oracle.com/javase/8/docs/api/java/awt/Graphics.html

Drawing Lines If we want to draw a line, we need to specify its end points Two points in 2d – four coodinates E.g. g.drawLine(xOne, yOne, xTwo, yTwo); We can loop it, and orient the lines any way we want!

Drawing rectangles g.drawRect(int x, int y, int width, int height) Draws the outline of a rectangle with top-left at (x,y) and width x height dimensions g.fillRect(…) Fills the rectangle with the current color We can change color with g.setColor(Color c) We can access different color constants like Color.BLUE, Color.GREEN, Color.RED, etc.

Drawing circles and ovals g.fillOval(int x, int y, int height, int width) Same idea as rectangle, but coodinates are the corner of the bounding rectangle Can also use g.drawOval(…)

Examples: Draw a set of lines on the screen Draw a set of nested rectangles Make the nested rectangles animated to move “inward” Draw random circles Draw a moving circle

Animate Objects Create a class called “Circle” centerX and centerY coordinates Radius size velocityX and velocityY Make one circle starting somewhere random, and update its position every frame, based on the velocity