CHAPTER 11

Conditionals


Whereas loops serve the graphic purpose of repeating instances of graphic elements in uniform patterns, conditionals allow us to break the uniformity of a pattern where appropriate, in order to adjust or inflect parts of a composition to respond to special conditions.

- Conditional Choices among Many Design Alternatives:

11.15 Stairs

prog11_15.png

  1. void setup(){
  2. size(800,600);
  3. }
  4.  
  5. void draw(){
  6.  
  7. int x_initial = 25;
  8. int y_initial = 180;
  9. int depth = 50;
  10. int width1 = 5;
  11.  
  12. int x_increment = 10;
  13. int y_increment = 10;
  14. int num_of_stairs = 20;
  15. int n = 5;
  16.  
  17. int landing_depth = 2 * depth;
  18. int x = x_initial;
  19. int y = y_initial;
  20.  
  21. for(int count = 1; count <= num_of_stairs; count++){
  22. if(count % 2 == 0){
  23. rect(x,y,landing_depth,width1);
  24. x = x + depth;
  25. }else{
  26. rect(x,y,depth,width1);
  27. }
  28.  
  29. x = x + x_increment;
  30. y = y + y_increment;
  31. }
  32. }

Comments

Leave a Reply



(Your email will not be publicly displayed.)


Captcha Code

Click the image to see another captcha.