Come vedete i due triangoli ruotano attorno allo stesso punto. Per fare ciò dobbiamo, ad ogni rotazione, individuare la posizione degli oggetti che non ruotano al proprio baricentro; cioè nel nostro caso il secondo triangolo.
La posizione è data dalle funzioni trigonometriche seno e coseno. Esse ci danno i coefficienti rispetto all'angolo corrente, da dare alla posizione dell'oggetto.
Se il centro di rotazione si trova in (152,118) e il secondo triangolo di deve sempre trovare a 100 pixel dal centro, il codice nel pulsante è:
on mouseUp if the label of me is "START" then set the label of me to "STOP" ruotafigura else set the label of me to "START" end if end mouseUp
on ruotafigura if the label of me is "START" then exit ruotafigura end if put the thumbpos of scrollbar "angolo" into Dangolo lock screen put the angle of graphic 1 into curangolo put dangolo + curangolo into curangolo set the angle of graphic 1 to curangolo set the angle of graphic 2 to curangolo #loc = 152,118 #w x h = 100,100 set the loc of graphic 2 to (152 + 100 * cos(pi/180 * curangolo), 118 + 100 * sin(pi/180 * curangolo) ) unlock screen send ruotafigura to me in 0.017 sec #non ha senso scendere sotto questo valoreend ruotafigura
Nessun commento:
Posta un commento