calculate a value with a switch from 1 to 0
in
Programming Questions
•
1 year ago
We have a path,
the length is normalized where the start of the path is 0.0 and the end is 1.0
Now let's say we can close the path, then the start is the same as the end, 1.0 / 0.0.
Every ellipse on the path is a anchor, the ones in red hold a value called weight (shown as w=6, w=.., w=15).
The ones in green also have a weight but this will depend on the 2 neighbors with a red ellipse.
I'm able to call the weight value for anchors on the dotted line (no anchors show for that in the picture).
But i can't get it done between the 0.0 and 1.0.
Showing code is not really a option but pseudo code or just explanation is welcome.
I guess the first step is to recalculate t to be within the range of 0 to 1 again -> where 0.85 will be the new 0 and 0.3 the new 1 (or the other way around).
Then for the weight:
w = weightA * newT + weightB;
------------
here is some code i tried to isolate the problem (which is like 100% different then the actual code but might help).
Atm there is a big gap between 1.0 and 0.0 which is wrong of course cause they should be on the same position.
- float[] tValuesS = {0.0, 0.2, 0.3};
- float[] tValuesE = {0.85, 0.9, 1.0};
- float weightStart = 15;
- float weightEnd = 6;
- void setup() {
- size(600, 300);
- textAlign(CENTER);
- float tLength = 1 - tValuesE[0] + tValuesS[tValuesS.length-1];
- for(int i = 0; i < tValuesE.length; i++) {
- float x = map(tValuesE[i], tValuesE[0], 1+tValuesS[tValuesS.length-1], 50, width-50);
- fill(i == 0 ? color(255, 0, 0) : color(0, 255, 0));
- ellipse(x, 150, 10, 10);
- fill(0);
- text(nfc(tValuesE[i], 2), x, 180);
- }
- for(int i = 0; i < tValuesS.length; i++) {
- float x = map(tValuesS[i]+1, 0, 1+tValuesS[tValuesS.length-1], 50, width-50);
- fill(i == tValuesS.length-1 ? color(255, 0, 0) : color(0, 255, 0));
- ellipse(x, 150, 10, 10);
- //float w = map(tValuesS[i]+1, 0, 1, weightEnd, weightStart);
- //println(w);
- noFill();
- ellipse(x, 150, w*10, w*10);
- fill(0);
- text(nfc(tValuesS[i], 2), x, 180);
- }
- }
1