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.
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