Drawing lines under software control

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Drawing lines under software control

Post by user#606 » Fri May 02, 2008 6:36 pm

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.

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Post by BvG » Fri May 02, 2008 9:37 pm

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:

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

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Post by user#606 » Sat May 03, 2008 8:16 am

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?

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Sat May 03, 2008 1:46 pm

Here's how to draw a line as an object on the basis of those four parameters:

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
Hope this helped,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

user#606
Posts: 217
Joined: Sun Jan 27, 2008 12:25 pm
Contact:

Post by user#606 » Sat May 03, 2008 2:20 pm

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

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Post by BvG » Sat May 03, 2008 2:43 pm

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.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

keyless
Posts: 211
Joined: Wed Dec 12, 2007 11:21 pm

Post by keyless » Sun May 04, 2008 7:54 am

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.
Well there are the Sample scripts in the Getting Started section. Things like this would make a great addition to that.

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Post by BvG » Sun May 04, 2008 10:00 am

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

kotikoti
Posts: 72
Joined: Tue Apr 15, 2008 7:35 pm

Re: Drawing lines under software control

Post by kotikoti » Fri Dec 11, 2009 3:27 pm

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.
Build 160
Version 2.9.0
Platform: Windows

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Drawing lines under software control

Post by bn » Fri Dec 11, 2009 3:43 pm

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

kotikoti
Posts: 72
Joined: Tue Apr 15, 2008 7:35 pm

Re: Drawing lines under software control

Post by kotikoti » Fri Dec 11, 2009 9:01 pm

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.

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

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
Build 160
Version 2.9.0
Platform: Windows

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Drawing lines under software control

Post by bn » Fri Dec 11, 2009 9:20 pm

Kotikoti,
glad is of of some use.
send "recordMouseLoc" to me in 90 milliseconds
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.
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

kotikoti
Posts: 72
Joined: Tue Apr 15, 2008 7:35 pm

Re: Drawing lines under software control

Post by kotikoti » Fri Dec 11, 2009 9:45 pm

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
Build 160
Version 2.9.0
Platform: Windows

Post Reply