How Do you change the rotational origin for a shape?

please format code with </> button * homework policy * asking questions

Hello, I am learning processing through this intro course and we have an assignment where we need to make a triangle that spins and follows your mouse. I have figured all of the code except, because rotate() operates around the origin which I have set at translate (mouseX, mouseY), it rotates around a vertices. I need to have the rotational origin on the side of the shape.

Here is my code, I have done so much research for the past 5 hours and I have finally decided to ask for help. I have no idea ho to fix this problem.

angle = 0

def setup ():
size (600, 600)

def draw ():
background (0)
global angle

translate (mouseX , mouseY)
rotate (radians (angle))
fill(255)
beginShape ()
vertex(-50, 50)
vertex (50, 50)
vertex (0, 0)
endShape ()


angle += 0.5
2 Likes

After rotate make a 2nd translate that is with -50,0

1 Like

Hello,

Consider centering the shape.
You have an x and y in your vertices and you can add an offset to these to center it.

I only centered the 0, 0 on the canvas so you could visualize the point of rotation:

angle = 0

def setup():
    size(200, 200);

def draw ():
    background (0)
    global angle
    
    translate (width/2, height/2) #0,0 is now center of canvas
    rotate (radians (angle))
    fill(255)
    beginShape ()
    vertex(-50, 50)
    vertex (50, 50)
    vertex (0, 0)
    endShape ()

    angle += 0.5

This is not the correct axis or value but a place to start.
It will work with the correct values; @Learner I will leave this with you to explore.

Some resources here:

``:)‘’

3 Likes

Hey! Thanks so much. I was able to figure it out! Your guy’s help is very much appreciated.

3 Likes