First idea, I could create a white line and empty image I. Then to go through loop with angle from 0 to 89, in every iteration do I++; and angle++; rotate this line with fixed origin at x=radius, y=0; This would create one image of gradient. Then I need to copy the image 3 times in a loop rotating it +90° in every iteration.

Now I ask what functions to use to copy the pixels from the original line to the image using rotation and how to do the same with an image. It's basically the same difference is only in image dimensions. That line is radius,0 and image dimensions are radius*2,radius,2

Yeah, but I need mathematical accurancy. If you use image editor you can see the image is blured in the 358-359° and that is problem. I can correct it in image editing software but it would be useless when I would use it as a build in solution. I have done recalculation for the smallest image (my question been updated). Just it is not perfect because I used floats and divisions of floats so it was a bit complicated.

Blur/slice at 360º slice is a known problem which has been tried to be solved (with not much success - #6189, #6206). You'll have to find a workaround for your exact problem. Anyway, imho, trying to achieve mathematical accuracy in a circular gradient of 255 levels but 12px radius (i.e. 75.398 px perimeter length) is quite strange/difficult...at least working with 1-pixel accuracy.

I would use the function cv::line. It draws a line between two points. So you set the first point to the center of the circle, and calculate 256 points along the edge of the circle. Then you draw a line between the center and each of those points with a steadily increasing value for the color parameter. You can change the thickness if the radius is too large for thickness one.