CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.

Slides:



Advertisements
Similar presentations
James A. Rome TGA August 2009 Mapping the TZs. In Java it is quite easy to do maps The only way to tell if we interpolated the data successfully is to.
Advertisements

Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Create a Simple Game in Scratch
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.
CS2984: Introduction to Media Computation Drawing directly on images.
TOPIC 5 INTRODUCTION TO PICTURES 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
SuperStar Basics Brian Bruderer. Sequence Editors Traditional sequence editors use a large grid to control when channels are turned on and off. This approach.

Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
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.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
CSC 160 Computer Programming for Non-Majors Section 1.2: Drawing a UFO Prof. Adam M. Wittenstein
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
ABC’s of PowerPoint (Office 2007) Part 1: Basic Vocabulary Part 2: Cursors Part 3: Insert Your Text Part 4: Insert Your Pictures Part 5: Basic Tools &
Power Point Presentation - Advanced Julia J. Stahl Distributed System Specialist.
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.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
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.
Agenda For Feb Finish up Unit 3 Exercises on page Unit 4 Exercises on page 33. Question #2 3. Create a Happy Face Java Applet (due next class).
Color Correct and Remove Keystoning A minimalist approach to photographing your art By Paul Marley.
PowerPoint 1 The Basics 1. Save this file to your Apps Folder as YourLastName_PP1 2. Read each slide. 3. Complete each set of numbered directions.
Changing Camera Views! Part 2: Simple Scene Change & Lighting Fixes By Bella Onwumbiko under the direction of Professor Susan Rodger Duke University July.
3–D Helium Molecule Tutorial Alice Project Duke University Professor Susan H. Rodger Gaetjens Lezin June 2008.
Introducing Scratch the Cat
Changing Color, Using Text Objects, and Random Selection in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Line Graphics Summary 1.drawLine(xStart, yStart, xEnd, yEnd); 2.drawRect(x, y, width, height); 3.drawRoundRect(x, y, width, height, cornerWidth, cornerHeight);
Graphics & Java 2D Drawing Two Dimensional Shapes Controlling Fonts Controlling Colors.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
To begin click: File, New, then select Design Familiarize yourself with the controls on the page. Then use the maximise button the make the window fill.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
CSC 1010 Programming for All Lecture 7 Input, Output & Graphics.
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
Ready, SET, go! By Melissa Dalis Professor Susan Rodger Duke University July 2011.
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.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Processing  Install Processing  Learn how to edit, run, save, export,
Java With NetBeans First Project. Java Are language for this semester is Java The Development Environment is Netbeans.
CompSci 42.1Intro to Java Anatomy of a Class & Terminology Running and Modifying a Program.
CompSci 4 Chap 10 November 4, 2010 Prof. Susan Rodger.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Building Java Programs
Levels of Organization Ecology Flow
Building Java Programs
Building Java Programs
Building Java Programs
Lesson One: The Beginning Chapter 1: Pixels Learning Processing Daniel Shiffman Presentation by Donald W. Smith Graphics from
Basic Graphics Drawing Shapes 1.
به نام مهربانترین In the name of the most compassionate
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
Building Java Programs
SSEA Computer Science: Track A
Go to =>
Levels of Organization Ecology Flow
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Creating a Simple Game in Scratch
Graphics Reading: Supplement 3G
Presentation transcript:

CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger

Announcements Assignment 7 presentations –April 16 and April 21 –Attendance mandatory both days! Final Exam – Tuesday, April 28 – LSRC D106, 2-5pm Classwork Today: Quilt

Problem: Draw a 2-item Quilt Quilt has two items: red circle, blue square Each row alternate items across Each col alternate items down

Write a complete program Project is CPS4Quilt Also doing graphics today with Java Two classes in the project –Main.java - DON’T MODIFY THIS FILE –Canvas.java – ONLY MODIFY ONE METHOD - paintComponent

Java Program Has lots of classes One class has a method named “main” –Starting point, like world.myfirstmethod in Alice

main method of Quilt program Creates a canvas of size 600 x 600 pixels you can draw on Lots of Graphics setup stuff – ignore for now

Quilt main method

Canvas Class– Part 1

First list class variables (like properties in Alice) and give their types Special method with same name as class –called a constructor –Give initial values to all class variables here –(see previous slide: public Canvas( … ) )

Canvas Class - Part 2

paintComponent method – special method for graphics – automatically called Pass in a pen that draws the picture Use “pen.setColor(java.awt.Color.red)” to change the color of the pen to a red pen –Doesn’t draw anything, just sets the color Other Colors: blue, green, yellow, black, cyan, pink, orange, magenta

Canvas Class – Part 2 (cont) Draw an oval with the pen using pen.fillOval(x,y,width, height); –Draws a filled oval with top left corner at position (x,y) and with width and height Draw a rectangle with the pen using pen.fillRect(x,y,width,height);

Classwork: Draw a Quilt Pick two shapes and two colors and draw them alternating on a quilt Have the code flexible so you can change the number of shapes per line and the quilt will adjust to fit them on the line (it is ok if they don’t fit exactly in the canvas) myNumItemsInRow = ? myNumItemsInCol = ?

Example

Getting Started Project started for you, “snarf” it and just modify paintComponent to draw the quilt In Eclipse, select “ambient”, then “Download (snarf) a project” (MUST HAVE AMBIENT to get code!) Must connect to CompSci 4 Snarf site Click here and add this snarf site

Getting Started (cont) Download folder CPS4Quilt Run program to see what it does –Right Click on Main.java (has main method) –Select “Run As” then “Java Application” –Should see:

Look at Loop again This prints circles with top left corner at: (0,0), (50, 0), (100, 0), (150, 0) … This prints rectangles with top left corner at: (0,100), (50, 100), (100, 100), (150, 100) …

Step 1: Look at the PaintComponent Method Pick two shapes and colors (can be the same shape if you want) and modify the code to print out those shapes and colors. I picked red circle and blue rectangle

Note After each step, make a copy of your loop code and comment one copy out. Add a comment to say what the loop does. Then you can go back and see how you did a previous step….

Step 2: Change the size of your two objects to make them bigger (with height and width set to 40) Note we are printing them with 10 units of blank space between two

Step 3: Now print circles and rectangles all the way across the canvas. The width of the canvas is myWidth

Step 4: Now move the 2cd object up so it is 10 units away from the 1 st object.

Step 5: Change so that the two objects are both printed on the same line. Print one object first every 100 units. Print the second object starting at position (50,0) and then one every 100 units. Note: use the same loop, you only have to change the (x,y) value for each

Step 6 Print two rows, one starting with one object and the other row starting with the other object. Copy the four lines inside your for loop so you have 8 lines in your for loop, fix the last four lines to print the second row

Step 7 Now tighten it up to get rid of the 10 units of space between items.

Step 8 Add another loop around the whole loop to repeat these two rows to complete the quilt (for int j=0; j < ? ; j++) Look at how you used “x” How do you use “j”? Think about the y part of (x,y) position Try commenting out some lines and focusing on just one line at a time to get right

Step 9 Make quilt shapes adjustable…. When you modify myNumItemsInRow and myNumItemsInCol, quilt should adjust to fill the canvas so you get different sizes…. But you must use those variables somewhere!

Quilt Requirements Must use two shapes (two circles, two squares, or one circle and one square) Must use two colors Must make quilt adjustable. When you modify myNumItemsInRow and myNumItemsInCol, quilt should adjust to fill the canvas Ok if edge of quilt is not correct Check off work when done.