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

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

Loop Structures

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

View Full Document
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
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?

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

View Full Document
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) ?
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 ?

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

View Full Document
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;
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

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

View Full Document
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
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online