matlab3 - Loop Structures PutPixel function Some of our...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Loop Structures
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
PutPixel function Some of our examples will use the function putPixel, that turns on the pixel at location (x,y) In java, the origin is located at top left corner, and y-coordinate values increase as you go down, making all coordinates on the screen have positive components Refer to www.bilkent.edu.tr/~ccelik/cs111/java_draw for more details
Background image of page 2
Draw a Line initWindow; putPixel(10,10,g); putPixel(11, 10, g); putPixel(12, 10 , g); putPixel(13, 10 , g); putPixel(14, 10 , g); putPixel(15, 10 , g); putPixel(16, 10 , g); putPixel(17, 10 , g); putPixel(18, 10 , g ); putPixel(19, 10 , g ); putPixel(20, 10 , g ); What if we need a line with length 200?
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Draw a line of 200 pixels Maybe we need a new type of statement that will repeat things for a specified amount of times. Here is an attempt (in pseudo-code): 200 times do putPixel(?, 10) ?
Background image of page 4
Draw a line of 200 pixels (2) We need to change the x coordinate at each iteration. Otherwise we keep putting the pixels at the same location. How do we vary the x coordinate at each iteration ?
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Draw a line of 200 pixels (3) vary variable Let’s use a variable currentX that will pull the window under the sewing machine needle currentX=10; 200 times do putPixel(currentX, 10); currentX = currentX + 1;
Background image of page 6
Draw a line What if the user wants to specify the length of the line? Our loop (repetition) statement should be flexible enough to provide varying number of iterations : get the length of the line from user currentX = 10 for length times do putPixel(currentX, 10) currentX = currentX + 1
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Mines? Let’s say that our drawing board has some “mines” on it. Our line explodes, or ends, when it hits a mine. We can ask if a particular pixel location has
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 31

matlab3 - Loop Structures PutPixel function Some of our...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online