Skip to content

Using Rotation

Gökdeniz edited this page Dec 30, 2018 · 2 revisions

Rotating Object

I believe it is easy to understand it from this example:

create an image with width 256 and height 256 with background color black

create new image text with id "test" with content "0 degree"
set size of "test" to 30
set font of "test" to "Comic Sans MS"
set {_textWidth} to width of "test"
set {_textHeight} to height of "test"

write image text with id "test" on the image at location (128 - {_textWidth} / 2), (128 - {_textHeight} / 2)

set content of "test" to "20 degree"
write image text with id "test" on the image at location (128 - {_textWidth} / 2), (128 - {_textHeight} / 2) with rotation 20 degree angle

set content of "test" to "90 degree"
write image text with id "test" on the image at location (128 - {_textWidth} / 2), (128 - {_textHeight} / 2) with rotation 90 degree angle

set content of "test" to "-45 degree"
write image text with id "test" on the image at location (128 - {_textWidth} / 2), (128 - {_textHeight} / 2) with rotation -45 degree angle

Preview

PNG

GIF

Rotating Object with a specified Origin Location

1 - Lets firstly make an image and select our origin location.

create an image with width 512 and height 512 with background color black

draw circle with radius 5 and color light green on the image at location 256, 256
Preview

2 - Now, lets draw what we want to be rotated around the green dot

At the distance we want from the dot

create an image with width 512 and height 512 with background color black
draw circle with radius 5 and color light green on the image at location 256, 256

create new image text with id "test" with content "imagesk"
set size of "test" to 30
set font of "test" to "Comic Sans MS"
set {_textWidth} to width of "test"
set {_textHeight} to height of "test"

write image text with id "test" on the image at location 300, (256 - {_textHeight}) - 10

draw line with width 10 on the image from location 300, 256 to (300 + {_textWidth}), 256
Preview

3 - Okay so it is the time to rotate our drawing around the green dot

Actually we will not rotate it only one time, we will loop the 0, 45, 90, 135, 180, 225, 270 and 315 angles, rotate it using the angle, draw it.

create an image with width 512 and height 512 with background color black
draw circle with radius 5 and color light green on the image at location 256, 256

create new image text with id "test" with content "imagesk"
set size of "test" to 30
set font of "test" to "Comic Sans MS"
set {_textWidth} to width of "test"
set {_textHeight} to height of "test"

loop 0, 45, 90, 135, 180, 225, 270 and 315:
    write image text with id "test" on the image at location 300, (256 - {_textHeight}) - 10 with rotation loop-number degree using origin location 256, 256 
    draw line with width 10 with rotation loop-number degree using origin location 256, 256 on the image from location 300, 256 to (300 + {_textWidth}), 256

(we used location of the green dot as the origin location)

It is done!