Week 8 - Monday.  What did we talk about last time?  StdAudio.

Slides:



Advertisements
Similar presentations
Graphics Shapes. Setup for using graphics You have to import the graphics library You can use either “import graphics” or “from graphics import *” or.
Advertisements

Noadswood Science,  To know how to use Python to produce windows and colours along with specified co-ordinates Sunday, April 12, 2015.
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.
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.
Week 7: Input and Output 1.  Now we are going to talk a little bit about output  You have a lot of experience with System.out.println() and System.out.print()
Chapter 5 Programming Graphics. Chapter Goals To be able to write applications with simple graphical user interfaces To display graphical shapes such.
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
Chapter 6 Photoshop and ImageReady: Part II The Web Warrior Guide to Web Design Technologies.
PYTHON TURTLE WORLD : CHAPTER 4 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
Parametric Equations Here are some examples of trigonometric functions used in parametric equations.
Copyright 2008 by Pearson Education Building Java Programs Graphics Reading: Supplement 3G.
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.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 3 Variables, Calculations, and Colors Starting Out with Games.
1 Bitmap Graphics It is represented by a dot pattern in which each dot is called a pixel. Each pixel can be in any one of the colors available and the.
Views and Viewports1 Sacramento City College EDT 310.
Click your mouse for next slide Flash – Introduction and Startup Many times on websites you will see animations of various sorts Many of these are created.
Graphics A graphics program allows you to combine pictures and text in many different ways. Features – General Level Draw graphics Enter Text Common Tools.
PROCESSING & JAVA An Introduction to Computing. Objectives Be able to state and apply phases of development Be able to state and describe the goals of.
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.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 2 Graphics Programming with C++ and the Dark GDK Library Starting.
1. Press the New Layer Button 3. Double click names to re-name Ball & Shadow layers 2. Click to change to 12 fps Step 1.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
CS177 RECITATION WEEK 7 Input and Output (Text & Graphical)
Android Graphics Library. Color Android colors are represented with four numbers, one each for alpha, red, green, and blue (ARGB). Each component can.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
CS 112 Introduction to Programming Graphics; Animation Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone:
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.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
Strategy Using Strategy1. Scan Path / Strategy It is important to visualize the scan path you want for a feature before you begin taking points on your.
CSC 1010 Programming for All Lecture 7 Input, Output & Graphics.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
File Input and Graphics An extract of slides from set 05_inout.ppt Designed to get you ready for the HW3.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
CRE Programming Club - Class 5 Robert Eckstein and Robert Heard.
Building Java Programs Graphics Reading: Supplement 3G.
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.
CS 5JA Introduction to Java Graphics One of the powerful things about Java is that there is.
Week 10 - Friday.  What did we talk about last time?  References and primitive types  Started review.
Welcome to Processing Who does not have access to digital camera?
Computer Science I Animations. Bouncing ball. The if statement. Classwork/homework: bouncing something. Compress and upload work to Moodle.
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
Turtle Graphics Let’s see what we can draw on Python!
Session 7 More Implications of Inheritance & Chapter 5: Ball World Example.
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.
Building Java Programs
Basic Graphics Chapter 5 3/19/15 Thursday Section Only
Building Java Programs
Building Java Programs
Week 8 - Monday CS 121.
Week 15 – Wednesday CS 121.
Learning to program with Logo
Basic Graphics Drawing Shapes 1.
Chapter 3 Variables, Calculations, and Colors
Building Java Programs
Building Java Programs
Lecture 7: Introduction to Processing
Building Java Programs
Building Java Programs
1.5 Input and Output Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2002–2010 2/14/11.
Building Java Programs
Building Java Programs
Building Java Programs
Graphics Reading: Supplement 3G
Presentation transcript:

Week 8 - Monday

 What did we talk about last time?  StdAudio

 StdDraw is a library of Java code developed by Robert Sedgewick and Kevin Wayne  StdDraw allows you to draw output on the screen easily  You can draw points, lines, and polygons in various colors  You can clear and resize the drawing area and even save the results  StdDraw is not standard Java that everyone uses, but it’s a nice tool for graphics

 The simplest things you can draw with StdDraw are lines and points  The first thing you should be aware of is that the canvas is drawn like Quadrant I of a Cartesian plane (0,0) (0,1)(1,1) (1,0)

 The following methods can be used to draw lines and points MethodUse void line(double x0, double y0, double x1, double y1) Draw a line from (x0,y0) to (x1,y1) void point(double x, double y) Draw a point at (x,y)

 Let’s draw a box then divide it into two halves, like so:

 There are built in commands for drawing:  Circles  Squares  Arbitrary polygons  Filled versions of each one of these  We won’t bother with the arbitrary polygons  It is also possible to set the color

 Here are some methods for drawing circles and squares and setting the color for doing so: MethodUse void circle(double x, double y, double r) Draw a circle centered at (x,y) with radius r void filledCircle(double x, double y, double r) Draw a filled circle centered at (x,y) with radius r void square(double x, double y, double r) Draw a square centered at (x,y) with edges 2r void filledSquare(double x, double y, double r) Draw a filled square centered at (x,y) with edges 2r void setPenColor(Color c) Start drawing with color c

 Eventually you will be able to define your own colors  For now you are limited to 13 presets  For example, to make something magenta, you would use the value StdDraw.MAGENTA BLACKBLUECYANDARK_GRAYGRAY GREENLIGHT_GRAYMAGENTAORANGEPINK REDWHITEYELLOW

 Let’s write some code for making 100 circles at random locations with random sizes and random colors  Location is easy  Size is easy, we just decide on the range of sizes we want and do some math  Color is more painful  We need a switch statement with 13 choices

 We just want to make a pattern of black and white squares on the screen  Hint: We need two loops

 A number of methods are given to give us more control over the display MethodUse void setXscale(double x0, double x1) Set the x scale void setYscale(double y0, double y1) Set the y scale void setPenRadius(double r) Set the pen radius void setCanvasSize(int w, int h) Set canvas size void clear() Clear canvas to white void clear(Color c) Clear canvas to color c void show(int delay) Delay for delay ms

 As you have seen, the default scale of the canvas is in the range [0,1] for both x and y  We can use the setXscale() method to set the minimum and maximum x values  We can use the setYscale() method to set the minimum and maximum y values  Useful for plotting functions

 Note that changing the scale doesn’t change the size of the window, just what is shown in it  If you want to change the size of the window, use the setCanvasSize() method to set the width and the height of the canvas in terms of screen pixels

 The show() method lets you specify a delay in milliseconds before things are drawn on the screen  You can use it to slow down or speed up animations

 Can we simulate a cannon being fired?  Let the user enter an initial velocity in m/s  Let the user an angle between 0° and 90°  Assume each iteration takes 1/10 of a second  Assume an initial height of 20 m  We draw the path of the cannon ball as it flies through the air  Let’s also set the x and y scales to both be [0,100]

 Plotting functions is really useful  Getting smooth curves is hard  Instead, we just pick a whole bunch of x points and figure out the function value  We can just draw dots to plot those values  We can connect them with lines for a more connected look  Let’s write some code to draw cubic polynomials

1. Ask the user for the coefficients of the four terms (ax 3 + bx 2 + cx + d) 2. Ask the user for an x range 3. Run through the function and find the minimum and maximum y values hit 4. Rescale the drawing area to show everything 5. Plot the function

 Static methods

 Read Chapter 8 of the textbook  Get an early start on Project 3  It's harder than the previous two!