Stretching graphics

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9729
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Stretching graphics

Post by dunbarx » Wed Jun 01, 2022 2:25 pm

I use CAD a lot. I also use LC a lot as a drawing program. I know it is not intended for this.

I needed to take a "stock" polygon graphic:
Screen Shot 2022-05-31 at 12.31.22 PM.png
Screen Shot 2022-05-31 at 12.31.22 PM.png (4.71 KiB) Viewed 1278 times
and be able to continuously stretch it in either x or y under script control. No problem, I simply increased, say, the width of the graphic until it was the right size. But in doing so, the small horizontal segment at the botRight stretches proportionately:
Screen Shot 2022-06-01 at 9.09.08 AM.png
Screen Shot 2022-06-01 at 9.09.08 AM.png (4.98 KiB) Viewed 1278 times
When what I want is this:
Screen Shot 2022-06-01 at 8.50.39 AM.png
Screen Shot 2022-06-01 at 8.50.39 AM.png (5.11 KiB) Viewed 1278 times
I am able to get the bottomMost version in two ways, by simply increasing the width and adjusting the length of that trailing segment on the fly, or by changing the points of the graphic explicitly, as the stretching process runs.

But is there a way to simply stretch? I originally had thought that by, say, doubling the width of the starting graphic, that the "ends" would stay the same. In fact, doing so doubles the size of any and all horizontal elements. Fortunately it does not increase the line width. This is not really unexpected, as, after all, an angled graphic changes its angle as the width changes.

Just wondering...

Craig

SparkOut
Posts: 2857
Joined: Sun Sep 23, 2007 4:58 pm

Re: Stretching graphics

Post by SparkOut » Wed Jun 01, 2022 3:14 pm

Assuming it's a continuous line drawn from the left to the right, you could take the points, and find the difference between the left and right ends of the segment you want to extend. Say that is 100 in the horizontal direction and you multiply by 2, then you can just change the x coordinate of the right end, and the x coordinate of the beginning of the next segment.
More complicated shapes might be rather trickier.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9729
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Stretching graphics

Post by dunbarx » Wed Jun 01, 2022 4:11 pm

Sparkout.

That is pretty much what I did.

I guess I was really asking if that behavior made sense, in that doubling the width of a control also doubled the width of all horizontal segments as well. I was not sure that is consistent with my perception of what changing the width really means, that is, that doing so proportionately "expands" the segments that comprise that graphic, as opposed to simply making the original "shape" twice as wide.

I do see it, though.

Craig

Post Reply

Return to “Talking LiveCode”