Several dynamics in one drawing

edited October 2013 in How To...

Hello, I'm quite new to Processing and I've been exercising alot. But there's one that I just can't find. However I know it's simple, I just can't solve it. Believe it or not but I've been searching for over 2weeks to complete this one, I would be eternally grateful for the one helping me out with this. Exercise says that I have to be able to set the following as dynamic:

  • size of the application window
  • thickness of the strokes/lines
  • color of each field
  • Position of the rect in the middle
  • Size of the rect in the middle
  • Distance between the big rect and the edge of the application window.

So the rect should fit perfectly in the middle of the window every time, even if i change the size, etc

Picture of what I mean: TinyPic

Anyone that could help me out? I'm probably not far from finding it but if i see the code I can sure find what I did wrong.

Regards -Ben

Answers

  • Dunno much either. But this should get ya started: :-\"

    // forum.processing.org/two/discussion/402/
    // several-dynamics-in-one-drawing
    
    void setup() {
      size(200, 200);
      frameRate(10);
      smooth();
      rectMode(CENTER);
    
      frame.setResizable(true);
    }
    
    void draw() {
      background(0);
      rect(width>>1, height>>1, width*.75, height*.75);
    }
    
  • edited October 2013

    Hmm, still no clue.. It's almost something like this:

    size(500,500);
    background(#000000);
    
    int afstand = 50;
    int rectSize= 200;
    
    stroke(#FFFFFF);
    fill(#000000);
    rect(width-afstand,afstand,-rectSize,rectSize); // uppersquare
    rect(afstand,height-afstand,rectSize,-rectSize); // bottomsquare
    
    stroke(#FFFFFF);
    
    line(width-afstand-rectSize,afstand,afstand,height-afstand-rectSize);
    line(width-afstand,afstand,afstand+rectSize,height-afstand-rectSize);
    line(afstand,height-afstand,width-afstand-rectSize,afstand+rectSize);
    line(afstand+rectSize,height-afstand,width-afstand,afstand+rectSize);
    

    Still tho, no clue how to do the one I posted before, anyone?=/

  • Perhaps you can use vertex() to make colored closed shapes?

  • void setup(){
      size(500,500);
      smooth();
      background(0);
      one();
      noLoop();
    }
    
    void draw(){}
    
    void one(){
      float w=random(20,200);
      float h=random(20,200);
      float x=random(width-w);
      float y=random(height-h);
      float iw=random(5,20);
      float ih=random(5,20);
      float ix=random(x,x+w-iw);
      float iy=random(y,y+h-ih);
      stroke(random(255),random(255),random(255));
      //strokeWeight(int(random(5)));
      strokeWeight(1);
      rfill();
      rect(ix,iy,iw,ih);
      rfill();
      quad(x,y,x+w,y,ix+iw,iy,ix,iy);
      rfill();
      quad(x,y,x,y+h,ix,iy+ih,ix,iy);
      rfill();
      quad(x+w,y,x+w,y+h,ix+iw,iy+ih,ix+iw,iy);
      rfill();
      quad(ix,iy+ih,ix+iw,iy+ih,x+w,y+h,x,y+h);
    }
    
    void rfill(){
      fill(random(255),random(255),random(255));
    }
    
  • edited October 2013

    Exercise says that I have to be able to set the following as dynamic

    Imho the objective of this excercise is to teach student to separate data and drawing. So by "dynamic" they mean that student shouldn't hard-code numbers into code as magic constants, but isntead should have them declared as variables. I don't think they meant "randomly assigned numbers" as you can't really dynamically change sketch screen size in runtime. :)

  • Thanks !

    With some more trial & errorin' with your sketch I found what my mistakes were. Appreciated alot sir!

    Regards -Ben

  • And yes, everything shouldn't have been random. But as I said with some longer research in his sketch I finally found my mistakes ;-) Thanks for the replies.

Sign In or Register to comment.