Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Rotate function

in Questions Posts: 8

Anyone knows how i can rotate an object starting from its x,y position without moving it like with the rotate function?

Comments

  • dave1707dave1707 Mod
    Posts: 6,230

    @Drea I've read that several times, but I still don't know what you want to do. Can you give more details on what you mean.

  • Posts: 8

    I mean like the clock hands, they rotate on a single point

  • dave1707dave1707 Mod
    Posts: 6,230

    Like this.

    function setup()
        a=0
    end
    
    function draw()
        background(40, 40, 50)
        a=a+1
        translate(300,300)
        rotate(a)
        sprite("Small World:Icon",0,0)    
    end
    
  • Posts: 8

    It works with that sprite, but for example if i wanted to create a line (350,250,350,500) and then rotate

  • Posts: 8

    Ops a part of my message was delated... i was saying and then rotate without changing the initial x and y positions, how should i do?

  • dave1707dave1707 Mod
    Posts: 6,230
    function setup()
        a=0
    end
    
    function draw()
        background(40, 40, 50)
        a=a+1
        translate(WIDTH/2,HEIGHT/2)
        rotate(a)
        stroke(255,0,0)
        strokeWidth(4)
        line(0,0,200,0)
    end
    
  • Posts: 8

    Yess, i also did something really similar but i didn't realize that it rotated starting from 0,0, that s why i couldn't do it right. Thank you so much dave!

  • dave1707dave1707 Mod
    edited July 25 Posts: 6,230

    Since you mentioned clock hands above, I thought I'd throw this in.

    function setup()
        a=0
        b=0
        fontSize(50)
    end
    
    function draw()
        background(40, 40, 50)    
        fill(223, 204, 170, 255)
        ellipse(WIDTH/2,HEIGHT/2,430)
        fill(255)
        text("12",WIDTH/2,HEIGHT/2+180)
        text("6",WIDTH/2,HEIGHT/2-180)
        text("3",WIDTH/2+180,HEIGHT/2)
        text("9",WIDTH/2-180,HEIGHT/2)    
        a=a-1
        pushMatrix()
        translate(WIDTH/2,HEIGHT/2)
        rotate(a)
        stroke(255,0,0)
        strokeWidth(6)
        line(0,0,0,200)
        popMatrix()    
        pushMatrix()
        translate(WIDTH/2,HEIGHT/2)
        rotate(a/12)
        strokeWidth(12)
        line(0,0,0,120)
        popMatrix()
        noStroke()
        fill(255)
        ellipse(WIDTH/2,HEIGHT/2,30)    
        noFill()
        stroke(0, 56, 255, 255)
        strokeWidth(8)
        ellipse(WIDTH/2,HEIGHT/2,430)
    end
    
  • Posts: 8

    Nice job man

Sign In or Register to comment.