Copy link to clipboard
Copied
Hello,
how do I simplify and optimize the code below? As you can see I would like to affect every 6th character starting with #2 when the length of the text is not predetermined. Thank you in advance.
if(textIndex == 2 || textIndex === 8 || textIndex === 14 || textIndex === 20 || textIndex === 26) {
100;
} else {
0;
}
Like this maybe:
textIndex%6 == 2 ? 100 : 0
Like this I guess:
n = thisProperty.propertyGroup(3).name%6;
textIndex%6 == n ? 100 : 0
Copy link to clipboard
Copied
textIndex % 6 + 2
Mylenium
Copy link to clipboard
Copied
Thank you.
When I replace
(textIndex == 2 || textIndex === 8 || textIndex === 14 || textIndex === 20 || textIndex === 26)
with
(textIndex % 6 + 2)
the effect is not the same.
Attached is the screenshot of what I am trying to achieve and it is working with my expression, but I would just like to simplify it so I can automate different scenarios.
Copy link to clipboard
Copied
Like this maybe:
textIndex%6 == 2 ? 100 : 0
Copy link to clipboard
Copied
Thank you so much, that works!!!
Copy link to clipboard
Copied
Hi Dan,
any ideas why when it comes to the 6th row it doesn't work?
so
textIndex%6 == 6 ? 100 : 0
is not working (no errors) but doesn't do anything. Thank you
Copy link to clipboard
Copied
Ah, OK, so you have a different version of the expression applied to each row. Try it this way:
textIndex%6 == 0 ? 100 : 0
Copy link to clipboard
Copied
Thank you.
Copy link to clipboard
Copied
Dan,
apologizes for taking more of your time for such basic questions,
but what is the best way to combine
textIndex%6 == 2 ? 100 : 0
and
textIndex%6 == 0 ? 100 : 0
so one expression will cover both of these situations.
I am asking all of this because I am taking #2 from
thisProperty.propertyGroup(3).name;
where "Animator" name is "2".
Of course, I start with "1" and by duplicating the animator everything works fine until I hit the 6th copy. As you recommended I could change it manually into "0" but I am looking for the way that the original expression applied to the "1" will work in the "6" etc., as well.
Thank you in advance.
Copy link to clipboard
Copied
Like this I guess:
n = thisProperty.propertyGroup(3).name%6;
textIndex%6 == n ? 100 : 0
Copy link to clipboard
Copied
Beautiful. Thank you so much.
By the way, I am trying to understand what is going on here and I was looking around but could not find anything regarding what "%" represents. Thank you again
Copy link to clipboard
Copied
Don't worry I found it. It is a remainder %.
Copy link to clipboard
Copied
Hi,
one additional question. Dan's solution from above works perfectly for selecting rows. I would like an added checkbox to be able to switch from selecting from rows to columns. The only way right now I can do it with the expression below but I have to manually switch Expression selector>Based On from Characters which will give me row selection to LINES which will select columns.
row = effect("ROWS")("Slider");
column = effect("COLUMNS")("Slider");
checkN = effect("if OFF vertical COLORS --- if ON horizonatal COLORS")("Checkbox");
numb = (checkN == 0) ? row : column;
numToColor = thisProperty.propertyGroup(3).name%numb;
textIndex%numb == numToColor ? 100 : 0
Is there any way to add expressions to select 1st, 2nd, etc columns so I avoid manually switching Expression selector?
A few screenshots are included one is with what happens with the character selected, one is with lines selected, and one is a screenshot of the expression's timeline section just for reference.
As always thank you so much.
Copy link to clipboard
Copied
I think your setup is the opposite of what I'm used to, but when I've done grids in the past, you get the column number with index%numberOfColumns and you get the row number with Math.floor(index/numberOfColumns). I don't know if that helps at all.
Copy link to clipboard
Copied
Thank you, Dan, for your time,
I am not sure if I was clear enough in my question.
Just to explain something in general, I am building the box chart graphic using Webdings "g" letter which is a square (you can see the reference image in the attachment above)
Let's say I have a box graph with 4 rows and 5 columns
With the expression that I used based on your previous advice, it selects 1st box and then 5th, 9th, 13th and 17th.
My question is how can I write the expressions that select 1st 4 boxes.
And because I am using thisProperty.propertyGroup(3).name but duplicating the "Animator"
I should be able to select 5th to 8th and then 9th to 12th and so on.
This may be very basic and I thank you again for your help.
Copy link to clipboard
Copied
OK, so I've been playing around with this, and hopefully I've set it up like you have it. I think you can get everything you need with just the one checkbox control. This is what I have:
checkN = effect("if OFF vertical COLORS --- if ON horizonatal COLORS")("Checkbox").value;
numRows = text.sourceText.split("\r").length;
numCols = text.sourceText.split("\r")[0].length;
numColors = thisProperty.propertyGroup(4).numProperties;
myRow = Math.floor((textIndex-1)/numCols) + 1;
myCol = (textIndex - 1)%numCols + 1;
n = parseInt(thisProperty.propertyGroup(3).name,10); // number of this selector
if (checkN){
myRow == n ? 100 : 0;
}else{
myCol == n ? 100 : 0
}
You won't need the numColors variable unless you have a situation where there are more rows (or columns) than there are colors, in which case you'll have to add some additional modulo math to the expression to get the colors to cycle. I hope you find it useful.
Copy link to clipboard
Copied
Absolutely beautiful. Thank you so much, Dan.
I have sent a little tip for you, to have a coffee or a beer on me.
Copy link to clipboard
Copied
Thanks -- I appreciate it! BTW, this has the mods to make the colors cycle:
checkN = effect("if OFF vertical COLORS --- if ON horizonatal COLORS")("Checkbox").value;
numRows = text.sourceText.split("\r").length;
numCols = text.sourceText.split("\r")[0].length;
numColors = thisProperty.propertyGroup(4).numProperties;
myRow = Math.floor((textIndex-1)/numCols)%numColors + 1;
myCol = ((textIndex - 1)%numCols)%numColors + 1;
n = parseInt(thisProperty.propertyGroup(3).name,10); // number of this selector
if (checkN){
myRow == n ? 100 : 0;
}else{
myCol == n ? 100 : 0
}
Copy link to clipboard
Copied
Thank you, Dan!!! It is amazing and so generous that you are always willing to help and provide guidance to everyone no matter how our questions sometimes could be so basic (maybe not in this case) and our skills level
so very novice.
The first solution worked perfectly for me. Just a quick question about the second "colors cycle" solution, in what situation that solution would be fitting. Thank you.
Copy link to clipboard
Copied
If you expand the grid of squares so that there are more rows and/or columns than color selectors, when it runs out of colors, it will start over, and cycle through the colors again.
Copy link to clipboard
Copied
Here's another solution:
gLen=6;
gOff=2;
((textIndex+gOff) % gLen)*selectorValue
Mylenium
Copy link to clipboard
Copied