basic draw line graphic
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
basic draw line graphic
Hi,
Does anyone know where I could find a simple tutorial about scripting graphic objects in Revolution? For example how can I draw a 1 pixel line from say point 10x 10y to 100x 100y ?
Many Thanks in advance.
Jim
Does anyone know where I could find a simple tutorial about scripting graphic objects in Revolution? For example how can I draw a 1 pixel line from say point 10x 10y to 100x 100y ?
Many Thanks in advance.
Jim
Re: basic draw line graphic
Code: Select all
local tPointsList --this will hold the list of coordinates, one per line
put "10,10" into tPointsList --the first coordinate
put cr & "100,100" after tPointsList --the next coordinate
create invisible graphic "myNewLine" --optionally invisible, but allows you to manipulate the properties before showing the line on screen
set the style of graphic "myNewLine" to "line" --you could set the style to polygon, etc instead
set the lineSize of graphic "myNewLine" to 1 --this is where the thickness of the line is specified (not border as I stated previously)
set the points of graphic "myNewLine" to tPointsList
set the antialiased of graphic "myNewLine" to true
set the visible of graphic "myNewLine" to true
Lines are graphic objects of style "line" - if you look in the property inspector and hover over the options you will see the transcript name of the property that can be manipulated by script. A graphic of style "line" has a "lineSize" of value 1 for a line thickness value of 1. Increase the lineSize value for a thicker line. Setting the antialiased to true will make it rather more defined too. There are plenty of other options you can set by script as well.
[edited to correct the definition of lineSize above]
Last edited by SparkOut on Tue Jul 22, 2008 8:51 am, edited 1 time in total.
re: basic draw line graphic
Thanks very much SparkOut that's just what I needed to get me started - totally clear and helpful.
Much obliged
Jim
Much obliged
Jim
basic draw line graphic
The problem with Rev graphics as I
find it is that if you want to show a number
of graphics you have to either create them with
unique names or clone with unique names.
When you get enough graphics (seems to
be around 2000) you can't see them in the
Property Inspector (gives an error) and the
scrpt won't compile into a standalone.
So you have to code to delete the graphics
after/before each use of the script.
Don't know if this is a problem with a
standalone (imagine not) or if there's some
way to avoid it.
find it is that if you want to show a number
of graphics you have to either create them with
unique names or clone with unique names.
When you get enough graphics (seems to
be around 2000) you can't see them in the
Property Inspector (gives an error) and the
scrpt won't compile into a standalone.
So you have to code to delete the graphics
after/before each use of the script.
Don't know if this is a problem with a
standalone (imagine not) or if there's some
way to avoid it.
Life is just a bowl of cherries.
-
- VIP Livecode Opensource Backer
- Posts: 10044
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
FWIW, if you have a lot of graphics which are lines or polygons and share the same appearance properties (lineWidth, backColor, foreColor, etc.), you can make a single polygon object out of them by just setting the points of a polygon and putting a blank line in between each elemnt you want to be discontiguous.
This post explains it well:
http://lists.runrev.com/pipermail/use-r ... 24133.html
Unfortunately, the example stack he refers to there is no longer available, but I may be able to get ahold of him to see if he can repost it. It's quite inspiring to see an Asteroids-like game made in Rev running so very efficiently.
This post explains it well:
http://lists.runrev.com/pipermail/use-r ... 24133.html
Unfortunately, the example stack he refers to there is no longer available, but I may be able to get ahold of him to see if he can repost it. It's quite inspiring to see an Asteroids-like game made in Rev running so very efficiently.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
The stack is still there, but the link in the post has an extra %22 code tacked onto the link so it goes to the wrong place.
It's still available here http://www.inspiredlogic.com/rev/starbattle.rev
Looks a great little game and I will be fascinated to take the script to bits and examine it.
It's still available here http://www.inspiredlogic.com/rev/starbattle.rev
Looks a great little game and I will be fascinated to take the script to bits and examine it.
basic draw line graphic
My other "wish" for the graphics is to
have the origin (0,0) at bottom left
rather than top left.
This way all the distances would be
positive and much easier to figure out.
Expect this could be coded - but needs
someone smarter than me!
have the origin (0,0) at bottom left
rather than top left.
This way all the distances would be
positive and much easier to figure out.
Expect this could be coded - but needs
someone smarter than me!
Life is just a bowl of cherries.
Your assumption about positive distances confuses me.
Consider a point in the current system being 100,10 and another one being 50,5. the card's bottomLeft is 0,200 and the topLeft 0,0.
For your new system the cards's bottomLeft would be 0,0 but the topLeft would be 0,200. So 100,10 would translate to 100,190 and 50,5 to 50,195.
To calculate distances I'd use Pythagoras:
for the existing system in rev:
put sqrt((100-50)^2+(10-5)^2) = 50.249378
for your proposed zero point:
put sqrt((100-50)^2+(190-195)^2) = 50.249378
So I'd say you're wrong, but maybe I misunderstood?
edit: At first I missread your bottomLeft for bottomRight
Consider a point in the current system being 100,10 and another one being 50,5. the card's bottomLeft is 0,200 and the topLeft 0,0.
For your new system the cards's bottomLeft would be 0,0 but the topLeft would be 0,200. So 100,10 would translate to 100,190 and 50,5 to 50,195.
To calculate distances I'd use Pythagoras:
for the existing system in rev:
put sqrt((100-50)^2+(10-5)^2) = 50.249378
for your proposed zero point:
put sqrt((100-50)^2+(190-195)^2) = 50.249378
So I'd say you're wrong, but maybe I misunderstood?
edit: At first I missread your bottomLeft for bottomRight
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
Actually turning the origin upside down is easy enough mathematically, you just have to take the difference in the top-relative coordinate and the bottom of the card. Making it work consistently and "semi-natively" in Rev under all permutations of geometry handling (drawing, moving, resizing, etc) is obviously a non-trivial job.
You could do some basic things like putting these in the stack script, or a library:
and use this as in This should draw a line from the bottom right hand corner (390,10) diagonally up and left to (300,100) (relative to the origin being bottom left, and assuming an appropriate card width - say 400 here. If you examine the points of the graphic, it will show Rev's native coords).
Perhaps more powerful and useful would be to make a setProp handler. Put this in the mainstack or library scripts:
Then you can use almost the same syntax as normal, as in:This should draw a right-angled triangle in the bottom left hand corner.
This setProp can be adapted to call a function which returns the (reverted to native) Rev points list so that you can have a similar setProp myOriginRelativePoints as well as setProp myOriginPoints handler.
You can obviously rename the functions and setProp handlers to something a bit more shorthand for you.
The above will NOT be useful for other commands, like "move" for example, and the other coordinate processing features, which will all use the top left as the origin. This is pretty ubiquitous in screen handling, as resizing and redrawing geometry will tend to be pulls from the bottom "adding" to the height, rather than "dragging" the origin "backwards". To be honest, the whole business is easier to just remember the top left as the origin.
You could do some basic things like putting these in the stack script, or a library:
Code: Select all
function fnBottomLeftOrigin pX, pY
local tYLimit
put the bottom of this card into tYLimit --in theory "this" card should be apparent from the source of the function call
--but might need checking in different stack/substack/palette situations
--the setProp handler below does full checking for the card/stack paths to get the right card height
put tYLimit - pY into pY
return pX & comma & pY
end fnBottomLeftOrigin
Code: Select all
if there is a graphic "myNewLine" then delete graphic "myNewLine" --just here to tidy up while testing
put fnBottomLeftOrigin(390,10) into tPointsList --returns the first coordinate turned upside down
put cr & fnBottomLeftOrigin(300,100) after tPointsList --returns the next coordinate also turned upside down
create invisible graphic "myNewLine" --optionally invisible, but allows you to manipulate the properties before showing the line on screen
set the style of graphic "myNewLine" to "line" --you could set the style to polygon, etc instead
set the lineSize of graphic "myNewLine" to 1
set the points of graphic "myNewLine" to tPointsList
set the antialiased of graphic "myNewLine" to true
set the visible of graphic "myNewLine" to true
Perhaps more powerful and useful would be to make a setProp handler. Put this in the mainstack or library scripts:
Code: Select all
setProp myOriginPoints pPointsList
local tYLimit, tLongName, tCardName, tPoints, tLoop, tCardPos
put the long name of the target into tLongName
put (wordOffset ("card", tLongName)) into tCardPos
put word (tCardPos) to -1 of tLongName into tCardName
--you could also use "the owner of the target" to get the card name, but you'd
--also need to check for the control being part of a group
put the bottom of (tCardName) into tYLimit
repeat for each line tLoop in pPointsList
put item 1 of tLoop & comma & (tYlimit - item 2 of tLoop) & cr after tPoints
end repeat
set the points of the target to tPoints
pass myOriginPoints
end myOriginPoints
Code: Select all
local tPointsList
if there is a graphic "myNewTriangle" then delete graphic "myNewTriangle" --just here to tidy up while testing
put "10,10" into tPointsList --the first coordinate
put cr & "100,100" after tPointsList --the next coordinate
put cr & "100,10" after tPointsList --third vertex
put cr & "10,10" after tPointsList --back again to close polygon at first vertex
create invisible graphic "myNewTriangle"
set the style of graphic "myNewTriangle" to "polygon"
set the lineSize of graphic "myNewTriangle" to 1
set the myOriginPoints of graphic "myNewTriangle" to tPointsList
--the above line sets the custom property "myOriginPoints" of the target to your list with the origin at bottom left
--the setProp handler is thereby triggered, and converts that list to Rev top left origin coodinates and sets the points of the target (to the native points)
--it also passes the custom property so that your bottom left origin relative points are saved.
--You can then interrogate either the native or your custom points in the future.
set the antialiased of graphic "myNewTriangle" to true
set the visible of graphic "myNewTriangle" to true
This setProp can be adapted to call a function which returns the (reverted to native) Rev points list so that you can have a similar setProp myOriginRelativePoints as well as setProp myOriginPoints handler.
You can obviously rename the functions and setProp handlers to something a bit more shorthand for you.
The above will NOT be useful for other commands, like "move" for example, and the other coordinate processing features, which will all use the top left as the origin. This is pretty ubiquitous in screen handling, as resizing and redrawing geometry will tend to be pulls from the bottom "adding" to the height, rather than "dragging" the origin "backwards". To be honest, the whole business is easier to just remember the top left as the origin.