# Golfing Task #4 - Reducing Radar

**URL:** <https://forum.electromage.com/t/golfing-task-4-reducing-radar/1019>\
**Category:** Pixelblaze Academy of Wizardry and Enchantment\
**Created:** [February 20, 2021, 11:50am UTC](https://forum.electromage.com/t/golfing-task-4-reducing-radar/1019 "2021-02-20T11:50:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [February 20, 2021, 11:50am UTC](https://forum.electromage.com/t/golfing-task-4-reducing-radar/1019/1 "2021-02-20T11:50:12Z")

</div>

Use this for discussion of advanced techniques for [Task #4.](https://forum.electromage.com/t/task-4-on-your-radar/1018)

And for finding as short a solution as possible.

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [February 22, 2021, 8:44pm UTC](https://forum.electromage.com/t/golfing-task-4-reducing-radar/1019/2 "2021-02-22T20:44:24Z")

</div>

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

```auto
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)
}

```

---

<div class="post-metadata">

**Author:** ![jeff](https://forum.electromage.com/user_avatar/forum.electromage.com/jeff/32/3473_2.png) [@jeff](https://forum.electromage.com/u/jeff)\
**Post date:** [February 23, 2021, 1:42am UTC](https://forum.electromage.com/t/golfing-task-4-reducing-radar/1019/3 "2021-02-23T01:42:48Z")

</div>

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

```javascript
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:

```javascript
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)
}

```

![ezgif.com-gif-maker](https://forum.electromage.com/uploads/default/original/1X/52760b3e520541c24c08c7f7e64af76c0bfd8d34.gif)

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [February 23, 2021, 2:09am UTC](https://forum.electromage.com/t/golfing-task-4-reducing-radar/1019/4 "2021-02-23T02:09:36Z")

</div>

Nice. I’ll have to walk thru how that works.

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [February 23, 2021, 2:14am UTC](https://forum.electromage.com/t/golfing-task-4-reducing-radar/1019/5 "2021-02-23T02:14:14Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [February 24, 2021, 1:48am UTC](https://forum.electromage.com/t/golfing-task-4-reducing-radar/1019/6 "2021-02-24T01:48:36Z")

</div>

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”?

---

<div class="post-metadata">

**Author:** ![Scruffynerf](https://forum.electromage.com/letter_avatar_proxy/v4/letter/s/34f0e0/32.png) [@Scruffynerf](https://forum.electromage.com/u/Scruffynerf)\
**Post date:** [February 24, 2021, 2:44am UTC](https://forum.electromage.com/t/golfing-task-4-reducing-radar/1019/7 "2021-02-24T02:44:57Z")

</div>

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.
