• fullscreen
  • _1113_TansyMak.pde
  • // Created by Tansy Mak
    // Arch 6509 Beyond Measurement: Generative Modeling in Architecture and Urbanism
    // Department of Architecture, AAP, Cornell University
    
    //number of blocks in the x-direction
    int numXBlock = 7;
    //number of blocks in the y-direction
    int numYBlock = 8;
    //pixel spacing between the blocks
    int spacing = 7;
    //the starting suffix to the filename for the image saved at keypress
    int saveSuffix = 1;
    
    void setup() {
      size(400, 800);
      stroke(255);
      strokeWeight(spacing);
      fill(0);
      float horDist =width/numXBlock;
      float verDist = height/numYBlock;
      for (int i = 0; i < numXBlock; i++)
      {
        for (int j = 0; j < numYBlock; j++)
        {
          rect((i*horDist), (j*verDist), horDist, verDist);
        }
      }
    }
    
    void draw() {
    }
    
    //Acts if mouse is pressed, depending on which button and how many times
    void mousePressed() {
      strokeWeight(1);
      float xBlock = width/numXBlock;
      float yBlock = height/numYBlock;
    
      //Draw the white block divisions on single click.
      if (mouseEvent.getClickCount()==1) drawDiv(xBlock, yBlock);
      //Draw new black block on double click.
      if (mouseEvent.getClickCount()==2) drawWhiteBlock(xBlock, yBlock);
      //Draw white block if right clicked.
      if (mouseEvent.getButton()==MouseEvent.BUTTON3) drawBlackBlock(xBlock, yBlock);
    }
    
    //Draws the divisions within the blocks
    void drawDiv(float xBlock, float yBlock) {
      strokeWeight(spacing);
      stroke(255, 255, 255);
      line(mouseX, mouseY, ((floor(mouseX/xBlock))*xBlock)+(spacing/2), mouseY);
      line(mouseX, mouseY, ((ceil(mouseX/xBlock))*xBlock)-(spacing/2), mouseY);
      line(mouseX, mouseY, mouseX, (floor(mouseY/yBlock)*yBlock)+(spacing/2));
      line(mouseX, mouseY, mouseX, (ceil(mouseY/yBlock)*yBlock)-(spacing/2));
    }
    
    //Draws a white block, creating a "void"
    void drawWhiteBlock(float xBlock, float yBlock) {
      fill(255, 255, 255);
      rect((floor(mouseX/xBlock)*xBlock)+(spacing/2), (floor(mouseY/yBlock)*yBlock)+(spacing/2), xBlock-spacing, yBlock-spacing);
    }
    
    //Draws a black block to erase the previous divisions
    void drawBlackBlock(float xBlock, float yBlock) {
      noStroke();
      fill(0);
      rect((floor(mouseX/xBlock)*xBlock)+(spacing/2)+1, (floor(mouseY/yBlock)*yBlock)+(spacing/2)+1, xBlock-(spacing), yBlock-(spacing));
    }
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Tien Ling

    Urban Divisions by Tansy Mak

    Add to Faves Me Likey@! 3
    You must login/register to add this sketch to your favorites.

    Created by Tansy Mak

    Expand the window for full display

    Urban Divisions allows the user to interact with a rectangular grid (with customizable size and spacing) through single-click, double-click, and right-click.

    Functions
    single-click = draw new block divisions
    double-click = remove block
    right-click = revert to original block

    //Draw the white block divisions on single click.
    if (mouseEvent.getClickCount()==1) drawDiv(xBlock, yBlock);
    //Draw new black block on double click.
    if (mouseEvent.getClickCount()==2) drawWhiteBlock(xBlock, yBlock);
    //Draw white block if right clicked.
    if (mouseEvent.getButton()==MouseEvent.BUTTON3) drawBlackBlock(xBlock, yBlock);

    that code doesn't work for me on Processing 1.5.1

    I tried this:

    size(200, 200);

    stroke(0);

    void mousePressed()
    {
    //Draw the white block divisions on single click.
    if (mouseEvent.getClickCount()==1) rect (10, 10, 10, 10);
    //Draw new black block on double click.
    if (mouseEvent.getClickCount()==2) ellipse(50, 50, 50, 50);
    //Draw white block if right clicked.
    if (mouseEvent.getButton()==MouseEvent.BUTTON3) line(100, 100, 50, 50);
    }

    and when I run it I get an error message: "It looks like you're mixing 'active' and 'static' modes." Do you have some tip?

    thanks in advance.
    Tien Ling
    8 Aug 2012
    this should work:

    ===============

    void setup() {
    size(200, 200);
    stroke(0);
    };

    void draw() {
    };

    void mousePressed()
    {
    //Draw the white block divisions on single click.
    if (mouseEvent.getClickCount()==1) rect (10, 10, 10, 10);
    //Draw new black block on double click.
    if (mouseEvent.getClickCount()==2) ellipse(50, 50, 50, 50);
    //Draw white block if right clicked.
    if (mouseEvent.getButton()==MouseEvent.BUTTON3) line(100, 100, 50, 50);
    }

    ===========

    whenever you see this warning message: "mixing 'active' and 'static' modes", check your "setup" and "draw" structure and you should be able to fix it. cheers.
    Hi Tien,

    Sorry it was my mistake :x Full working code:

    void mousePressed()
    {
    if (mouseButton == LEFT) //1 click mouse button left
    {
    if (mouseEvent.getClickCount()==2) //2 clicks mouse button left
    {
    ellipse(50, 20, 20, 20);
    ellipse(60, 60, 60, 60);
    println("double-click");
    }
    else
    {
    println("left-click");
    rect(10, 10, 10, 10);
    }
    }
    else if (mouseButton == RIGHT) //1 click mouse button right
    {
    rect(100, 100, 20, 20);
    println("right-click");
    sharings[chosenSharing].close(); //stop the plaback of the sharing
    }
    }
    You need to login/register to comment.