Graphics Concepts CS 2302, Fall 2014. 12/3/20142 Drawing Paths.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Made with love, by Zachary Langley Applets The Graphics Presentation.
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.
Variables and Operators
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Chapter 5 Programming Graphics. Chapter Goals To be able to write simple applications To display graphical shapes such as lines and ellipses To use colors.
CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Viewing & Clipping In 2D. 2 of 44 Contents Windowing Concepts Clipping –Introduction –Brute Force –Cohen-Sutherland Clipping Algorithm Area Clipping –Sutherland-Hodgman.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
Road Map Introduction to object oriented programming. Classes
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
CSC 160 Computer Programming for Non-Majors Lecture #8: Animations I Prof. Adam M. Wittenstein
© The McGraw-Hill Companies, 2006 Chapter 18 Advanced graphics programming.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
ObjectDraw and Objects Early Chris Nevison Barbara Wells.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
Week 5 Recap CSE 115 Spring Composition Informally called “has a” Represented in UML with a diamond- headed arc In code: Declare an instance variable.
Games and Simulations O-O Programming in Java The Walker School
TOPIC 9 MODIFYING PIXELS IN A MATRIX: COPYING, CROPPING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
Factoring Expressions
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
TOPIC 3 INTRODUCTION TO PROGRAMMING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
CSC Programming I Lecture 8 September 9, 2002.
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
tiled Map Case Study: Rendering with JPanel © Allan C. Milne v
CSCI-383 Object-Oriented Programming & Design Lecture 14.
به نام خدا تنظیم کننده : فرانه حدادی استاد : مهندس زمانیان تابستان 92.
Learners Support Publications Classes and Objects.
Lesson 34: Layering Images with Java GUI. The FlowLayout RECAP.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Creating a Multiple-Form Interface.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Lecture 08. Since all Java program activity occurs within a class, we have been using classes since the start of this lecture series. A class is a template.
More Control Properties Part 10 dbg. Form Properties that Affect TitleBar ControlBox Property (T/F) Do you display the icon, associated menu to the left,
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
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.
Aquarium Lab Series Developed by Alyce BradyAlyce Brady of Kalamazoo CollegeKalamazoo College.
CS 115 Lecture 7 Graphics – coordinate systems, Text, Entry, aliases Taken from notes by Dr. Neil Moore.
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Sound and more Animations
Topic 9 Modifying Pixels in a Matrix: Copying, Cropping
Scratch for Interactivity
Factoring Expressions
Classes.
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
Project Snake. Project Snake Snake For this project, we’re going to make Snake This includes Making the overall game logic (using a 2D array) Handling.
Packages and Interfaces
Teaching Java using Turtles part 2
A+ Computer Science METHODS.
Classes and Objects.
Workshop for Programming And Systems Management Teachers
A+ Computer Science METHODS.
Object Oriented Programming in java
Submitted By : Veenu Saini Lecturer (IT)
Teaching Java using Turtles part 2
Presentation transcript:

Graphics Concepts CS 2302, Fall 2014

12/3/20142 Drawing Paths

12/3/20143 Random Diamonds Create a method that will draw a random diamond The method will get a Canvas The class will have a static random number generator defined The center and width and height of the diamond will be randomly computed The fill and outline colors will be randomly chosen The color value will be in a specified range

12/3/20144 Random Coordinates The width and height of the View used for drawing can be obtained with getWidth() and getHeight(), repsectively The width times a random float (in the range 0 to 1) will give the x coordinate of the center The y coordinate is similar, but uses the height To determine the diamond's width Compute the distance of the center from the left and right edges Multiply the minimum by a float and then by 2 The diamond' height is similar

12/3/20145 Random Colors Using RGB to pick random colors does not give very good colors Using HSV to pick colors gives better results The Value will be in the range from.25 to.75 Specified in the diamonds resource file The Hue and saturation will be randomly chosen over their entire range

12/3/20146 Many Random Diamonds Modify the diamond view to draw many diamonds at random The number of diamonds is another resource

12/3/20147 Interactive Diamonds View This is the same as the basic diamond view except that every time the view is clicked, the number of diamonds is reduced by 1 The view will contain a listener registered to 'this' Once the number of diamonds has been reduced, the view must be redrawn Note that, right now, clicking the view causes no visible change Write a message to the log file (visible in the logcat view) to show that the listener is actually active

12/3/20148 Interactive Diamonds View This is the same as the basic diamond view except that every time the view is clicked, the number of diamonds is reduced by 1 Copy the diamond view class and use the new class as a component Define an onClick listener Register the listener to 'this' The Listener will reduce the number of diamonds Note that, right now, clicking the view causes no visible change Write a message to the log file (visible in the logcat view) to show that the listener is actually active

12/3/20149 Forcing Redrawing There is an internal change but not a visible change The onDraw method must be executed somehow However, we don't have a Canvas, necessary to call onDraw There's no good way to create a useful one either The system must call onDraw So, we ask the system to call onDraw for us This is what the method 'invalidate' does It tells the system that the current state of the view is not valid, so it must be redrawn

12/3/ Redrawing Restarts Notice that the collection of diamonds displayed changes each time the number is reduced To keep the same set of diamonds, the diamonds have to be stored so that they can be redrawn as they were This requires Keeping a list of diamonds Representing diamonds

12/3/ Representing Diamonds Create a class that holds the essential values Colors: fill and outline Coordinates: left, top, right, bottom This will be a private class inside the View so The instance variables will be final and public A constructor will set the instance variables

12/3/ List of Diamonds Create a list of Diamond objects in the View The list will be initially null Create a method to initialize the list to a random list of diamonds Scavenge the code used to draw random diamonds

12/3/ When to Initialize Setting up the list is tricky The constructor for the View is too soon since the dimensions of the View are not known then The onDraw method can initialize the list, but should only do it once OnDraw checks if the list is null and initializes the list if it is null

12/3/ Drawing a Diamond Modify the drawDiamond method to take a Diamond object instead of the separate parameters Change the references in the body

12/3/ OnDraw Changes Change onDraw to Check if the list of Diamond objects should be initialzied Draw the list

12/3/ Change Listener The listener will remove a Diamond from the list Check if the list is empty before doing that!