Results 1 to 5 of 5

Thread: Weird Plasma

  1. #1
    Zaei
    Guest

    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.
    Attached Images Attached Images  

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    what does the vb version look like?

  3. #3
    Zaei
    Guest
    Like this, only bigger...

    Z.
    Attached Images Attached Images  

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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

  5. #5
    Zaei
    Guest
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width