-
1 Attachment(s)
Weird Plasma
I am having a strange problem. I am using a plasma function in VB, and it works great, but it is mush to slow. So, I tried to convert it into C++, but the function seems to be returning incorrect values. I have attached an image of just how odd it looks. The function is this:
Code:
32 + 63 * fabs(sin(hypot(400 - j, 400 - i) / 72) + cos(0.5 * 13 * sin(i / 65) + sin(j / 50)));
Any help is appreciated.
Z.
-
what does the vb version look like?
-
1 Attachment(s)
Like this, only bigger...
Z.
-
if i and j are integers (short/int/long), it could be due to integer division problems.
try this code:
Code:
32 + 63 * fabs(sin(hypot(400 - j, 400 - i) / 72) + cos(0.5 * 13 * sin(i / 65.0) + sin(j / 50.0)));
note that I used 65.0 and 50.0 at the end of the line, thus the values are of type double and i/j are converted to double too. If you wouldn't do that, for example if i was < 65 sin and j < 50, it would always result in 0, thus the multiplication would result in 0, and the cosine would always be 1. This woul make for the lines in the jpg. (maybe)
VB automatically uses floating point numbers in divisions, C does not, 64 / 65 = 0
All the buzzt
CornedBee
-
Thanks CornedBee. That is very probably it =).
Jim, just copy the function I posted in the first post, and define a 2D array, about 1100x1100, and use a nested loop and run the i and j values through the function above. Then, loop though that array, and use RGB(v(i,j), v(i,j), v(i,j)) to get a greyscale version.
To get the effect i posted, create a second array of the same size, and loop though and use the function "64 + 63 * (sin(hypot(550 - i, 550 - j)))" to get the color, and when you go to set the pixels, just add the two values. The function "hypot(x, y)" is defined as "sqrt(x^2 + y^2)".
Z.