1

I would like draw a curved line and attach an object to it. Is it possible to create fraction (from 0.0 to 1.0) which makes move my object on the path? When fraction is 0 then object is on the beginning, when 0.5 is on half way and finally when is on 1.0 it is at the end. Of course i want a curved path, not a straight line :) Is it possible to do in PaintCode?

Adam Smaka
  • 5,977
  • 3
  • 50
  • 55
  • Not sure if it's the right place to ask, though, but I've tried the same and came to the conclusion: No, it's not possible within PaintCode. – Leandros Oct 05 '15 at 07:45
  • It's a programming language, so it's entirely possible, but you're missing important information. Should the speed along the path be linear, physics-based, or "whatever"? Because you tagged this with "bezier", which is an utterly non-linear curve: objects moving along bezier curves will do so rather fast along straight sections and slow down proportional to the path curvature. While parameter=distance values 0=0%, 0.5=50% and 1=100% are by definition true, none of the other parameter=distance values will be true for Bezier curves, so just giving those three values isn't enough. – Mike 'Pomax' Kamermans Oct 05 '15 at 23:23
  • but i don't need animation. i would like use it as a visual progress bar :) just want set value 0.5 and have my object in half way of the bezier – Adam Smaka Oct 06 '15 at 05:53
  • that's reading the almost irrelevant bit while not focussing on the important part. A progress bar is linear with distance. Bezier curves are absolutely not, so you answered the question: you need linear curve traversal. See my answer for the actual answer based on that information. – Mike 'Pomax' Kamermans Oct 11 '15 at 18:03
  • That's reading the almost irrelevant bit while not focussing on the important part. A progress bar is linear with distance, while Bezier curves are absolutely not, so you need to somehow turn that non-linear Bezier curve traversal into linear curve traversal. See my answer based on that information. And remember: updating a progress bar is most definitely an animation. Sure, it's "bit by bit", but that just makes it a *slow* animation. You're still moving a thing along a curve. – Mike 'Pomax' Kamermans Oct 11 '15 at 18:16

2 Answers2

2

If you need it only as a progress bar, it is possible in PaintCode. The trick is to use dashed stroke with very large Gap and then just change the Dash.

Example

Then just attach a Variable and you are done.


Edit: Regarding the discussion under the original post, this solution uses points as the unit, so it will be distributed equally along the curve, no matter how curved the bezier is.

Tricertops
  • 8,492
  • 1
  • 39
  • 41
0

Based on the fact that you're going to walk along the curve using linear distance, a thing Bezier curves are terrible for, you need to build the linear mapping yourself. That's fairly simple though:

When you draw the curve, also build a look-up table that samples the curve once, at say 100 points (t=0, t=0.01, t=0.02, etc). In pseudocode:

lut = [];
lut[0] = 0;
tlen = curve.length();
for(v=0; v<=100; v++) {
  t = v/100;
  clen = curve.split(0,t).length();
  percent = 100*clen/tlen;
  lut[percent] = t;
}

This may leave gaps in your LUT - you can either fix those as a secondary step, or just leave them in and do a binary scan on your array to find the nearest "does have a value" percentage.

Then, when you need to show your progress as some percentage value, you just look up the corresponding t value: say you need to show 83%, you look up lut[83] and draw your object at the value that gives you.

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153