back

by epaga·3y ago·view on hn ↗
Not having much of an idea what I was looking at there, I asked GPT-4 to explain this to me. Quite helpful (though it didn't seem to know what "pn" was for)

----

This K program appears to be defining three functions (point, line, and draw) that are related to drawing a mathematical pattern.

point function: point: {(y;pn[f%20;0.3x;0.1y]-18sin ypi%100)} This function takes two arguments: y and a variable function pn[f%20;0.3x;0.1y]. The function computes a value based on these arguments and returns the result. The expression (f%20;0.3x;0.1y) inside the pn function seems to generate new values for x and y based on the input x and y. The final result is multiplied by -18 sin(y * pi % 100), which can create interesting patterns depending on the input values.

line function: line: {((30;x)+)'point[x]'!100} This function takes a single argument, x, and computes the result of the point function for 100 evenly spaced values of y in the range 0 to 1 (by indexing the point function with x and each value in the range '0 to 99'). The results are then shifted by (30; x) to create a new set of coordinates. The function returns a list of these transformed coordinates.

draw function: draw: {,(,/line'38+6*!16;cga;1)} This function generates a sequence of 16 values (from 0 to 15) and multiplies each by 6, then adds 38. It then computes the line function for each of these values and concatenates the results. The final expression (cga; 1) seems to be related to the color or other visual properties of the pattern, but it is not clear from the given code snippet how it is being used.

Overall, this K program appears to be generating a list of coordinates for a complex pattern by applying transformations to a series of points. The specific pattern depends on the input values and the function pn, which is not fully defined in the provided code snippet.

2 comments
pn is perlin noise. It's not part of the k standard, but provided by the iKe environment here. iKe is also providing 'f' which is the frame counter, and pi which is obviously pi.

It's a bit confused by the first function. It takes two arguments, x and y, and returns a tuple. The first value is 'y' and the second value is (sin(pi % 100 * y) * -18) * perlinNoise(frameNumber % 20, 0.3 * x, ), 0.1 * y). I might be a little off on that formula, it's been awhile since I've read k code.

> The function computes a value based on these arguments and returns the result

The Eternal September of AI has come earlier than expected.