# Golfing Task #4 - Reducing Radar

Use this for discussion of advanced techniques for Task #4.

And for finding as short a solution as possible.

Iâ€™m going to have a try at this from several different angles this week - hereâ€™s something short and simple to start with.

``````var limiter = 0.04;
var t1;

export function beforeRender(delta) {
// generate sawtooth wave for timing and reshape it to a
// curve for better contrast between low and high.
t1 = time(.015)
t1 = t1 * t1 * t1;

// the 'limiter' variable lets us light a small
// area in the center of the strip while our pulse
// is growing, then as it nears maximum brightness,
// we let 'limiter' grow so the lighted region expands
// towards the ends of the strip.
limiter = (t1 > 0.6) ? t1 / 1.6 : 0.04;
}

export function render(index) {
// calculate the current pixel's distance from center
v = abs(0.5 - (index/pixelCount));
// limiter controls how big an area around the center
// we light up.  Smaller values mean a smaller region
v = (v < limiter) ? 1-(v / limiter) : 0;

// multiply by our timer for pulsing effect, and
// gamma correct.
v = t1 * v * v * v;

// display in a 1950s radar-ish looking palette
hsv(0.5+v, 1-v,v)
}
``````

Here goes! I feel I am beating @zranger1 on obfuscation

``````export function render(index) {
if (index < pixelCount / 2) index = pixelCount - index
p = index / pixelCount
v = p - time(.05)
v = 10 * v % 1 * square(v, .1)
hsv(.3, 1, v * v * v * (1 - p))
}
``````

or, visually similar:

``````export function render(index) {
p = triangle(index / pixelCount)
v = ((1 - p) / 2 - 2 * time(.1) + 1) % 1 * 6 - 5
hsv(.3, 1, v * v * v * p * p)
}
``````

2 Likes

Nice. Iâ€™ll have to walk thru how that works.

I really like the use of the square wave to limit which pixels can be turned on. Thatâ€™s a trick Iâ€™ll definitely be borrowing in the future!

Iâ€™m not sure exactly how to organize this, but I think we ought to collect the information we develop in these golfing topics and other places where people are playing with code and post it as â€śLoreâ€ť or â€śCollected Wisdomâ€ť, or â€śHandy Stuff to Knowâ€ť, or something.

Beyond basic coding, thereâ€™s a lot of information here that would be helpful to everyone. For example, as a newcomer looking at the discussion & code for the last couple of exercises, I might like to know:

• Okâ€¦ so, everything is a traveling wave of some sort, and we tend to iterate over a frame buffer only as a last resort. Why? How do I control the timing and size of my waves? What are some common idioms?
• In many cases, we donâ€™t bother truncating 16.16 numbers when an integer is wanted (say, an array index!) Why does this work? When would you have to truncate?
• There are other circumstances in which we just pass numbers to functions, knowing that the system will perform the desired modulo arithmetic. Is this documented anywhere? Are there exceptions?
• What the heck is a 16.16 number anyway? Why is that important? What are the benefits and limitations?
• Why HSV instead of good old RGB?
• WTF is Rule 30?

What do you think? Is this worth topic in the â€śPixelblaze Academyâ€ť?

Yes to all of thoseâ€¦

As for the Wit and Wisdom of Golfing/etc, I was planning on collating the bits in here, because you are correct, so much good stuff.

1 Like