[RESOLVED] mouseX Position as Degrees to Rotate the drawing

I have an assignment due tomorrow and there is this one part where it says “Use the mouse’s horizontal position as the amount of degrees to rotate the hero”.

(Edit) I’m uploading the complete code cause I realized just this part doens’t work
(Edit2) I deleted the code cause it’s solved now

I’m a beginner with processing and I got help from my classmate.
Any advice on what to do? The drawing is not following the mouse’s x position.

Without showing us the code for complete, running sketch, it is quite hard to tell what you are doing.

Here is some sample code that uses the mouse’s horizontal position as the number of degrees to rotate a shape:

void setup(){
  size(600,600);
  rectMode(CENTER);
  fill(0,200,0);
}

void draw(){
  background(0);
  
  pushMatrix();
  translate(mouseX,mouseY);
  rotate(radians(mouseX));
  fill(0,200,0);
  rect(0,0,40,40);
  popMatrix();
  
  fill(0,0,200);
  ellipse(30,30,40,40);
}

Please understand the concepts this presents - using translate(), using rotate(), using radians() to convert from degrees to radians, using pushMatrix() and popMatrix() to store and restore the coordinate system - and, once you understand the concepts, edit your own code to make use of them.

This is the running sketch, there are more parts but those are just the drawing codes.


    void setup()
    {
    size(640, 480);//app size
    rectMode(CENTER);//draw rectangles from their centers
    background(#E5F0C6);//bg color, light green
    }



//runs all the time
       
    void draw()
    {
    fc++;//increment to the next frame drawn
    background(#08FF26);//clears app canvas, bright green

    drawTileWingStripRotation();
    drawNightwing();
    pushMatrix();
  
    rotate(rotateAng);
    popMatrix();
    }


//////////LMB and RMB click rotation and reset

    void mousePressed();//previous code above post


    void mouseDragged();//the previous code in the above


    void drawTileWingStripRotation()
    {
     pushMatrix();//start isolating mem
  
  //TRANSFORMATIONS HAPPEN IN REVERSE
      
     translate(mouseX, mouseY);//rotation based on mouse position
     rotate(radians(fc * .7));//rotation
     translate(-1400, -1800);//move its center to the origin
  
  //drawing here
  

  //horizontal strip of tiles

     for(int i=0; i < 7; i++)
     {
      drawNightwingTile2DGrid();
     }
      popMatrix();//end isolating mem
    }



//draw a 2D grid of tiles

    void drawNightwingTile2DGrid()
    {
      //vertical component of the 2D grid
      for(int j=0; j < 28; j++)
    {
    //horizontal strip of tiles
    for(int i=0; i < 36; i++)
    {
      drawTile(i * 100, j * 100);
    }
  }
}


    void drawTile(int xxx, int yyy)
    {
      pushMatrix();//start isolating mem
  
      //TRANSFORMATIONS HAPPEN IN REVERSE
      translate(xxx, yyy);//move tile over by this amount
  
      //all drawing below here
      symbolTile();
      popMatrix();//done isolating mem
    }


    void symbolTile()
    {
        drawTile();
    }


//make nightwing invisible after top 3/4 of the application
//void nightwingOpacity()
{
 
 wingOp = 255;//
}


//draw nightwing figure

    void drawNightwing()
    {
        *where I have all the sketch drawing for figure*

     //make Nightwing appear only on 3/4 of the application
      if(mouseX > (width/1.27) || mouseY > (height/1.3))
     {
         wingOp = 0;//nightwing opacity is 0 = invisible
     }
     else
     {
      wingOp = 255;//nightwing opacity is 255 = visible
      }
  
     if (mouseY < 360)
     {
        pushMatrix();//isolate memory
    
        translate((Xpos + width/2), (Ypos + height/2));
        rotate(radians(mouseX));
        translate(-(Xpos + width/2), -(Ypos + height/2));
    
        popMatrix();//done isolating memory
      
       }
     }

It’s just the mouseX position as degree to rotate the hero drawing that’s not working

Hmm you could try

rotate(map(mouseX, 0, width, -PI / 2, PI / 2));

I tried the new code but the hero drawing doesn’t follow the mouse when I click it. Am I missing something?

Can you please format the code? Edit you comment, highlight you code and press </>. That way it is easier to read and copy the code.

On this forum we try not to do peoples homework for them, but it is of course okey to ask for guidance or help.

Are you familiar with the map() function? If not you can read about it the reference.

I’m not asking to do homework for me…I need guidance on x and connecting with figure rotation.

Once again, PLEASE POST A COMPLETE, RUNNING SKETCH.

I have TRIED to piece together your code, and all I can get running is a BLANK LIME GREEN SCREEN.

Do NOT reference code you have posted previously.

Do NOT break it up into sections or tabs.

ONE BLOCK. OF CODE. THAT RUNS.

P. L. E. A. S. E.

I got it working from a help from my classmate. Thank you all for the advice, I’ll keep it in mind for the future.