rotating SVG images

Want to talk about something that isn't covered by another category?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10433
Joined: Fri Feb 19, 2010 10:17 am

rotating SVG images

Post 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.
Vector "sprite" in Scratch.
Vector "sprite" in Scratch.
scritch.png (47.85 KiB) Viewed 4359 times
[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: rotating SVG images

Post 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>
shiftLock happens
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10433
Joined: Fri Feb 19, 2010 10:17 am

Re: rotating SVG images

Post by richmond62 »

Thank you.

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