# KITT without arrays

@zranger1 got a proof of concept for this going in this thread.

I took a shot at this today and got something workable. Sorry I’m lazy and didn’t add nice UI controls

``````var tailPct = .6 // length of the tail in 0..1
var t1, shift = 1 - tailPct

export function beforeRender() { t1 = time(.05) }

function pulse(x) {
var halfsaw = triangle(x - t1) * square(x - t1, .5)
return max(0, (halfsaw - shift) / tailPct)
}

export function render(index) {
pct = index / pixelCount / 2
v = pulse(pct) + pulse(-pct)
hsv(0, 1, v * v * v)
}
``````

Interestingly, original KITT is about 1.6x faster.

2 Likes

I feel like golfing this could end with a super minimal KITT.

And now I’m curious to see a mapped arrayless KITT too. But the array is otherwise useful (it’s a cheap framebuffer approach, which can be handy for all sorts of stuff) so lots of ways to do the same thing.

Ok, golfed mapped arrayless version (with sliders and exports for exploration):

``````export var tailPct = .6 // length of the tail in 0..1
export var speed = .05
export var pct1
export var pct2

export function sliderTail (v) {
tailPct = .6 + v/3;
}

export function sliderSpeed (v) {
speed = v/10;
}

export function render2D(index,x,y) {
pct1 =  y/2 - time(speed)
pct2 = -y/2 - time(speed)
v = max (0,( tailPct - 1 + triangle(pct1) * square(pct1,.5) ) / tailPct )
+ max (0,( tailPct - 1 + triangle(pct2) * square(pct2,.5) ) / tailPct )
hsv(0, 1, v * v * v)
}
``````

that’s running at 69+ FPS on my v3 with a 16x16 matrix

to compare:
Original KITT runs at 79 FPS
Mapped Array KITT runs at 80 FPS

So the array approach is slightly faster… but… even changing it from `v*v*v` to `v*v` adds a frame or 2 back. But still, that’s only a 15% difference in speed. You’ve entirely eliminated any arrays, pure math/waves, so it’s a bit slower but uses MUCH less memory.

1 Like

Very nice! No arrays, just math!

1 Like