Hi everyone
I have read some where at RevOnline that coding can be done for making graphics. i.e we can make graphics of our desired shape and size by writing the script. And now I am unable to find that downloaded material which I saw at RevOnline. Can anyone please tell me is their really a way of making our own graphics through coding giving it suitable shape size and desired properties.
Surbhit
Making graphics from coding
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Making graphics from coding
Hi
Hi v,
Maybe this script help
Best regards
Jean-Marc
Hi v,
Maybe this script help
Code: Select all
on CreateNewPolygon
put the points of grc "MyGrcSource" into tPoints -- or what you want like list of points
lock screen
new grc
set the style of last grc to polygon
set the name of last grc to "MyGrc"
set the points of grc "MyGrc" to tPoints
set the topleft of last grc to 10,10
end CreateNewPolygon
Jean-Marc
https://alternatic.ch
-
- VIP Livecode Opensource Backer
- Posts: 4003
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Making graphics from coding
As Jean-Marc points out a polygon graphic is made up of a list of points. You can see this easily if you make a polygon graphic and then look at it in the properties inspector. On the bottom you can see the list of points that make up the graphic. Now you can set these points by code. You have to calculate the points yourself but the graphic changes according to your points. You can also edit the points you see in the properties inspector: just add a line with an x and y coordinate and click outside of the points field to see what changes.
You can also tweak an existing polygon graphic by selecting the graphic and choosing in the Object menu -> reshape graphic. This will show the points the graphic is made of and you can drag the points to give the graphic a different shape. You can not however add points to the graphic this way.
Since you were interested in moving and turning a graphic at the same time I made a little stack that uses another feature of polygon graphics. Instead of setting the points of a graphic I use the relativePoints of a graphic -> dicitionary. I make a polygon graphic manually with about the shape I want then I manually tweak the graphic by using the reshape function described above.
Now in a button I use revRotatePolygon to rotate the graphic in 15 degree increments. After each increment I store the relativePoints of the graphic in a custom property of the graphic. The naming of the custom properties is u0, u15, u30 and so on. If I want to rotate the polygon say by 45 degrees I set the relativePoints of the graphic to the u45 of the graphic. Since I made all the relative points of the graphic by starting each time from the non-rotated state I have little degradation of the graphic and that will not increase the longer I rotate the graphic. (see Malte's comment on that).
As a little bonus I let the graphic turn clock wise if it is moved to the right and counterclockwise if it is moved to the left. The movement is constrained to the rect of the card on the fly.
Have a look at the scripts of the stack and follow the instructions how to tweak the graphic and get the custom properties of the newly shaped graphic attached to the graphic. See box in stack.
Kind regards
Bernd
You can also tweak an existing polygon graphic by selecting the graphic and choosing in the Object menu -> reshape graphic. This will show the points the graphic is made of and you can drag the points to give the graphic a different shape. You can not however add points to the graphic this way.
Since you were interested in moving and turning a graphic at the same time I made a little stack that uses another feature of polygon graphics. Instead of setting the points of a graphic I use the relativePoints of a graphic -> dicitionary. I make a polygon graphic manually with about the shape I want then I manually tweak the graphic by using the reshape function described above.
Now in a button I use revRotatePolygon to rotate the graphic in 15 degree increments. After each increment I store the relativePoints of the graphic in a custom property of the graphic. The naming of the custom properties is u0, u15, u30 and so on. If I want to rotate the polygon say by 45 degrees I set the relativePoints of the graphic to the u45 of the graphic. Since I made all the relative points of the graphic by starting each time from the non-rotated state I have little degradation of the graphic and that will not increase the longer I rotate the graphic. (see Malte's comment on that).
As a little bonus I let the graphic turn clock wise if it is moved to the right and counterclockwise if it is moved to the left. The movement is constrained to the rect of the card on the fly.
Have a look at the scripts of the stack and follow the instructions how to tweak the graphic and get the custom properties of the newly shaped graphic attached to the graphic. See box in stack.
Kind regards
Bernd
-
- VIP Livecode Opensource Backer
- Posts: 4003
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Making graphics from coding
the stack rotatePolygon was inadvertendly posted in 5.5 Livcode format.
I added a version in 2.7 format for Livecode versions prior to 5.5.
Kind regards
Bernd
I added a version in 2.7 format for Livecode versions prior to 5.5.
Kind regards
Bernd
Re: Making graphics from coding
Thnx a lot Bernd,
That helped a lot...
Surbhit
That helped a lot...
Surbhit