I’m newbie programmer and am learning JavaScript so I can program the PixelBlaze. Actually, I’m trying to learn how to program it by studying the patterns that Ben provided. I can read most of it now, but there’s a couple lines Here and there that I’m not clear about. If anyone could illuminate me,I’d appreciate it.
My understanding of modulus, x % y , is that it is the remainder after division of x by y. It would follow that if x is an integer and y is 1 then x % 1 would always be 0, and if x < 1 then x % 1 = x. Am I missing something, or is this the point?
Ben uses this, for instance in the pattern for “fast Pulse” where he defines v = triangle((2*wave(t1) + index/pixelCount) % 1). Can someone explain what the modulus does here, what’s its purpose?
Also in “Fast Pulse”, he defines another variable as
S = v < .9 followed immediately by the hsv function
hsv(t1,s,v).
I understand < to be a logical operator, but I don’t understand what happens if it is true or false. I’m guessing that if v < .9 is true, then s = v, if it is false, then s doesn’t change and in this case is undefined and Thus s = 0. Am I close?
And, finally, in Color Twinkle Bounce, he has this line:
a = (a> .1 ? a : 0)
I don’t have a clue how to understand this line. I can’t seem to find what the ? character means and I think the colon refers to an object literal, but don’t understand what that is. This might be too hard to explain to a novice programmer here in the forum, but if you give me some clues I can go read about it elsewhere. Like, what is he trying to accomplish here?
Questions aside, I’m really impressed with how simple these programs are considering how beautiful and complex the resulting patterns are. I’ve never appreciated the beauty of math so much and I’m hungry to learn more.