# Marketing and CS

Animation and CS Philip Chan Animation Hand-drawn Early Disney movies Animation

Hand-drawn Early Disney movies Computer-drawn Pixar movies Animation A sequence of drawings

Shown to the audience quickly flip book A simple animation A stick figure kicking a ball What are the basic shapes that you need?

A simple animation A stick figure kicking a ball What are the basic shapes that you need? lines circles Drawing a Line Drawing a Line

Input Starting point: (x1, y1) Ending point: (x2, y2) Output A line from (x1,y1) to (x2, y2) How?

Drawing a Line Same as plotting an equation on graph paper Drawing a Line Same as plotting an equation on graph paper Given an equation: y = f(x) Drawing a Line

Same as plotting an equation on graph paper Given an equation: y = f(x) 1. Determine the x interval (domain) 2. Sample x values 3. Calculate the corresponding y values (range) 4. Plot the (x, y) pairs Equation for a Line What is the equation for a line?

Equation for a Line What is the equation for a line? y = mx + b What is m? What is b? Equation for a Line Given (x1, y1) [start] and (x2, y2) [end]?

How to determine m and b? Finding Slope m (x2, y2) (x1, y1) Finding Slope m (x2, y2)

? (x1, y1) Finding Slope m (x2, y2) y2-y1

(x1, y1) ? Finding Slope m (x2, y2) y2-y1

(x1, y1) m = rise / run x2-x1 Finding Slope m (x2, y2)

y2-y1 (x1, y1) x2-x1 m = rise / run m = (y2 y1) / (x2 x1)

Finding y-intercept b y = mx + b Plug in the calculated m and given (x1,y1) y1 = m*x1 + b Solve for b Finding y-intercept b y = mx + b

Plug in the calculated m and given (x1,y1) y1 = m*x1 + b Solve for b b=? Finding y-intercept b y = mx + b Plug in the calculated m and given (x1,y1) y1 = m*x1 + b

Solve for b b = y1 - m*x1 Calculating Slope m = slope = (y2 y1) / (x2 x1) Could have a problem? Calculating Slope m = slope = (y2 y1) / (x2 x1)

Could have a problem? x2 x1 could be zero Division by zero! What kind of line is that? Vertical Lines x1 is the same as x2 Dont need the equation Change y values from y1 to y2

Without changing x Equation for a Line -- Summary Given (x1, y1) [start] and (x2, y2) [end] y = mx + b m = (y2 y1) / (x2 x1) If x2 and x1 are not the same b = y1 - m*x1

Drawing a Line (reminder) Same as plotting an equation on graph paper Given an equation: y = f(x) 1. Determine the x interval (domain) 2. Sample x values 3. Calculate the corresponding y values (range) 4. Plot the (x, y) pairs Algorithm Summary

If not a vertical line Find equation for the line By calculating slope (m) and y-intercept (b) For each x value from x1 to x2 (domain)

Calculate corresponding y value Plot the (x, y) pair Else For each y value from y1 to y2

Plot the (x, y) pair Drawing a Circle Drawing a Circle Input Center (a, b) Radius r

Output A circle centered at (a,b) with radius r Drawing a Circle Similar to a line Find the equation Sample x values

Calculate the corresponding y values Plot the (x,y) pairs Equation for a Circle (x,y)

r (a,b) Equation for a Circle (x,y) r

(a,b) Equation for a Circle (x,y) r (a,b)

? Equation for a Circle (x,y) r ? (a,b)

x-a Equation for a Circle (x,y) r (a,b)

y-b x-a Equation for a Circle 2

2 2 () +() = (x,y) r (a,b)

y-b x-a Equation for a Circle We want to sample x and get y values

Solve for y Equation for a Circle We want to sample x and get y values

Solve for y Equation for a Circle We want to sample x and get y values

Solve for y Equation for a Circle We want to sample x and get y values

Solve for y Domain of x Values (x,y)

r (?,?) (a,b) y-b x-a

(?,?) Domain of x Values (x,y) r (a-r, b) (a,b)

y-b x-a (a+r, b) Each x Value has Two y Values

(x,y) r (a-r, b) (a,b) y-b x-a

(a+r, b) Each x Value has Two y Values Algorithm Summary For each x value from a-r to a+r (domain) Calculate the corresponding two y values

Using the equation for a circle Plot the two (x,y) pairs Drawing a Filled Circle

Fill the Circle with a Color Ideas? Fill the Circle with a Color How would you systematically fill it by hand? Fill the Circle with a Color Hint: you have two y values for each x

Algorithm Summary For each x value from a-r to a+r (domain) Calculate the corresponding two y values (y1 and y2)

Using the equation for a circle Draw vertical line between (x,y1) and (x,y2) Drawing a Moving Ball Drawing a Moving Ball Basic ideas for moving a ball?

Drawing a Moving Ball Drawing the ball in a different location for each frame/image Sequence of images flipbook

Moving a Ball in a Straight Line Input Center of ball and starting point (x1,y1) Radius of ball r Ending point (x2, y2) Output Moving a ball with radius r

from (x1, x2) to (x2, y2) Moving a Ball in a Straight Line Redraw the ball At a different center Along a straight line

Using the equation for a line Two Approaches to a Moving Ball 1. Multiple pictures Each picture is different Ball at different locations

Two Approaches to a Moving Ball 1. Multiple pictures Each picture is different Ball at different locations 2. One picture

Edit the picture Ball at different locations Two Approaches to a Moving Ball 1. Multiple pictures Each picture is different

Ball at different locations 2. One picture Edit the picture Ball at different locations

Tradeoffs? When the picture has only a moving ball Two Approaches to a Moving Ball 1. Multiple pictures Each picture is different Ball at different locations

2. One picture Edit the picture Ball at different locations Tradeoffs? When the picture has only a moving ball

When the picture has many stationary objects (e.g. buildings), and only one moving ball Algorithm Summary (using only one picture) At each (x,y) along a straight line from (x1,y1) to (x2,y2) Draw a filled circle centered at (x,y)

Show the picture Delay/sleep for some time Why?

Erase the filled circle centered at (x,y) Why? How?

## Recently Viewed Presentations

• Poppies are a symbol of hope. The poppy became a symbol of hope, that those who had fought would be remembered by future generations and that that sacrifice of all those who were killed and injured would not have been...
• In Lesson Feedback - Plenaries . An effective plenary should highlight a pupil's misconceptions. Once identified these need to be addressed either at the time or within the lessons that follow. They should also give the pupils opportunity to reflect...
• VA Women's Mental Health Services Research Paula P. Schnurr, Ph.D VA National Center for PTSD Dartmouth Medical School HSR&D Support for Women's Health Research Special solicitation focused on WHR since 1996 Aimed at explaining care and utilization by women Veterans...
• Notice that each categorical word is in the same grammar form: adverbs. Don't mix and match the terminology! Writing the Classification Essay Questions to Consider Do you use the most logical principle of division or classification for your purpose? Do...
• Figure 3. Myelosuppression profiles for the same 25 ran-domlygenerated individuals as in Figure 1, receiving the same 100mg, 1-hr infusion. Together, these pharmacokinetic and myelosuppression models comprise a population PK/PD model
• Slide 4 Sources of Law in the EU Official Journal Major EU Institutions Co-decision Procedure Slide 9 Slide 10 EUR-LEX searching EUR-LEX record EUR-LEX record (con't) National Execution Measures (implementation by members) Tracking national implementation N-LEX Directory of European Union...
• All trunks must have a native VLAN Native VLAN must be the same on both ends (both switches). Can be modified to be a VLAN other than VLAN 1. Should not be used for user VLAN or Management VLAN. Control...
• Times New Roman Arial Wingdings Courier New Symbol netskills_ppt Introduction to JavaScript Introduction What is JavaScript? JavaScript Allows Interactivity How Does It Work? What is Java? Learning JavaScript JavaScript Statements JavaScript Statements JavaScript Statements Example Statements ...