transitioning shapes

edited October 2016 in Questions about Code

I'm trying to use mouseClicked to make these arcs move to the top right corner and shrink in size. I momentarily had it, but lost it while trying to add something else haha.

    void setup(){
      fullScreen();

    }
    int x1 = 0;
    int x2 = 0;
    int y1 = 0;
    int y2 = 0;


    void draw(){  
     x1 = width/2;
     x2 = 600;
     y1 = height/2;
     y2 = 600;

       stroke(0);
      strokeWeight(5);
      fill(0);
      arc(x1, y1, x2, y2, PI, PI*3.25); //Arc1

  stroke(0);
      strokeWeight(5);
      fill(#FFF700);
      arc(x1, y1, x2, y2, PI*2.25, PI*2.75);//Arc2

 fill(#FF0000);
       stroke(0);
      strokeWeight(5);
      arc(x1, y1, x2, x2, PI*2.75, PI*3.25);//Arc3

stroke(0);
      strokeWeight(5);
      fill(#FFFFFF);
      arc(x1, y1, x2, y2, TWO_PI-PI/4, PI*2.25);//Arc4
    }

    void mouseclicked(){
        x1 = (width/3 + (width/3 + width/4));
      y1 = height/3;
      x2 = 80;
      y2 = 80;
    }

Answers

  • edited October 2016 Answer ✓

    mouseClicked

    ok, first, the in-build function is called mouseClicked(), not mouseclicked(). Big "C".

    Processing is case-sensitive.

    Because you had your spelling wrong, mouseclicked() was never executed.

    You can find out those things by guessing, and by putting a println("here 1"); into the function mouseclicked() or the code area you expect to be wrong.

    background

    Also, you might want to use background(0); at the beginning of draw(). Because otherwise, you have 2 shapes

    Best, Chrisir ;-)

  • Thank you again this was helpful.

  • I don't understand why my arc's start in the upper left corner? I am trying to have the arc's form a circle around the middle of the screen. The issue seems to be somewhere in how I declare my variables using width/2...What am I doing wrong?

        int l = width/2;
        int m = height/2;
        int n = 600;
        int o = 600;
    
    
     void setup(){
          fullScreen();
    
        }
    
    
        void draw(){  
          background(0,0,0);
    
           stroke(0);
          strokeWeight(5);
          fill(0);
          arc(l, m, n, o, PI, PI*3.25); //Arc1
    
      stroke(0);
    
          strokeWeight(5);
          fill(#FFF700);
          arc(l, m, n, o, PI*2.25, PI*2.75);//Arc2
    
     fill(#FF0000);
           stroke(0);
          strokeWeight(5);
          arc(l, m, n, o, PI*2.75, PI*3.25);//Arc3
    
    stroke(0);
          strokeWeight(5);
          fill(#FFFFFF);
          arc(l, m, n, o, TWO_PI-PI/4, PI*2.25);//Arc4
        }
    
        void mouseReleased(){
    
    
           if (n > 100) {
            l = (width/3 + (width/3 + width/4));
          m = height/3;
          n = 80;
          o = 80; }     
         else {
            l = width/2;
            m = height/2;
            n = 600;
            o = 600;
        }
    
    
    
    }
    
  • Answer ✓

    Line 1 and 2 don't work before setup

    Place at end of setup

  • edited October 2016 Answer ✓

    For an explanation of why global variables assigned to width/height don't work, and why these assignments need to be done in setup() after size() is called, see for example this description:

  • I am using the fullScreen(); for my size does this affect declaring my variable in setup? It doesn't seem to work. However I have found a way around it so I'm just wondering for the sake of knowing.

  • edited October 2016

    I guess fullscreen does internally the same as size

    only there width and height are defined

    so you can use them only after fullscreen or size

  • edited October 2016

    Right -- calling a screen-size-setting function (such as size() or fullscreen() will define width and height -- and then you can safely define other variables based on width and height, after they have been set.

  • edited October 2016

    btw ctrl-t in the processing editor will indent your code nicely.

Sign In or Register to comment.