COM148X1 Interactive Programming Lecture 6. Topics Today Generate Random Numbers Graphics Animation.

Slides:



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

Lesson One: The Beginning
Chapter 9 Color, Sound and Graphics
COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
Copyright 2008 by Pearson Education Building Java Programs Graphics Reading: Supplement 3G.
Tutorial 3 Designing a Web Page.
An array of controls Not particularly convenient in VB Examples: array of pictureboxes Array of textboxes Notes on Concentration game (a possible final.
Workshop: CSS-Part I Cascading Style Sheets add style to your HTML web pages.
Higher-level PHP constructs for manipulating image files.
Chapter 13 Graphics, Animation, Sound, and Drag-and-Drop Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Graphics and Multimedia. Outline Introduction Graphics Contexts and Graphics Objects Color Control.
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.
Graphics and Multimedia. Outline Drawing Polygons and Polylines Advanced Graphics Capabilities.
Visual Basic Graphics Warning: The way I am using Visual Basic graphics is somewhat different (and much simpler!) to that of the book. Use these slides.
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
Graphics Images – PictureBox control Drawing graphics - Graphics object Multimedia controls PictureBox control Image property – select image Choose how.
1 Chapter 26 D&D – Graphics Outline 26.1 Introduction 26.3 Graphics Contexts and Graphics Objects 26.4 Color Control 26.5 Font Control 26.6 Drawing Lines,
HIGHER COMPUTING CSS. WHAT IS CSS? CSS: Cascaded Style Sheets used to separate a web site’s content(information) from its style(how it looks).
1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes and Combo Boxes 9.2 Eight Additional Controls and Objects 9.3 Multiple-Form Objects 9.4 Graphics.
COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
Graphics and Multimedia Part #2
Chapter 9 - VB.Net by Schneider1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes, Combo Boxes, and the File-Opening Control The List Box Control.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
Arrays Code: Arrays Controls: Control Arrays, PictureBox, Timer.
Some graphics. Projects included A slideshow a dark moon moving phases of the moon billiards Your own icons and bitmaps Pie chart.
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.
Tkinter Canvas.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
1 Graphic Device Interface (GDI). 2 Class Form A Form is a representation of any window displayed in your application. The Form class can be used to create.
Cascading Style Sheets Eugenia Fernandez IUPUI. CSS Purpose CSS allow you to specify the style in which your XML elements are displayed. CSS were originally.
16.9 Introduction to Multimedia Visual Basic offers many convenient ways to include images and animations in programs Computing field decades ago mainly.
HTML & Color How to Use Color  Backgrounds-  Usually a light color is best  Should have a color based on a theme or plan  Can have a dark.
Fall UI Design and Implementation1 Lecture 6: Output.
Graphics and Multimedia. OUTLINE Font Control Drawing Lines, Rectangles and Ovals Drawing Arcs Drawing a General Path.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Graphic Programming Advanced Computer Programming.
CRE Programming Club - Class 5 Robert Eckstein and Robert Heard.
Images Part 11 dbg. 2 Images The form and several controls can display a number of different types of image files in the BackgroundImage Property. These.
Lab 10 Slides.
Practical Programming COMP153-08S Lecture: Repetition.
Paint Tutorial Created February 2006 Start Paint: Start>Programs>Accessories>Paint.
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
ColorsColors. Color Keywords/Names 140 color keywords/names are defined in the HTML and CSS color specification –17 standard colors (HTML accepts 16 of.
COM148X1 Interactive Programming Lecture 8. Topics Today Review.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Graphics and Multimedia 2 Lecture 8. OUTLINE Font Control Drawing Lines, Rectangles and Ovals Drawing a General Path.
Chapter 13 Colors & backgrounds.
CSS Layouts CH 13.
Creating Your Own Webpage
Building Java Programs
Cascading Style Sheets
Computer Programming I
Graphics and Multimedia
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
Basic Graphics Drawing Shapes 1.
Building Java Programs
CSc 110, Spring 2018 Lecture 9: Parameters, Graphics and Random
Images Presentation Name Course Name Unit # – Lesson #.# – Lesson Name
What Color is it?.
Building Java Programs
Building Java Programs
Cascading Style Sheets
Building Java Programs
Chapter 12 Graphics in Windows and the Web
Presentation transcript:

COM148X1 Interactive Programming Lecture 6

Topics Today Generate Random Numbers Graphics Animation

Generate Random Number In VB, random numbers can be generated using Rnd() function Rnd() function returns random number in the range [0 … 1) (include 0 but exclude 1) Example x = Rnd() ‘0 ≤ x < 1 x = Rnd() * 5 ‘0 ≤ x < 5 x = Int(Rnd() * 5) + 1 ‘1 ≤ x ≤ 5, integer only

Randomize() Function The number sequence generated by Rnd() will be the same when the application start Randomize() function is used to shuffle the sequence again Call Randomize() once when the application start

Pseudo Random Number Sometimes, non-repeatable random number is required, for example, shuffle a deck of card (A, 2, 3, …, J, Q, K) Use the technique called pseudo random number to generate non-repeatable random number

Pseudo Random Number Algorithm Use array to store all number Use Rnd() function to pick two array position randomly and then SWAP the content Repeat the step above several times and use the array as random result

Pseudo Random Number Example Dim cards(13) As Integer Dim j, k, card1, card2 As Integer For j = 1 To 13 cards(j) = j Next j PseudoRandom(cards)

Pseudo Random Number Example (cont’) ‘Perform pseudo random from 1 … UBound(a) Sub PseudoRandom(ByRef a() As Integer) For k = 1 to card1 = Int(Rnd() * UBound(a)) + 1 card2 = Int(Rnd() * UBound(a)) + 1 Swap(a(card1), a(card2)) Next k End Sub

Pseudo Random Number Example (cont’) Sub Swap(ByRef x As Integer, ByRef y As Integer) Dim temp As Integer = x x = y y = temp End Sub

Graphics

Coordinate System Coordinate of form use (x, y) coordinate system Upper left corner is the origin x value increase from left to right y value increase from top to bottom All UI controls use their upper left corner as their reference position

Coordinate System x y (0, 0) (300,300) (120, 50)

Point Class Point object represents a coordinate Example Dim p As new Point(10, 20) Dim x, y As Integer x = p.X() ‘x = 10 y = p.Y() ‘y = 20 ‘change coordinate p = new Point(100, 150)

Color Class Color object represents a color Default color available for use Black, Silver, Gray, White, Maroon, Red, Purple, Fuchsia, Green, Lime, Olive, Yellow, Navy, Blue, Teal, Aqua … Example Dim c1 As Color = Color.Green ‘use default color Dim c2 As Color c2.FromArgb(128, 128, 128) ‘RGB value

SolidBrush Class Brushes specified how to fill an object SolidBrush specified which color used to fill an object Dim brush_name As New SolidBrush(color) Example Dim b As SolidBrush(Color.Red)

Pen Class Pen class is used to draw difference kinds of lines and curves Dim pen_name As New Pen(brush,width) Example Dim b As New SolidBrush(Color.Red) Dim p As New Pen(b, 1.5)

Graphics Class Before start drawing on UI controls, Graphics object of the UI control is required Use CreateGraphics() method of the UI control to obtain Graphics object Example Dim g As Graphics g = Panel1.CreateGraphics()

Commonly Use Graphics Functions FunctionDescription DrawLine(pen, p1, p2) Draw line from p1 to p2 DrawRectangle(pen, x, y, w, h) Draw w x h rectangle with top left corner at (x, y) DrawEllipse(pen, x, y, w, h) Draw w x h ellipse with top left corner at (x, y) DrawPolygon(pen, points()) Draw polygon by given array of points DrawCurve(pen, points()) Draw curve by given array of points

Commonly Use Graphics Functions FunctionDescription FillRectangle(brush, x, y, w, h) Fill w x h rectangle with top left corner at (x, y) FillEllipse(brush, x, y, w, h) Fill w x h ellipse with top left corner at (x, y) FillPolygon(brush, points()) Fill polygon by given array of points Fill ClosedCurve(brush, points()) Fill closed curve by given array of points

Graphics Functions Example Dim g As Graphics g = Panel1.CreateGraphics() Dim brush1 As New SolidBrush(Color.Red) Dim pen as New Pen(brush1, 10) g.DrawLine(pen, p1, p2) Dim brush2 As New SolidBrush(Color.Green) g.FillRectangle(brush, p1.X(), p1.Y(), 100, 150)

Animation

Image Preparation Use ImageList control to prepare a set of images for application

Properties of ImageList Images is set of Images, index start from 0 ImageSize is the size of image, maximum size is 256x256 Number of images in the ImageList can be found in the Count properties of Images Example x = ImageList1.Images.Count

Show Picture (Image) Use picture control to make different animation effects

Properties of PictureBox Control Location represents the top-left corner of PictureBox Top represents the top most coordinate of PictureBox Left represents the left most coordinate of PictureBox Width represents the width of PictureBox Height represents the height of PictureBox Image represents the picture showing in the PictureBox, set Image to Nothing in order to make the PictureBox shows nothing Example PictureBox1.Image = Nothing

Playing Animation Use Timer control to control the frame rate of animation and make the application responsive to other event when the animation is playing

Animation Example ‘move image from left to right while playing ‘image sequence inside PictureBox Dim i As Integer = 0 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim x, y as Integer x = PictureBox1.Location.X + 1 y = PictureBox1.Location.Y PictureBox1.Location = new Point(x, y) PictureBox1.Image = ImageList1.Images(i) i = (i + 1) mod ImageList1.Images.Count End Sub