Scripting A Curve Graphic

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

johnmiller1950
Posts: 119
Joined: Mon Apr 30, 2007 3:33 pm

Scripting A Curve Graphic

Post by johnmiller1950 »

Greetings All,

Using the code below is supposed to set the graphic to a curve, but it uses straight lines instead. Any wisdom? I am using Mac OS 27.2 on a MacBook Pro M5 Max - Thanks, John

on mouseUp
create graphic "sCurve"
set the style of graphic "sCurve" to "curve"
put "100,100" & CR & "300,50" & CR & "500,100" into cPoints
set the points of graphic "sCurve" to cPoints
set the pencolor of graphic "sCurve" to "red"
set the linesize of graphic "sCurve" to 3
end mouseUp
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10523
Joined: Fri Feb 19, 2010 10:17 am

Re: Scripting A Curve Graphic

Post by richmond62 »

That does seem odd.

Personally I always mess around with SINES and COSINES to generate a set of values in a field, then set the points of a graphic to those points.
Klaus
Posts: 14353
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Scripting A Curve Graphic

Post by Klaus »

Hi John,

who told you this? :shock:
As far as I remember (way back in the Metacard years) this has never been the case.

As Richmond said, for some kind of (bezier or whatever) curve you'll need to set the
neccessary points of the graphic to the result of a lot of points created with COS
and SIN equitations. (Which is way over MY head... 8) )

Best

Klaus
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10523
Joined: Fri Feb 19, 2010 10:17 am

Re: Scripting A Curve Graphic

Post by richmond62 »

SS 2026-11-04 at 19.32.02.jpg
-

Code: Select all

on mouseUp
   put empty into fld "POYNTS"
   put 0.05 into DEGG
   repeat until DEGG > 4.71
      put sin(DEGG) into SDD
      put SDD * 300 into SDDH
      put cos(DEGG) into CDD
      put CDD * 300 into CDDH
      put DEGG * 20 into LYNE
      put (SDDH + 400) & "," & (CDDH + 400) into line LYNE of fld "POYNTS"
      add 0.05 to DEGG
      ------
      set the points of grc "PP" to fld "POYNTS"
   end repeat
end mouseUp
Unlike Klaus, when I was 14, I had a wonderful teacher called Bonehead Barker who made me work all this sort of thing out with a book of tables, a pencil, and some graph paper:
-
tables.png
tables.png (172.48 KiB) Viewed 171 times
-
Which has stood me in good stead e'er syne. 8)

Which also explains how I got an A in 'O' Level Maths. [The fact that I got an E in 'A' Level Maths is all down to Calculus & Adolescent spots :lol: ]
Attachments
CURVEZ.livecode.zip
(1.18 KiB) Downloaded 3 times
johnmiller1950
Posts: 119
Joined: Mon Apr 30, 2007 3:33 pm

Re: Scripting A Curve Graphic

Post by johnmiller1950 »

I'm a little confused.

Klaus, you asked, "who told you that?" I'm not sure what you are referring to.

This is what the LiveCode documentation says . . . "Setting the style of a graphic to curve makes the graphic into a curved line. Curve graphics, unlike painted curves, can be changed and reshaped: use the points property to change the shape of the curve."

Does setting the style of a graphic to "curve" actually generate a curve, or am I misunderstanding you?

John
johnmiller1950
Posts: 119
Joined: Mon Apr 30, 2007 3:33 pm

Re: Scripting A Curve Graphic

Post by johnmiller1950 »

Richmond,

Thanks for the sample code. I have been playing around with sin and coin coding, and I can create a curved line, but I thought setting the style to curve and then setting the archangle and the startangle properties would be easier, but apparently this doesn't work.

John
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10523
Joined: Fri Feb 19, 2010 10:17 am

Re: Scripting A Curve Graphic

Post by richmond62 »

Well, I don't know: all that example is is a rehash of a program I wrote in BBC BASIC on a BBC Micro in 1989 when I was bored out of my box in the U.A.E. 8)

AND, of course my 'curve' is NOT a curve at all, it is a thing made up of lots of little straight lines.
Last edited by richmond62 on Wed Nov 04, 2026 11:01 pm, edited 1 time in total.
Klaus
Posts: 14353
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Scripting A Curve Graphic

Post by Klaus »

johnmiller1950 wrote: Wed Nov 04, 2026 7:07 pm I'm a little confused.

Klaus, you asked, "who told you that?" I'm not sure what you are referring to.

This is what the LiveCode documentation says . . . "Setting the style of a graphic to curve makes the graphic into a curved line. Curve graphics, unlike painted curves, can be changed and reshaped: use the points property to change the shape of the curve."

Does setting the style of a graphic to "curve" actually generate a curve, or am I misunderstanding you?

John
Hi John,

I'm a little confused, too! Never read that part of the docs, to be honest...

The docs are misleading, I think, there has never beeen a "real" bezier-like curve graphic in MC, Rev, RR or LC
except when you set the points*** to something like in Richmonds script.

***Which implies to me that this is just a polygon with another name. :-D

Best

Klaus
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10543
Joined: Wed May 06, 2009 2:28 pm

Re: Scripting A Curve Graphic

Post by dunbarx »

John.

I have used LC to draw curved shapes of all kinds for years. I did so by pushing its limits, after all, LC is not a drafting program like AutoCad or SolidWorks.

I believe that a "curved graphic" in LC is defined simply and only by a list of points. But if that is true, then all curved LC graphics are simply a suite of straight lines connected together, however close those points are on screen. And even true drafting programs, with their renderings being mathematically generated, still display on screen as straight lines defined by pixel locations.

So in that sense they both render similarly; the point list defining a curve in LC could also be pixel-to pixel, its resolution being as good as any.

All that said, what limitations are you concerned about?

Craig
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10523
Joined: Fri Feb 19, 2010 10:17 am

Re: Scripting A Curve Graphic

Post by richmond62 »

SandC1.jpg
-
SandC2.jpg
-
My example only employs a 'few' points (94), but there is no real reason that one could not subdivide these to such an extent an observer won't notice any 'jaggies'.
-
SS 2026-11-04 at 21.37.01.jpg
-
Although, to be honest, the resultant line looks MORE jaggy than the previous one. 8)
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10543
Joined: Wed May 06, 2009 2:28 pm

Re: Scripting A Curve Graphic

Post by dunbarx »

Richmond.

Your handler generates a portion of a circle, that portion possibly more or less that 360 degrees depending on your parameters. It is still a string of straight lines connected together, not a "smooth" curve.

So I think this sidesteps the concern of JohnMiller, who, (as Klaus implied) thought that a "curve" in LC was somehow more "true".

It is not, and that begs the issue of the fact that everything we see on a computer monitor is a digital, not analog image, all being straight lines defined by pixel locations, even if the endpoints of a particular graphic are the same pixel. In other words, a single pixel (a dot on screen) is a straight line with the same endpoints.

Craig
Last edited by dunbarx on Wed Nov 04, 2026 8:56 pm, edited 3 times in total.
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10543
Joined: Wed May 06, 2009 2:28 pm

Re: Scripting A Curve Graphic

Post by dunbarx »

Richmond.

I notice you are catching up to me in the number of posts on this forum.

Cut it out :wink:

Craig
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10523
Joined: Fri Feb 19, 2010 10:17 am

Re: Scripting A Curve Graphic

Post by richmond62 »

Craig . . .

Why don't you just try and catch up with me over on the alternative forums?

Richmond.
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10543
Joined: Wed May 06, 2009 2:28 pm

Re: Scripting A Curve Graphic

Post by dunbarx »

John.

If I pull an oval graphic from the toolbar, there are no points in that object. If I draw an oval using the "curve graphic" tool, there are, and this begs the issue of how badly I draw a circle with that tool.

The two sections of graphics in the toolbar draw two different varieties of objects, one with points and one without. They must each be rendered on screen by a list of points, however, but the points in the oval graphic are hidden.

If I

Code: Select all

set the points of grc "2" to the points of grc "1
grc 2 being one drawn by hand with the "curve graphic" tool (which has points) nothing changes. If I do it the other way around, nothing changes. The graphic with points keeps its points. The one without points never gets any new ones.

Craig
Klaus
Posts: 14353
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Scripting A Curve Graphic

Post by Klaus »

To add to the confusion, there is the EFFECTIVE keyord.

Do this:
1. Create ANY "curve" graphic -> grc 1
2. Create an OVAL graphic -> grc 2

Now use the message box or a button:
set the points of grc 1 to the EFFECTIVE points of grc 2

Et voila, the "curve" graphic turns into an "edgy" copy of the oval graphic. :-)

P.S.
We can get the effective points of rectangle, round-rectangle, oval and regular polygon graphics.
Post Reply