Basic Graphics Drawing Shapes 1.

Slides:



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

Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
Introduction to Programming
PHY-102 SAPIntroductory GraphicsSlide 1 Introductory Graphics In this section we will learn how about how to draw graphics on the screen in Java:  Drawing.
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
© red ©
Copyright 2008 by Pearson Education Building Java Programs Graphics Reading: Supplement 3G.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
2D Graphics in Java COMP53 Nov 14, Applets and Applications Java applications are stand-alone programs – start execution with main() – runs in JVM.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
A Simple Applet. Applets and applications An applet is a Java program that runs on a web page –Applets can be run from: Internet Explorer Netscape Navigator.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
A Simple Applet.
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.
2D Graphics: Rendering Details
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
Copyright 2010 by Pearson Education Building Java Programs Graphics reading: Supplement 3G.
Image Representation. Objectives  Bitmaps: resolution, colour depth and simple bitmap file calculations.  Vector graphics: drawing list – objects and.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
Graphics & Java 2D Drawing Two Dimensional Shapes Controlling Fonts Controlling Colors.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
Loops & Graphics IP 10 Mr. Mellesmoen Recall Earlier we wrote a program listing numbers from 1 – 24 i=1 start: TextWindow.WriteLine(i) i=i+1 If.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
1 A Simple Applet. 2 Applets and applications An applet is a Java program that runs on a web page Applets can be run within any modern browser To run.
CS305j Introduction to Computing Simple Graphics 1 Topic 11 Simple Graphics "What makes the situation worse is that the highest level CS course I've ever.
Introduction to Graphics. Graphical objects To draw pictures, we will use three classes of objects: –DrawingPanel : A window on the screen. –Graphics.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
CS 112 Introduction to Programming Java Graphics Yang (Richard) Yang Computer Science Department Yale University 208A Watson, Phone:
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Basic Graphics Drawing Shapes 2.
Chapter 8 Graphics.
Graphical Output Basic Images.
Pixels, Colors and Shapes
Adapted from slides by Marty Stepp and Stuart Reges
Building Java Programs
Graphical Output Graphical Text.
Building Java Programs
Building Java Programs
Building Java Programs
A note on Programming Assignment
Example: Card Game Create a class called “Card”
Week 8 - Monday CS 121.
Building Java Programs
Lesson One: The Beginning Chapter 1: Pixels Learning Processing Daniel Shiffman Presentation by Donald W. Smith Graphics from
Images Presentation Name Course Name Unit # – Lesson #.# – Lesson Name
Chapter 10 Graphics.
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
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
CSc 110, Spring 2018 Lecture 9: Parameters, Graphics and Random
Building Java Programs
SSEA Computer Science: Track A
CSE 142 Lecture Notes Graphics with DrawingPanel Chapter 3
Images Presentation Name Course Name Unit # – Lesson #.# – Lesson Name
Building Java Programs
Chapter 8 Graphics.
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Graphics Reading: Supplement 3G
Building Java Programs
Presentation transcript:

Basic Graphics Drawing Shapes 1

Learning Goals By the end of the lesson you should know: Using the Helper Library to: Use predefined colours Create custom colours Where to write our graphics code The screen resolution How to draw a line How to draw a rectangle How to draw a filled rectangle

The Helper Library The Helper library built into the Java Game Engine allows you to do a number of things: Generate random values within a given range Take advantage of a number of predefined colours Use custom colours Using the Helper Library Like other libraries such as Math, we simply need to use the library’s name followed by the desired value or command E.g. Helper.BLACK

Predefined Colours There are 13 predefined colours you can take advantage of: WHITE RED GREEN BLUE ORANGE YELLOW GRAY BLACK PINK CYAN DARK_GRAY LIGHT_GRAY MAGENTA To use these colours you need to follow the Helper. prefix with the colour you need: Helper.WHITE or Helper.BLACK

Custom Colours In order to create custom colours it is best practice to create a variable to store that new colour. The data type for your variable will be Color From here we will take advantage of one of two Helper commands: Helper.GetColor(int red, int green, int blue) Helper.GetColor(int red, int green, int blue, int transparency) The red, green and blue values are numbers between 0 to 255. Think of it like mixing paint, these three colours can produce any colour you want. HINT: Go to colorpicker.com to get exact values for any colour you want Transparency is also a value from 0 to 255, in this case however the number represents how transparent (see-through) the colour is. 255 is completely opaque and 0 and invisible. When creating your colours, it is best to make these variables global, but they do NOT need to be static. E,g. Color skyColor = Helper.GetColor(0,0,200);

Where to Draw? public void Draw(GameContainer gc, Graphics2D gfx) { For our purposes we will be using the Game project on the Moodle which has the Java Game Engine built in and ready to go. Recall that all of our drawing commands will go in the Draw command of our Game Loop. public void Draw(GameContainer gc, Graphics2D gfx) { //Add your draw code here }

The screen X (0,0) You will be drawing to the game window which you specify as a certain size in the Main code of the Game Project Assume you use the default values of 800 pixels wide by 600 pixels high Also note that the (0,0) origin is NOT in the bottom left of the screen, it is at the top left of the screen. This implies coordinate (800,600) is located at the bottom right of the screen. This means that x in creases as you move right and y increases as your move DOWN Y (800,600)

Draw a Line Draw.Line(gfx,50,125,300,200,3,Helper.RED,0.5f) Draw.Line(gfx, x1, y1, x2, y2, lineWidth, Color, transparency) gfx represents your game window, leave this alone x1, y1 is the coordinate of the first end point of the line x2, y2 is the coordinate of the second end point of the line lineWidth is the number of pixels wide the line is Color is the colour of the line, e.g. Helper.RED transparency is how see-through the line is, a float number from 0 to 1 where 0 is invisible Example: Draw a red line from (50,125) to (300,200) that is half transparent and 3 pixels wide Draw.Line(gfx,50,125,300,200,3,Helper.RED,0.5f)

Draw a Rectangle Draw.Rect(gfx, x, y, width, height, lineWidth, color, transparency) gfx represents your game window, leave this alone x,y is the coordinate for the rectangle’s top left corner width, height are the dimensions of the rectangle color is the border’s colour transparency is how see-through the line is, a float number from 0 to 1 where 0 is invisible Example: Draw a 200x400 White opaque rectangle at (25,100) Draw.Rect(gfx,25,100,200,400,5,Helper.WHITE, 1f);

Draw a Filled Rectangle Draw.FillRect(gfx, x, y, width, height, color, transparency) gfx represents your game window, leave this alone x,y is the coordinate for the rectangle’s top left corner width, height are the dimensions of the rectangle color is colour the rectangle is filled in with transparency is how see-through the line is, a float number from 0 to 1 where 0 is invisible Example: Draw a 300x100 ¾ opaque yellow filled rectangle at (40,150) Draw.FillRect(gfx,40,150,300,100,Helper.YELLOW,0.75f);