Insight Through Computing 13. More on Arrays Square Bracket Notation Subscripts Plotting and color Built-In Functions: ginput, fill, sum, axis.

Slides:



Advertisements
Similar presentations
Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.
Advertisements

Important Irvine Library Procedures Randomize Randomize –Initializes the seed of the random-number formula by both the Random32 and the RandomRange procedures.
MA/CS375 Fall MA/CS 375 Fall 2002 Lecture 4.
Informationsteknologi Monday, October 29, 2007Computer Graphics - Class 21 Today’s class Graphics programming Color.
Insight Through Computing 14. Still More on Arrays Functions with array parameters. Row and column vectors Built-Ins: length, zeros, std Revisit: rand,
Insight Through Computing 17. Structures Simple Structures Structure Arrays Structures with Array Fields Other Possibilities.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/27/2003.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
Insight Through Computing 11. User-Defined Functions Input parameters Local Variables Output Values.
Insight Through Computing 8. More Practice with Iteration and Conditionals Through Graphics For-Loop Problems Introduce While-Loops.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
13.4 and 13.5 Translations, reflections, and symmetry
Click on the text to see the different geometric proofs.
Motion Geometry Part I Geometry Solve Problems Organize Model Compute
Equations of straight lines
COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing.
Art 321 Lecture 7 Dr. J. Parker. Programming In order to ‘make things happen’ on a computer, you really have to program it. Programming is not hard and.
Graphics & Java 2D Drawing Two Dimensional Shapes Controlling Fonts Controlling Colors.
Is this a square or a pentagon? It is a square.
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,
Reflections Grade 6 Copyright © Ed2Net Learning Inc.1.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Vertices, Edges and Faces By Jordan Diamond. Vertices In geometry, a vertices is a special kind of point which describes the corners or intersections.
Colors of Pigment The primary colors of pigment are magenta, cyan, and yellow. [
Lesson 9-R Chapter 9 Review. Objectives Review chapter 9 material.
Decimals, Fractions and Percentages 17/07/06 Aim : revise place value and equivalence between fractions, decimals and percentage.
Rotations. Goals Distinguish between a translation, reflection, and rotation. Visualize, and then perform rotations using patty paper. To determine the.
Digital & Interactive Media
COM366 Interactive Computer Graphics Topic 1 : Introduction.
X, Y X axis Y axis Let’s just start with a point on a plane surface like this sheet of paper. Now coordinate “x” describes how far to the right, and “y”
Introduction to Graphics. Graphical objects To draw pictures, we will use three classes of objects: –DrawingPanel : A window on the screen. –Graphics.
PART TWO Electronic Color & RGB values 1. Electronic Color Computer Monitors: Use light in 3 colors to create images on the screen Monitors use RED, GREEN,
Mixing Complementary Colors to create neutrals. Complementary colors are directly across from one another on the color wheel. When mixed they get various.
L17. Structures Simple Structures Structure Arrays Structures with Array Fields Other Possibilities.
L8. Iteration and Graphics Introduce Matlab Graphics More practice with iteration and boolean-type thinking Warm-up for functions and arrays.
CS100A, Fall 1998, Lecture 191 CS100A, Fall 1998 Lecture 19, Thursday Nov 05 Matlab Concepts: Matlab arrays Matlab subscripting Matlab plotting.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
Prof. N. P. Jadhav Presented by. Overview of MATLAB environment MATLAB is an interactive, matrix-based system for scientific and engineering numeric computation.
Digital & Interactive Media
MID-POINT CIRCLE ALGORITHM
Digital & Interactive Media
Introduction to Illustrator
Building Java Programs
Course Information Do not rely on color to distinguish curves (due to black-white printout). Use different line styles to distinguish curves (solid, dashed,
Lecture 25: Exploring data
Building Java Programs
Lesson One: The Beginning Chapter 1: Pixels Learning Processing Daniel Shiffman Presentation by Donald W. Smith Graphics from
Digital & Interactive Media
Basic Graphics Drawing Shapes 1.
MATLAB How to use (using M-files) Double click this icon
L14. Arrays and Functions Functions with array parameters.
Digital & Interactive Media
MATLAB How to use (using M-files) Double click this icon
Fractions 1/2 1/8 1/3 6/8 3/4.
Two ways to discuss color 1) Addition 2) Subtraction
Introduction to MATLAB Plotting LAB 3
Here are four triangles. What do all of these triangles have in common
L13. More on Arrays Square Bracket Notation Subscripts
Color and Shading Lecture 9 Mon, Sep 26, 2005.
Introduction to MATLAB
Plotting Signals in MATLAB
What Color is it?.
Lesson 9-R Chapter 9 Review.
Primitive Drawing Algorithm
probability with cards
Primitive Drawing Algorithm
Presentation transcript:

Insight Through Computing 13. More on Arrays Square Bracket Notation Subscripts Plotting and color Built-In Functions: ginput, fill, sum, axis

Insight Through Computing The Square Bracket These are equivalent: x = linspace(0,1,5) x = [ ] x: Handy for setting up “short” vectors.

Insight Through Computing Three “Short Vector” Examples Line Segments Little Polygons Color

Insight Through Computing Plotting a Line Segment a = 1; b = 2; c = 3; d = 4; plot([a c],[b d]) This draws a line segment that connects (1,2) and (3,4): A natural mistake: plot([a b],[c d])

Insight Through Computing Drawing Little Polygons x = [a a+L a+L a a]; y = [b b b+W b+W b]; plot(x,y) This draws an L-by-W rectangle with lower left corner at (a,b): Connect (a,b) to (a+L,b) to (a+L,b+W) to (a,b+W) to (a,b)

Insight Through Computing Coloring Little Polygons x = [a a+L a+L a a]; y = [b b b+W b+W b]; fill(x,y,c) This draws an L-by-W rectangle with lower left corner at (a,b) and colors with the color named by c: Connect (a,b) to (a+L,b) to (a+L,b+W) to (a,b+W) to (a,b) and then fill it in.

Insight Through Computing Built-In Function Fill fill(,, ) Vectors that specify the vertices of a polygon. Specify the fill-in color.

Insight Through Computing x = [ ] y = [ ] fill(x,y,’y’)

Insight Through Computing DrawRect function DrawRect(a,b,L,W,c) x = [a a+L a+L a a]; y = [b b b+W b+W b]; fill(x,y,c)

Insight Through Computing Color is a 3-vector Any color is a mix of red, green, and blue. Represent a color with a length-3 vector and an “rgb convention”. c = [ ] red value between 0 and 1 blue value between 0 and 1 green value between 0 and 1

Insight Through Computing Some Favorites White[0 0 0] Blue[0 0 1] Green[0 1 0] Cyan [0 1 1] Red[1 0 0] Magenta[1 0 1] Yellow[1 1 0] Black[1 1 1]

Insight Through Computing A Problem Display all colors [r g b] where r ranges over the values g ranges over the values b ranges over the values

Insight Through Computing Preliminary Notes There will be 5 x 5 x 5 = 125 colors to display. To display a color, we will draw a unit square with that color.

Insight Through Computing Script Derivation for r = 0:.25:1 Display all colors with red value r. end Refine This!

Insight Through Computing Script Derivation for r = 0:.25:1 for g = 0:.25:1 Display all colors with red value r and green value g. end Refine This!

Insight Through Computing Script Derivation for r = 0:.25:1 for g = 0:.25:1 for b = 0:.25:1 Display the color with red value r, green value g, and blue value b. end Refine This!

Insight Through Computing Script Derivation for r = 0:.25:1 for g = 0:.25:1 for b = 0:.25:1 c = [r g b]; fill(x,y,c) end Done!

Insight Through Computing Subscripts It is possible to access and change specific entries in an array. x = [ ] The value of x(1) is The value of x(2) is The value of x(3) is The value of x(4) is The value of x(5) is x:

Insight Through Computing Subscripts It is possible to access and change specific entries in an array. x = [ ] x: a = x(1) a = x(2) a = x(3) a = x(4) a = x(5)

Insight Through Computing Subscripts It is possible to access and change specific entries in an array. x = [ ] x: for k = 1:5 a = x(k) end

Insight Through Computing Subscripts It is possible to access and change specific entries in an array. x = [ ] x: a = x(1)+x(2) a = x(2)+x(3) a = x(3)+x(4) a = x(4)+x(5)

Insight Through Computing Subscripts It is possible to access and change specific entries in an array. x = [ ] x: for k=1:4 a = x(k)+x(k+1) end

Insight Through Computing Subscripts This x = linspace(a,b,n) is equivalent to this h = (b-a)/(n-1); for k=1:n x(k) = a + (k-1)*h; end

Insight Through Computing Subscripts h = (1-0)/(5-1); x(1) = 0 + 0*h; x(2) = 0 + 1*h; x(3) = 0 + 2*h; x(4) = 0 + 3*h; x(5) = 0 + 4*h; x:

Insight Through Computing Subscripts h = (b-a)/(n-1); for k=1:n x(k) = a + (k-1)*h ; end Recipe for a value Where to put it.* * Only now we compute where to put it. x(k)a + (k-1)*h

Insight Through Computing A Problem Click in the three vertices of a triangle. Display the triangle. Compute the centroid (xc,yc). Highlight the centroid and the vertices. Connect each vertex to the centroid.

Insight Through Computing Clicking in the Vertices The command [x,y] = ginput(3) will assign the xy coordinates of the clicks to the arrays x and y. Clicks: (1,2), (3,4), (5,6) x: y:

Insight Through Computing Display the Triangle fill(x,y,’y’)

Insight Through Computing Compute the Centroid xc = (x(1) + x(2) + x(3))/3; yc = (x(1) + y(2) + y(3))/3; The x coordinate of the centroid is the average of the x-coordinates of the vertices. Ditto for y-coordinate.

Insight Through Computing Highlight the Vertices and Centroid plot(x,y,’ok’,xc,yc,’*k’)

Insight Through Computing Connect Each Vertex to the Centroid plot([xc x(1)],[yc y(1)]) plot([xc x(2)],[yc y(2)]) plot([xc x(3)],[yc y(3)])

Insight Through Computing Overall [x,y] = ginput(3) fill(x,y,’y’) xc = (x(1)+x(2)+x(3))/3; yc = (y(1)+y(2)+y(3))/3; plot(x,y,’ok’,xc,yc,’*k’) plot([xc x(1)],[yc y(1)]) plot([xc x(2)],[yc y(2)]) plot([xc x(3)],[yc y(3)])

Insight Through Computing More General n = 3; [x,y] = ginput(n) fill(x,y,’y’) xc = sum(x)/n; yc = sum(y)/n; plot(x,y,’ok’,xc,yc,’*k’) for k=1:n plot([xc x(k)],[yc y(k)]) end

Insight Through Computing Question Time What is the output? x = [ ]; y = [3 1 2] k = y(3)-1; z = x(k+1) A. 11 B. 20 C. 21 D. 30 E. 31

Insight Through Computing A Problem Plot the function y = sin(x) across [0,2pi] but add random noise if In particular, use sin(x)+.1*randn(1) if x is in this range.

Insight Through Computing Solution x = linspace(0,2*pi,n); y = sin(x); for k=1:n if 2*pi/3 <= x(k) && x(k) <= 4*pi/3 y(k) = y(k) +.1*randn(1); end plot(x,y) axis([0 2*pi ]) x range:[0 2pi] y range: [ ]

Insight Through Computing

Problem On a black background, click in the location of 10 stars. (A “constellation”.) Repeat many times: for k=1:10 Redraw the k-th star using black or yellow with equal probability end This box redraws the constellation.

Insight Through Computing To Simulate Twinkling… [x,y] = ginput(10); for k = 1:100 for j=1:10 if rand <.5 DrawStar(x(j),y(j),r,'k') else DrawStar(x(j),y(j),r,'y') end pause(.01) end

Insight Through Computing Subscripting Review for j=1:3 DrawStar(a(j),b(j),.1,’y’) end DrawStar(3,2,.1,’y’) a:a: b: j=1

Insight Through Computing Subscripting Review for j=1:3 DrawStar(a(j),b(j),.1,’y’) end DrawStar(1,8,.1,’y’) a:a: b: j=2

Insight Through Computing Subscripting Review for j=1:3 DrawStar(a(j),b(j),.1,’y’) end DrawStar(7,4,.1,’y’) a:a: b: j=3