LED marquee 2, led headlight

Source: Internet
Author: User

LED marquee 2, led headlight

This is the address of the previous Article: http://blog.csdn.net/pandeng4639088/article/details/46550257

In the previous article, I analyzed the principles and rules of the running horse lamp. Although the story would have ended there, I thought about it again on my way to lunch, since A hypothetical length is added to object A, why not map the hypothetical length to object? In real life, this effect also exists, that is, when the length of A is exceeded by B, it appears directly at the starting position of A. The similar effect is as follows:


Okay. How can this effect be achieved? Similarly, we analyze the laws of things on the surface of facts and use them to solve problems.

(1) As shown in, when object B just exceeded object A, how can we map some B0 that just exceeded to A0 ?, Assume that the starting subscript position of the ing is S1, then S1 = S %. len,. len indicates the length of array A. The operation is A [I]. style. backgroundColor = B [j].


However, this is still not a reasonable clue, because the next loop cannot be done, because the problem is that the subscript I, if the value of I is 0, is equivalent to the end of this loop! But we thought again, I = S1 = S % A. len, then, why doesn't we use S to represent I ?, Set I = S to A [I % A. len]. style. backgroundColor = B [j].

The process is as follows:

For (var I = S, j = 0; I> = 0; I --, j ++ ){

If (j <B. len ){

A [I % A. len]. style. backgroundColor = B [j];

} Else {

A [I % A. len]. style. backgroundCOlor = '# ccc'; // default color

}


(2) If array B is traversed, as shown in:


After analysis, when S> (. len + B. len-1), that is, when S grows to the length of A and B, the ing just completes ing all B, indicating that this round is over.

The result is as follows:

If (S> (A. len + B. len-1 ){

// End and start a new round

S = S % A. len;

}

It seems that the analysis is over now, but after running it, I found that after a round, I did not get the correct running result. Why? Because the value of I is always decreasing and reduced to 0, the color mapped to the past is overwritten by the default color. So how do we know where to stop? That is, how do we know which part is mapped? In the above two figures, there is an E mark, which indicates the position where I ends. E is calculated as follows:

When the graph is in the (1) status, E = S % A. len + 1 = 5% 5 + 1 = 1

When (2), E = 0, why is it = 0, not the same as (1? The answer is that the end is reached and the start is over. E is 0 of course!

But you may still have doubts. What about normal conditions? Is the formula still correct? Normally, the value of E is still 0, because S does not exceed the length of array A. When only S exceeds the length of A, it is mapped, E will be moved. When the ing ends, that is, the final state, E also needs to return to the normal state, that is, 0.

Therefore, the Code is as follows. Here I also add a control button to facilitate viewing various processes:

<Pre name = "code" class = "html"> <! DOCTYPE html> 




The effect is as follows:


Note that this ing method has its limitations, that is, the length of array A cannot be smaller than the length of array B. Otherwise, the ing length is insufficient, which may cause repeated overwrites!


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.