1 / 14

Lecture 6: Supplementary material For your own interest

COMP1610/DGC1330. Lecture 6: Supplementary material For your own interest. Looping. More complex example – Nested FOR Loop. size(450,450); smooth(); strokeWeight(5); for ( int j=0 ; j<10 ; j=j+1 ) { for ( int i=0 ; i<10 ; i=i+1 ) {

Download Presentation

Lecture 6: Supplementary material For your own interest

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMP1610/DGC1330 Lecture 6: Supplementary material For your own interest

  2. Looping More complex example – Nested FOR Loop size(450,450); smooth(); strokeWeight(5); for ( int j=0 ; j<10 ; j=j+1 ) { for ( int i=0 ; i<10 ; i=i+1 ) { ellipse ( i*50 , j*50 , 50 , 50); } }

  3. Looping Let’s see step by step for ( int j=0 ; j<10 ; j=j+1 ) { for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50 , j*50 , 50 , 50); } }

  4. Looping Let’s see step by step

  5. Looping Let’s see step by step

  6. Looping Let’s see step by step

  7. Looping One FOR Loop: for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); }

  8. Looping X10 for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 450,50,50); } X10 X10

  9. Looping So, for ( intj=0 ; j<10 ; j=j+1 ) { } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50 , j*50 , 50 , 50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 100,50,50); } for ( inti=0 ; i<10 ; i=i+1 ) { ellipse ( i*50, 450,50,50); } X10

  10. Looping + Random Another example: Now, we use these five squares to tile the following graphic randomly.

  11. Looping + Random How can we do that? • Looping • Loop to tile squares horizontally and vertically. • Random • Choose one color each time to tile.

  12. Looping + Random • Let’s see how to do it: • First load five images: • img1, img2, img3, img4, img5 • Then start to tile the image: for (int x=50 ; x<600 ; x+=50) { for (int y=50 ; y<600 ; y+=50) {

  13. Looping + Random • Randomly choose one image: • Tile that image: int ran = round(random(1, 5)); if (ran == 1) { image(img1, x, y); } if (ran == 2) { image(img2, x, y); } if (ran == 3) { image(img3, x, y); } if (ran == 4) { image(img4, x, y); } if (ran == 5) { image(img5, x, y); }

  14. The end.

More Related