How to create pixel gradient with attractor curves? As shown in the image. Thanks in advance.

pixel gradient.gh (10.7 KB)

Pixel Gradient.3dm (101.9 KB)

How to create pixel gradient with attractor curves? As shown in the image. Thanks in advance.

pixel gradient.gh (10.7 KB)

Pixel Gradient.3dm (101.9 KB)

You cannot make bitmaps by settings individual pixels in GH without at least a plugin, but there’s an imaging plugin which allows you to draw shapes on bitmaps, and of course you can create coloured points or meshes.

In either case what you need is the following steps:

- For each coordinate/pixel measure the distance to the attractor curve (or the nearest attractor curve if you have more than one). This will give you numbers between d_{min} and d_{max}.
- Create a numeric domain, either (d_{min}, d_{max}), or maybe (0, d_{max}), or maybe even (a, b) if you want full control over the distance falloff. You then remap all your measured distances from that domain to the unit interval (0,1). This basically allows you to ‘normalise’ your distances. You can also choose to ‘clamp’ your values to be exactly within the unit interval, but you don’t have to.
- Generate a list of random numbers with the same length as your normalised distances. The random domain will be (-x, +x), with x being a smallish number, probably something like 0.1 or 0.2 based on the image you posted.
- Add the random noise to all your normalised distances.
- Multiply the randomised data by the number of distinct colours you want minus one (seems like your image has 5 colours), then round them to the nearest integer. At this point you definitely want to make sure that you don’t have any integers outside the (0, 4) range, which is possible if your noise is strong.
- Use these integers to pick a colour from your palette
`(black, darkgrey, grey, lightgrey, white)`

and assign to the relevant point/object.

A completely different approach might be:

- Measure the distances from all coordinates to the attractor (same as before).
- Sort these distances from small to large while synchronously sorting the list of coordinates. At this point the first coordinate in the list is the one closest to the attractor, and the last coordinate will be the one furthest away.
- Jitter your coordinates now using some small factor, roughly equivalent with the noise strength from the previous method. This shuffles them back and forth a bit, and the stronger the jitter strength the more a point is allowed to move within the list.
- Now break your list into n equal parts, where n is the number of colours you have.
- Assign each colour to all the items in the appropriate sublist.

1 Like