Some Graphics CS303E: Elements of Computers and Programming.

Slides:



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

Lesson One: The Beginning
Graphics Shapes. Setup for using graphics You have to import the graphics library You can use either “import graphics” or “from graphics import *” or.
Introduction to Programming
Python Programming, 2/e1 CS177: Programming in Multimedia Objects Recitation Topic: Graphics Library.
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
CSC 160 Computer Programming for Non-Majors Lecture #3c: Working with Pictures (continued) Prof. Adam M. Wittenstein
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 Python Programming: An Introduction to Computer Science Chapter 3 Objects and 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.
Chapter 4 Objects and Graphics
Python: Graphics
Checkerboard Examples Top Down Design. The Problem On a checkerboard where locations are numbered similar to java coordinates, draw a rectangle using.
Animation CSC 161: The Art of Programming Prof. Henry Kautz 10/14/2009.
CSC 110 Objects and Graphics [Reading: chapter 4] CSC 110 E 1.
Chapter 5 Graphics.  We’ve been doing command line programming, but now it’s time to try GUI programming—programming in a graphical user interface, using.
PowerPoint: Working with Slides Lecture 7-2 CMPSC 100 Spring 2004 Penn State University Doug Hogan.
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.
Introduction to Java Simple Graphics. Objects and Methods Recall that a method is an action which can be performed by an object. –The action takes place.
Tkinter Canvas.
1 A first OpenGL program Brian Farrimond Robina Hetherington.
Introducing Templates and Graphics. 2 Creating Workbooks from Templates Choose a blank workbook or an existing workbook Search for templates at Office.
CSC 1010 Programming for All Lecture 7 Input, Output & Graphics.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Xiaojuan Cai Computational Thinking 1 Lecture 5 Objects and Graphics Xiaojuan Cai (蔡小娟) Fall, 2015.
Documenting a function. Documenting a function definition We have a template for information that we need you to put at the top of each function - if.
Introduction to Graphics. Graphical objects To draw pictures, we will use three classes of objects: –DrawingPanel : A window on the screen. –Graphics.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 4 Objects and Graphics.
5. COMPUTING WITH GRAPHICS OBJECTS Dennis Y. W. Liu and Rocky K. C. Chang October 8, 2015 (Adapted from John Zelle’s slides)
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.
CS 115 Lecture 6 Graphics Taken from notes by Dr. Neil Moore.
ENGINEERING 1D04 Tutorial 4. What are we doing today? Focus Functions Scope of Variables Returning Values Objects Graphics library Aliasing Events Mouse.
Graphics Taken from notes by Dr. Neil Moore & Dr. Debby Keen
GUI in Python Ismail Abumuhfouz.
Adapted from slides by Marty Stepp and Stuart Reges
Python Programming: An Introduction to Computer Science
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Python: Simple Graphics and Event-driven Programming
Building Java Programs
Lesson One: The Beginning Chapter 1: Pixels Learning Processing Daniel Shiffman Presentation by Donald W. Smith Graphics from
CSc 110, Spring 2017 Lecture 6: Parameters (cont.) and Graphics
Graphics Part I Taken from notes by Dr. Neil Moore
Graphics Part I Taken from notes by Dr. Neil Moore
Basic Graphics Drawing Shapes 1.
CS 106A, Lecture 12 More 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
CS 115 Lecture Graphics II – coordinate systems, Text, Entry, aliases
CSc 110, Spring 2018 Lecture 9: Parameters, Graphics and Random
Building Java Programs
SSEA Computer Science: Track A
Graphics Part I Taken from notes by Dr. Neil Moore
CSE 142 Lecture Notes Graphics with DrawingPanel Chapter 3
Simple Graphics Package
Building Java Programs
Class 7 coordinates: pixel and with setCoords aspect ratio Rectangle
Building Java Programs
Building Java Programs
Class 6 using the math library
Building Java Programs
Building Java Programs
Graphics Reading: Supplement 3G
Building Java Programs
Presentation transcript:

Some Graphics CS303E: Elements of Computers and Programming

Announcements Test NEXT Wednesday, May 1st Test NEXT Wednesday, May 1st –Same time (regular class time) –Place: UTC 2.112A Study guide, sample exams up later today Study guide, sample exams up later today

Some Graphics Very Brief Introduction Very Brief Introduction Uses Zelle’s graphics module Uses Zelle’s graphics module –Download from his website: – –Put in same directory as your program

Graphics Objects Recall that in object-oriented programming objects consist of: Recall that in object-oriented programming objects consist of: –Data –Actions on that data (methods) To use the graphics packages you: To use the graphics packages you: –Create objects –Perform actions on those objects

Example: A Possible Circle Object Data Data –center = (20,20) –radius = 10 –interior_color = “blue” –outline_color = “green” Operations Operations –Draw myself –Move myself –Set interior color –Set outline color

Windows Graphics objects are drawn on windows Graphics objects are drawn on windows –Windows are also objects –A single program can create multiple windows Created using the GraphWin() object Created using the GraphWin() object

GraphWin() Objects GraphWin(title, width, height) GraphWin(title, width, height) –Constructs a new graphics window –All parameters are optional –Default size is 200x200 setBackground(color) setBackground(color) –Sets window’s background to a color –Options: red, cyan, green, blue, purple, yellow getMouse() getMouse() –Pause for a mouse click in the window, and return the Point at which it was clicked close() close()

Example: Creating a Window from graphics import * win = GraphWin() win2 = GraphWin(“Second”,300,300)

Point Objects Often used to define the position of other objects Often used to define the position of other objects Can also be drawn on the window Can also be drawn on the window

Points Objects: Operations Point(x,y) Point(x,y) –Construct a point with the specified coordinates x and y getX() getX() –Returns the x coordinate of the point getY() getY() –Returns the y coordinate of the point AND all the operations for drawable objects AND all the operations for drawable objects

Drawable Objects A category of objects that are drawable A category of objects that are drawable All drawable objects implement all the drawable operations All drawable objects implement all the drawable operations Includes: Point, Line, Circle, Oval, Rectangle, … Includes: Point, Line, Circle, Oval, Rectangle, …

Drawable Objects: Operations MethodDescription setFill(color) Sets the interior color of the object to the specified color setOutline(color) Sets the outline of the object to the specified color setWidth(pixels) Sets the width of the object’s outline to the specified number of pixels draw(graphicWindow) Draws the object on the specified graphics window undraw() Undraws the object move(dx,dy) Moves the object dx units in the horizontal direction and dy units in the vertical directions

Example: Point Objects pt=Point(15,55) #construct a #point with #x=15, y=55 pt.setOutline(“purple”) pt.draw(win) #draw point on #the window win

Question Which is a Boolean value? A. True B. true C. “True” D. “true”

Circle Objects A Circle is defined by its center coordinates (given as a Point ) and its radius A Circle is defined by its center coordinates (given as a Point ) and its radius Operations: Operations: –Circle(centerPoint, radius) Constructs a circle with a specified center point and radius Constructs a circle with a specified center point and radius –getRadius() Returns the radius of the circle Returns the radius of the circle

Example: Circle Objects cir=Circle(Point(50,100), 25) #center=(50,100), radius=25 #center=(50,100), radius=25 cir.setFill(“yellow”) #set #interior to yellow cir.draw(win) #draw circle on #window win

Line Objects Specified by two points Specified by two points Operations: Operations: –Line(point1, point2) Construct a line from point1 to point2 Construct a line from point1 to point2 –setArrow( ) Set arrow status of the line. Set arrow status of the line. Possible values for are: first, last, both, or none. Possible values for are: first, last, both, or none.

Example: Line Objects diag = Line(Point(0,0),Point(200,200)) #line from top left to bottom right diag.setWidth(15) #increase thickness diag.setOutline(“blue”) #make it blue diag.draw(win) #draw line on window win

Rectangle Objects Draws a rectangle Draws a rectangle Operations Operations –Rectangle(point1, point2) Constructs a Rectangle with opposite corners point1 and point2 Constructs a Rectangle with opposite corners point1 and point2

Example: Rectangle Objects rec1 = Rectangle(Point(3,4),Point(8,10)) rec1.setFill(“green”)rec1.draw(win)

Exercise

Exercise

Question I’ll come to class Monday, 4/29, prepared to: A. Take an exam B. Ask questions to review for the exam C. Sleep