# My code for mapping spokes of a wheel if anyone would like it

We don’t really have a place / way to share mappings as far as I can tell. I thought I’d share my mapping code I came up with when working on an idea to have a lights running down the spokes of a garden umbrella 2D mapped. My other half was not a fan of the concept and given how much work it was going to be it never progressed beyond code. But maybe it will be useful to somebody else.

The code allows for any number of spokes to be added by changing the sparCount variable at the top. Obviously the pixelCount should really be a multiple of the spar count although the code doesn’t check for that - but in real life it would be really.

Anyway - here’s the code. Let me know if anybody does use it in anger - I’d love to see a 2D mapped umbrella.

``````function (pixelCount) {
sparCount = 8
map = [];
for (i = 0; i < pixelCount; i++) {
pixel = i + 1
spar = Math.floor((i)/(pixelCount/sparCount))+1
sparPixel = pixel-(spar-1)*(pixelCount/sparCount)
theta = (spar-1) * (360/sparCount)
distance = 1/(2*pixelCount/sparCount+1)*sparPixel
x = 0.5 + distance * Math.sin(theta * Math.PI / 180)
y = 0.5 + distance*Math.cos(theta * Math.PI / 180)
map.push([x,y])
}
return map
}
``````
6 Likes

Unable to edit the original post(?) Tidied up the code a little to remove my odd little +1 and then -1 everywhere…

``````function (pixelCount) {
sparCount = 8
map = [];
for (i = 0; i < pixelCount; i++) {
pixel = i + 1
spar = Math.floor((i)/(pixelCount/sparCount))
sparPixel = pixel-(spar)*(pixelCount/sparCount)
theta = (spar) * (360/sparCount)
distance = 1/(2*pixelCount/sparCount+1)*sparPixel
x = 0.5 + distance * Math.sin(theta * Math.PI / 180)
y = 0.5 + distance*Math.cos(theta * Math.PI / 180)
map.push([x,y])
}
return map
}
``````
3 Likes

Thank you for sharing this.

So I immediately thought of adapting this for some kind of Christmas star… Now to see if I can do something with it.

1 Like