Drawing lines under software control
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Drawing lines under software control
Part of a project requires the drawing to scale of a right angled triangle.
The base line called BASE and vertical called VERT have changing values and the hypotenuse starts at BASE (opposite end to VERT) and ends at top of VERT
I can see the numbers in the properties of a line, but dont know how to change them with variables.
Can anyone help please.
The base line called BASE and vertical called VERT have changing values and the hypotenuse starts at BASE (opposite end to VERT) and ends at top of VERT
I can see the numbers in the properties of a line, but dont know how to change them with variables.
Can anyone help please.
Restate your question by assuming that no one knows what you want to do.
Otherwise I (and others) can only guess of what you actually want. My guess:
Otherwise I (and others) can only guess of what you actually want. My guess:
Code: Select all
put the points of graphic "base" into varBase
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
Put another way, a line is defined as a start x & y and an end x & y
How do you state this in rev so the line is drawn.
In the properties of a line object, near the bottom of the panel is the current coordinates e.g. 123,45 and below that 345,567
if I had vars called StartX End X StartY EndY how would you use them to draw the line?
How do you state this in rev so the line is drawn.
In the properties of a line object, near the bottom of the panel is the current coordinates e.g. 123,45 and below that 345,567
if I had vars called StartX End X StartY EndY how would you use them to draw the line?
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
Here's how to draw a line as an object on the basis of those four parameters:
Hope this helped,
Jan Schenkel.
Code: Select all
on DrawLine startX, startY, endX, endY
local tPoints
-- initialize the points list
put startX & comma & startY & return & \
endX & comma & endY \
into tPoints
-- the next commands gives us a nice clean line object
reset the templateGraphic
set the style of the templateGraphic to "line"
set the points of the templateGraphic to tPoints
create graphic
end DrawLine
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
Hi Janschenkel,
That is just the ticket, now why didnt Rev put this into their manual.
I am most grateful to you, I can now make a boring static diagram into a less boring one.
It takes me back to my early days of programming when leading companies were producing CAD packages for timber frame homes. My poor company could not afford such a luxury. Using a Tandy TRS80 and a continous roll A4 wide pen plotter, the panel workshop soon had perfect plotted panel drawings with cutting lists.
Bring back GWbasic, thats what I say!
Kind regards
Alan Perks
That is just the ticket, now why didnt Rev put this into their manual.
I am most grateful to you, I can now make a boring static diagram into a less boring one.
It takes me back to my early days of programming when leading companies were producing CAD packages for timber frame homes. My poor company could not afford such a luxury. Using a Tandy TRS80 and a continous roll A4 wide pen plotter, the panel workshop soon had perfect plotted panel drawings with cutting lists.
Bring back GWbasic, thats what I say!
Kind regards
Alan Perks
I am against putting that code into the documentation. It's way too specific, and meaningless to 99% of people.
However it'd be great if there'd be a different part of the documentation that contains general hints that let's people understand how stuff works in Rev.
For example you could have tried to put the points of a line you did draw by hand, and then you'd know how it's formatted, and could arrange your variables appropriately. But most languages don't have such a tight integration between visual objects and the properties they have, especially not available during development (as opposed to after a compile). That's why most people just never expect such a connection.
Of course RunRev makes this harder by not telling anywhere obvious (like the inspector) that there is actually no line object, in reality (virtuality?) it's just a polygon with two points.
However it'd be great if there'd be a different part of the documentation that contains general hints that let's people understand how stuff works in Rev.
For example you could have tried to put the points of a line you did draw by hand, and then you'd know how it's formatted, and could arrange your variables appropriately. But most languages don't have such a tight integration between visual objects and the properties they have, especially not available during development (as opposed to after a compile). That's why most people just never expect such a connection.
Of course RunRev makes this harder by not telling anywhere obvious (like the inspector) that there is actually no line object, in reality (virtuality?) it's just a polygon with two points.
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
Well there are the Sample scripts in the Getting Started section. Things like this would make a great addition to that.BvG wrote:I am against putting that code into the documentation. It's way too specific, and meaningless to 99% of people.
However it'd be great if there'd be a different part of the documentation that contains general hints that let's people understand how stuff works in Rev.
For example you could have tried to put the points of a line you did draw by hand, and then you'd know how it's formatted, and could arrange your variables appropriately. But most languages don't have such a tight integration between visual objects and the properties they have, especially not available during development (as opposed to after a compile). That's why most people just never expect such a connection.
Of course RunRev makes this harder by not telling anywhere obvious (like the inspector) that there is actually no line object, in reality (virtuality?) it's just a polygon with two points.
Yes that part of the documentation (and others too) could need some heavy lifting. But this is a deficiency in the concept of the rev IDE, and just throwing documentation content at all of those will only worse the problem, because then the documentation would contain even more stuff then right now, and people already have much problems finding the relevant information within it.
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
Re: Drawing lines under software control
How would you implement a line draw "freehand".
I have tried this and the quality of the line is not good. I have an image on the card, and the line will be drawn onto it, but comparing the quality with the suggested code above, which uses a graphics object to contain the line, mine is way off.
I have tried this and the quality of the line is not good. I have an image on the card, and the line will be drawn onto it, but comparing the quality with the suggested code above, which uses a graphics object to contain the line, mine is way off.
Build 160
Version 2.9.0
Platform: Windows
Version 2.9.0
Platform: Windows
Re: Drawing lines under software control
Kotikoti,
do you want to "paint" into an image or do you want to draw a freehandline in a graphic above the image?
If you want the later then you might want to look at
http://revonline2.runrev.com/stack/314/ ... on-Graphic
I did this exactly to get the outlines of an image with a graphic sort of freehand. The code is in an image on top of which will be drawn graphics manually.
If this is what you want and have difficulties with the stack then please ask again. Or if I am wrong in what you want could you tell us in more detail what you want to achieve?
regards
Bernd
do you want to "paint" into an image or do you want to draw a freehandline in a graphic above the image?
If you want the later then you might want to look at
http://revonline2.runrev.com/stack/314/ ... on-Graphic
I did this exactly to get the outlines of an image with a graphic sort of freehand. The code is in an image on top of which will be drawn graphics manually.
If this is what you want and have difficulties with the stack then please ask again. Or if I am wrong in what you want could you tell us in more detail what you want to achieve?
regards
Bernd
Re: Drawing lines under software control
Thanks Bernd,
I have had a look and can see you have the style set to polygon. Did try to change this to line, and the effect is that the drawing is actually placed on the image, which is not necessarily ideal for what I had in mind, hence your solution as is, is a great help.
Since I needed to draw a "line" still in freehand way, but still have a way to manage these lines (as already in your code), I have altered the script as follows.
Have highlited my entries.
One thing I noted though is that, I have to leave the wait in milliseconds at a higher value in the
send "recordMouseLoc" to me in 90 milliseconds
script line, else getting a twitchy display of the polygonal line on redraw.
Thanks again for pointing me in the right direction.
kotikoti
I have had a look and can see you have the style set to polygon. Did try to change this to line, and the effect is that the drawing is actually placed on the image, which is not necessarily ideal for what I had in mind, hence your solution as is, is a great help.
Since I needed to draw a "line" still in freehand way, but still have a way to manage these lines (as already in your code), I have altered the script as follows.
Code: Select all
on recordMouseLoc
put return & the mouseloc after tLocList
set the points of last graphic to tLocList
if not (the mouse is up) then
--kotikoti (1line)
set the points of last graphic to line 1 of tLocList &cr& line -2 of tLocList
send "recordMouseLoc" to me in 90 milliseconds -- adjust the timing
else
--kotikoti (3 lines)
set the points of last graphic to line 1 of points of last graphic &cr& line -2 of points of last graphic
set the style of last graphic to "line"
set the endArrow of last graphic to true
set the opaque of last graphic to the hilite of button "opaque"
set the markerpoints of last graphic to makeMarkerpoints()
set the markerdrawn of last graphic to the hilite of btn "show points"
end if
end recordMouseLoc
One thing I noted though is that, I have to leave the wait in milliseconds at a higher value in the
send "recordMouseLoc" to me in 90 milliseconds
script line, else getting a twitchy display of the polygonal line on redraw.
Thanks again for pointing me in the right direction.
kotikoti
Build 160
Version 2.9.0
Platform: Windows
Version 2.9.0
Platform: Windows
Re: Drawing lines under software control
Kotikoti,
glad is of of some use.
But this may not be what you intend to do.
If you give me an example what exctly your are trying to do I might propose different solutions. Is the user supposed to draw, is it for you a one-time job to create the straight lines. What are they for. And so on.
But maybe you already solved your problem.
regards
Bernd
glad is of of some use.
the 90 milliseconds is just a trade off between accuracy (the number of points of a polygon) and too many points (overly accurate) Since you just want the starting point and the end point for the line, one could even imagine a different solution. Checking for an option/alt key down and than recording the first click and the second click. Or something like that. It is not really necessary to change the style to line, for what it is worth a polygon with two points is a line. You could even put more then one straigth line into one polygon graphic: if you open the inspector for the polygon graphic you find the points of the graphic at the bottom. In your case with a straight line you should have two points there. In case you changed the style to line change it to polygon. After the list of two points you insert a blank line, just a return. Than you take two points and paste them after the blank line (or you just type them in there) leave that field and your polygon now displays two straigth lines, not connected to each other. You can do this with as many objects as you like, not only straight lines.send "recordMouseLoc" to me in 90 milliseconds
But this may not be what you intend to do.
If you give me an example what exctly your are trying to do I might propose different solutions. Is the user supposed to draw, is it for you a one-time job to create the straight lines. What are they for. And so on.
But maybe you already solved your problem.
regards
Bernd
Re: Drawing lines under software control
Hi Bernd
The line
set the points of last graphic to line 1 of points of last graphic &cr& line -2 of points of last graphic
solves the two points for me and works fine. The line being created is to mark two endpoints in draw mode, and optionally to be able to delete the said line, which your stack has given me ideas on how this can be implemented. I was of the thinking that, I could just use a statement like
select line tool
but this will mean, I have no control of the created line to start with, and that was initially also coupled with the low quality of the drawn line, now with your suggestion, I have something to build on.
Thanks again
The line
set the points of last graphic to line 1 of points of last graphic &cr& line -2 of points of last graphic
solves the two points for me and works fine. The line being created is to mark two endpoints in draw mode, and optionally to be able to delete the said line, which your stack has given me ideas on how this can be implemented. I was of the thinking that, I could just use a statement like
select line tool
but this will mean, I have no control of the created line to start with, and that was initially also coupled with the low quality of the drawn line, now with your suggestion, I have something to build on.
Thanks again
Build 160
Version 2.9.0
Platform: Windows
Version 2.9.0
Platform: Windows