prime numbers ccounter

Moderators: Disciple, zlovatt

Post Reply
dvanw
Posts: 3
Joined: June 22nd, 2021, 4:13 am

Hello !
I've been tryiong to make a simple integer counter with the prime numbers being displayed in a specific color. I'm not a coder, and I had already some trouble discovering the syntax I need to do it. But' I'm afraid I've run into a more srieus trouble, because I can't find a way to incrmement my "i" variable wich is supposed to track the progress in the primes array.

Some help wpould be (obviously) greatly appreciated !

Denis van W.
vimeo.com/dvanw

Code: Select all

P = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149] ;

t = (time*25).toFixed(0);

if (t==0){
	i=0 ;
}

if (t==P[i]){
	i=i+1;
	text.sourceText.createStyle().setFontSize(72).setFillColor([1,0,1]).setText(t);

}else{
	text.sourceText.createStyle().setFontSize(72).setFillColor([1,1,1]).setText(t);
}
crossrad
Posts: 9
Joined: May 1st, 2021, 1:36 pm
Contact:

Are you trying to write an expression for the colour of the counter, for example to use in the "Change to Color" effect, or to write a script that will set keyframes for the color and value of a text layer? I ask because this is the "Expressions" area of the forum but setting attributes such as fill color is something you would do in a script?

dvanw
Posts: 3
Joined: June 22nd, 2021, 4:13 am

I'm trying to make a counter whose color will change when the number dispalyed is prime. The best way I've found to do that is to check if the number is part of an array where I'll have all the primes from 2 to1000, for instance.
I'm not sure I understand the distinction you're doing between expression and script... I have some limited knowledge of AE expressions but don't know what you mean by "script"...

Thanx for yoy response anyway !
Denis van W.

dvanw
Posts: 3
Joined: June 22nd, 2021, 4:13 am

I made some progress in my knowledge of the expressions and javascript syntax.... But I'm still stucked...

Code: Select all

P = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149] ;

t = (time*25).toFixed(0);

	if (P.includes(t)){
		text.sourceText.createStyle().setFontSize(72).setFillColor([1,0,1]).setText(t);
	}else{
		text.sourceText.createStyle().setFontSize(72).setFillColor([1,1,1]).setText(t);
	}
crossrad
Posts: 9
Joined: May 1st, 2021, 1:36 pm
Contact:

I think you can do what you want with expressions using a text layer which shows the frame number and then add an effect "Change to Color" where the "To" color is:

Code: Select all

P = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149] ;

t = timeToFrames(t = time + thisComp.displayStartTime, fps = 1.0 / thisComp.frameDuration, isDuration = false);

P.includes(t) ? [1, 0, 0, 1] : [1, 1, 1, 1];

You need to set "Change" to "Hue, Lightness % Saturation" and "Change By" to "Transforming To Color".

I used the official way of getting the frame number which you can find from the arrow symbol next to the pickwhip -> Global.

I found that having a loop to test for primes rather than searching a precalculated array ran fast enough. In the attached file, "ColPrimes 3" uses the array and "ColPrimes 2" computes them.

Attachments
ColourPrimes.zip
(11 KiB) Downloaded 397 times
Post Reply