Blinking color sequence in Angular - css

I have a task to create 4 blinking divs in an Angular project. The colors come from an API in an array with 16 elements and each element is an array with 4 elements (string).
ColorPatterns[
Pattern1["Color1", "Color2", "Color3", "Color4"],
Pattern2["Color1", "Color2", "Color3", "Color4"],
...
Pattern16["Color1", "Color2", "Color3", "Color4"],
]
Color1 is for the first div, Color2 is for the second div and so on.
The sequence of 16 must change per 1 second and after the last element (Pattern16) the sequence should start over: Pattern1 -> Pattern2 -> ... -> Pattern16 -> Pattern1 -> ... .
How should this problem be solved in Angular?

Use an Observable to do the timing stuff. If we can to it for one div then others can be repeated.
Observable.interval(1000) //emit every 1 sec with values = 0 then 1 them 2 ..
.map(value=>ColorPaterns[value%16][0]) // 0 for 1st color
.subscribe((firstColor)=>{
// set 1st div color here
})

Related

How would an alternate color pass every 4 elements to repeat the same component pattern with Array.map function?

I'm trying to send my child components in a reaction app an alternate color as a property, and I'm not really sure how to do it. The color of each CardSimpleRow component must alternate in 4 different colors and once the 4th color is there, it returns to the beginning of the color, let's say. I want to use map because my matrix is dynamic and writing each row of the matrix to render seems unnecessary.
export const FollowScreen = () => {
const alternatingColor = [ ["#d72226", "#a8232a"], ["#123", "#a33a"], ["#f3f3f3", "#a8232a"], ["#dd26", "#a8232a"] ]
return (
<>
{
data.map((elements, index) => {
return <CardSimpleRow
color={index % 4 ? alternatingColor[1] : alternatingColor[0]}
elements={elements}
/>
})
}
</>
)
It's a gradient so I need to send the 1st array, then the 2nd array, then the 3rd, then the 4th and after that go back to the 1st array>
Example if there are 8 CardSimpleRow, I need 4 cards with the array from 0 to 4 and then the other four with the array from 0 to 4 again
If I got it right, you need something like:
alternatingColor[0]
alternatingColor[1]
alternatingColor[2]
alternatingColor[4]
alternatingColor[0]
alternatingColor[1]
...
To obtain that you just need to change a single line:
...
color={alternatingColor[index % 4]}
...
this will access the correct element in alternatingColor by taking the integer remainder based on the index.
Index 0 => remainder of 0 / 4 == 0
Index 1 => remainder of 1 / 4 == 1
...
Index 5 => remainder of 5 / 4 == 1

How to know if there is a different element in one array in Scilab?

My goal is to check if there are misplaced objects in one array.
for example the array is
2.
2.
2.
2.
2.
1.
3.
1.
3.
3.
3.
1.
3.
1.
1.
1.
1.
I want to know if the first 5 elements, 6 to 13 and 14-17 are the same.
The purpose of this is to identify the misplaced elements in a clustering solution.
I have tried for the first 5 elements
ISet=5
IVer=7
IVir=5
for i=1:ISet
if(isequal(FIRSTMIN(i,1,2),FIRSTMIN(i+1,1,2))==%f)
numMisp=numMisp+1
mprintf("Set misp: %i",numMisp)
end
end
For the next 6 to 13 elements
for i=ISet+1:IVer+ISet-1
if(isequal(FIRSTMIN(i,1,2),FIRSTMIN(i+1,1,2))==%f)
mprintf("%i %i Ver misp: %i\n",FIRSTMIN(i,1,2),FIRSTMIN(i+1,1,2),i)
numMisp=numMisp+1
end
end
For the next 14 to 17 elements
for i=IVer+ISet:IVer+IVir-1
if(isequal(FIRSTMIN(i,1,2),FIRSTMIN(i+1,1,2))==%f)
mprintf("%i %i Ver misp: %i\n",FIRSTMIN(i,1,2),FIRSTMIN(i+1,1,2),i)
numMisp=numMisp+1
mprintf("Vir misp: %i",i)
end
end
You can use unique for that purpose. For example the following test checks if the first five elements are the same
x=[2 2 2 2 2 1 3 1 3 3 3 1 3 1 1 1 1];
if length(unique(x(1:5))) == 1
//
end
You can do the the same for the other clusters by replacing 1:5 by 6:13 then 14:17.

How to use the function "table:get" (table extension) when 2 keys are required?

I have a file .txt with 3 columns: ID-polygon-1, ID-polygon-2 and distance.
When I import my file into Netlogo, I obtain 3 lists [[list1][list2][list3]] which corresponds with the 3 columns.
I used table:from-list list to create a table with the content of 3 lists.
I obtain {{table: [[1 1] [67 518] [815 127]]}} (The table displays the first two lines of my dataset).
For example, I would like to get the value of distance (list3) between ID-polygon-1 = 1 (list1) and ID-polygon-2 = 67 (list1), that is, 815.
How can I use table:get table key when I have need of 2 keys (ID-polygon-1 and ID-polygon-2) ?
Thanks very much your help.
Using table:from-list will not help you there: it expects "a list of two element lists, or pairs" where the "the first element in the pair is the key and the second element is the value." That's not what you have in your original list.
Furthermore, NetLogo tables (and associative arrays in general) cannot have two keys. They are always just key-value pairs. Nothing prevents the value from being another table, however, and in your case, that is what you need: a table of tables!
There is no primitive to build that directly, however. You will need to build it yourself:
extensions [ table ]
globals [ t ]
to setup
let lists [
[ 1 1 ] ; ID-polygon-1 column
[ 67 518 ] ; ID-polygon-2 column
[ 815 127 ] ; distance column
]
set t table:make
foreach n-values length first lists [ ? ] [
let id1 item ? (item 0 lists)
let id2 item ? (item 1 lists)
let dist item ? (item 2 lists)
if not table:has-key? t id1 [
table:put t id1 table:make
]
table:put (table:get t id1) id2 dist
]
end
Here is what you get when you print the resulting table:
{{table: [[1 {{table: [[67 815] [518 127]]}}]]}}
And here is a small reporter to make it convenient to get a distance from the table:
to-report get-dist [ id1 id2 ]
report table:get (table:get t id1) id2
end
Using get-dist 1 67 will give the 815 result you were looking for.

autoIt3 how to select n-th matched control?

When using autoIt to get Window's Text and the WinGetText matches multiple controls (e.g. with the same Class SciCalc in this case), the WinGetText will concatenate the text of all the controls. How can I get the Text of the n-th (say 3rd 'MR') control?
e.g.
Local $output = WinGetText("[CLASS:SciCalc]", "")
print
output:666666.
MC
MR
MS
M+
7
4
1
0
8
5
2
+/-
9
6
3
.
/
*
-
+
=
Backspace
CE
C
1/x
sqt
%
Something like this
ControlGetText("[CLASS:SciCalc]","","[CLASS:Button; INSTANCE:3]")
Use AutoIt Window Info to find the Advanced mode details on the wanted control.

OCTAVE with enlarging width of elements

I have a problem (Octave):
lets say I have a = 1 2 3 4 5
and I want to add 'b' character to every element in a.. So that I get something like that: a = 1b 2b 3b 4b 5b
How do I do that?
Thanx
To be able to do that, a must be defined as a string of characters rather than an array of doubles. There may be a more elegant solution, but the following works:
a = num2str(1:5); % '1' is a(1), '2' is a(5), etc...
% a(2) to a(4) are white spaces
for k=2:4:18
a(k) = 'b';
end

Resources