Try to guess what the instructions would be for the following image.
Example
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Exercise 1-4: Try to guess what the instructions would be for the following screenshot.

size(200,200);
background(255);
stroke(0);
fill(0);
rect(0,0,100,100);
fill(150);
rect(100,100,100,100);

2 Comments

»

  1. I understand the dimension parameters for the upper left square (rect), but it seems like the lower right should be:

    rect(100, 100, 200, 200);

    I know I’m wrong because I loaded the code and it draws exactly as you have laid it out:

    rect(100,100,100,100);

    What did I miss?

    Best Regards

    Comment by Joel Wright — February 2, 2009 @ 8:51 am

  2. The rectangle is defined by:

    (top left x, top left y, width, height)

    your code would be correct if you used rectMode(CORNERS), which would define the rectangle by

    (top left x, top left y, bottom right x, bottom right y)

    For more: http://www.processing.org/reference/rectMode_.html

    Comment by admin — February 3, 2009 @ 9:35 am

Leave a comment