Scale + noFill not working ?

I'm trying to use scale and I'm puzzle by the result of the following code:

void setup()
{
  size(1000, 600);
  noLoop();
}

void draw()
{
  scale(width/2, height/4);
  noFill();
  rect(0,0,1,1);
}

I'm expecting a unfilled rectange taking half the width and quarter the height but I'm seeing a filled rectange with strange boundaries.

Is there any reason or is this a bug ? The same happens with shapes.

Answers

  • Scale values are specified as decimal percentages. For example, the function call scale(2.0) increases the dimension of a shape by 200%.

  • I understand that, it is exactly why I don't understand what is going on in the above example

  • edited January 2017
    size(1000, 600);
    noLoop();
    smooth(4);
    
    rectMode(CENTER);
    noFill();
    stroke(0);
    
    background(0350);
    translate(width>>1, height>>1);
    scale(width>>1, height>>2);
    
    rect(0, 0, 1, 1);
    //point(0, 0);
    
  • edited January 2017 Answer ✓

    @marc_nostromo --

    If you comment out your call to scale() you will see that you have drawn a 1x1 pixel rect -- it has no fill, but the default stroke is black, so the result is a black dot in the upper-left corner of your sketch. You use scale() to zoom in on that black dot with width of x500 and a height of x150. The zoomed in and distorted shape of that single pixel becomes a very big rectangle on the screen.

    Here is a simple sketch to show you this happening -- it zooms in x1, x2, x3, x4 etc. as the frameCount increases. When the count becomes higher than x400 (after about seven seconds) that 1 pixel rectangle will 400 pixels wide and will fill the sketch area.

    void setup()
    {
      size(400, 400);
    }
    
    void draw()
    {
      background(255);
      scale(frameCount);
      noFill();
      rect(0,0,1,1);
    }
    

    To better understand how scale() works and why, check the reference page and read the Processing "Coordinate System and Shapes" tutorial for background:

    Regarding:

    I'm expecting a unfilled rectangle taking half the width and quarter the height

    ...the easiest way to do this is:

    rect(0,0,width/2,height/4);
    
  • edited January 2017

    Haa... I get it. So I'm basically stroking with a huge pen. That make sense, thanks

Sign In or Register to comment.