# Rotating Graphics

Jim Hurley jhurley at infostations.com
Fri Mar 5 11:20:07 CST 2004

```>
>Message: 3
>Date: Fri, 5 Mar 2004 11:28:48 -0500
>From: "Springer, Paul" <paul.springer at sensis.com>
>Subject: RE: Rotating Graphics
>To: 'How to use Revolution' <use-revolution at lists.runrev.com>
>Message-ID:
>	<ADF6087CA978A4418AF7F76DDCF2F72104C07E28 at europa.ats.sensis.com>
>Content-Type: text/plain
>
>Dar,
>
>Thanks for the help. As a beginner with RR, I need a little clarification.
>
>1. When you say "Rotate that." Do you mean with a built in command or with a
>custom command that is re-calculating where the points should be?
>
>2. Aren't there points already defined for the polygons vertices? Do I need
>to somehow use my custom properties instead of those?
>
>-Paul
>

Hi Paul,

This is tricky stuff in the beginning.

What follows is a variation on something developed by the list. It
avoids the rounding errors you have encountered, following Dar
Scott's suggestion, by using a set of custom properties.

There are two components, setAngle and rotatePoly. The latter just
sets the angle to the existing angle plus the degree of rotation.

You can script the construction of the custom properties, for example

set the defaultPoints of grc "myPoly" to the points of grc "myPoly"
set the pivotPoint of grc "myPoly" to line 1 of the points of
graphic "myPoly"
set the theAngle of grc "myPoly" to 0

On mouseUP
--Rotate a polygon 8 times by an angle of 45 about a pivot point
repeat 8
rotatePoly "myPoly", 45
wait 20 ticks --Slow it down so you can see it.
end repeat
end mouseUP

On setAngle tGraphic, tAngle
--Uses three custom properties of the polygon
--1) A default angle called "theAngle" used to define the initial orientation
--2) A set of default points used to define the initial shape:
"defaultPoints"
--3) A pivot point "pivotPoint"

set the theAngle of grc tGraphic to tAngle
put the defaultPoints of graphic tGraphic into tPoints
put the pivotPoint of grc tGraphic into tPivot
put item 1 of tPivot into xPivot
put item 2 of tPivot into yPivot

put empty into newPointList

put sin(tAngle* pi/180) into S
put cos(tAngle * pi/180) into C

--Set points relative to pivot

repeat for each line tLine in tPoints
put (item 1 of tLine)- xPivot into theX
put (item 2 of tLine)- yPivot into theY
put round(C*theX+ S*theY + xPivot)& comma after rotPtlist
put round(-S*theX + C*theY+  yPivot)after rotPtlist
put return after rotPtList
end repeat
set the points of graphic tGraphic to rotPtlist
end setAngle

on rotatePoly tGraphic, tChange
put the theAngle of grc tGraphic into tAngle
setAngle tGraphic, tAngle+tChange
end rotatePoly
```

More information about the use-livecode mailing list