Blitz Sin() function acting funky  


👉 BlitzCoder will be building a new platform and other plans to preserve and continue the Blitz legacy.

To be able to achieve this goal, we need your support by becoming a Patreon Paid Member 👈

 

Tweet
kerblitz32

Hi all.

I'm trying to semi-follow the tutorials from this site but in Blitz3D since my Code::Blocks and C and compilers and everything are all messed up, but mainly just to learn the math behind the cool graphics patterns I see.

I'm trying to translate the very first code snippet from the tutorial into BlitzBASIC:

int main(int argc, char *argv[])
{
  screen(256, 256, 0, "Plasma");

  for(int y = 0; y < h; y++)
  for(int x = 0; x < w; x++)
  {
    int color = int(128.0 + (128.0 * sin(x / 8.0)));
    pset(x, y, ColorRGB(color, color, color));
  }
  redraw();
  sleep();
  return(0);
}

This is what I ended up with in BlitzBASIC:

w = 256
h = 256

col% = 0

Graphics w,h,0,2

    For y = 0 To h
        For x = 0 To w
            col% = Int(128 + (128 * (Sin(x/8.0)))
            Color col%,col%,col%
            Plot x,y
        Next
    Next

While Not KeyHit(1)

Wend

This is what I'm expecting to see in my output:

But instead I get this:

I bet it probably has something to do with some weird stipulation of the Sin() function in BlitzBASIC, but after reading through the documentation I can't see why it's not working.

I could also very well have done something stupid that I'm just not seeing here and one of you guys will.

Either way, thanks for the help!

  kerblitz32 commented:

Changing the Sin(x/8.0) to Sin(x*8.0 and adding some checks to the color value fixed it. What a weird problem! I'm sure there's some reason why that fix worked but I'm too tired to check right now.

Reply To Topic (minimum 10 characters)

Please log in to reply