Page 1 of 1

rotating SVG images

Posted: Tue Dec 06, 2016 11:49 am
by richmond62
I have been messing around with Scratch . . .

I notice that all the pre-supplied 'sprites' are SVG files . . .

Within Scratch these SVG images can be rotated any which way one wants with no visible deterioration at all.

As the only ways one can import a vector image into LiveCode is either via the SVG widget or
by setting the points of a graphic object to the points of an SVG image there seems to be
NO way one can rotate them.
scritch.png
Vector "sprite" in Scratch.
scritch.png (47.85 KiB) Viewed 3727 times

Re: rotating SVG images

Posted: Tue Dec 06, 2016 2:49 pm
by [-hh]
For rotating the points of a polygon in LC Script use the following.

Code: Select all

-- b is the angle of rotation in degrees (positive b turns clockwise, negative b turns ccw)
-- pts are the points of a polygon and (x0,y0) is the center of rotation
function hhRotateTo b,pts,x0,y0
   put sin(pi*b/180) into s; put cos(pi*b/180) into c
   repeat for each line L in pts
      if L is empty then put cr after pts2
      else
         put -x0 + item 1 of L into sx; put -y0 + item 2 of L into sy
         put cr & ( (statRound(x0+c*sx-s*sy),statRound(y0+c*sy+s*sx)) ) after pts2
      end if
   end repeat
   return char 2 to -1 of pts2
end hhRotateTo
For rotating a deliberate imported SVG use in LC Builder
(there are several lcb files that show how to "prepare" for rotation)

Code: Select all

rotate this canvas by <angle>   OR   rotate <path> by <angle>

Re: rotating SVG images

Posted: Tue Dec 06, 2016 8:16 pm
by richmond62
Thank you.

Although, compared with rotating PNG, GIF and JPG images this does seem a bit complicated.