From:
https://rosettacode.org/wiki/Plasma_effectLooking at the code examples for this rosetta code task, FreeBASIC took their program and converted it over from
https://lodev.org/cgtutor/plasma.html. To help showcase how similar the various BASICs are that are out there, I decided to do the same and translate the last demo from that website over into QB64 for everyone.
'converted from https://lodev.org/cgtutor/plasma.html, last example
CONST wide
= 256, high
= 256
t = timeGetTime / 50 't + .99
v
= SIN(Dist
(x
+ t
, y
, 128, 128) / 8) _
+ SIN(Dist
(x
, y
, 64, 64) / 8) _
+ SIN(Dist
(x
, y
+ t
/ 7, 192, 64) / 7) _
+ SIN(Dist
(x
, y
, 192, 100) / 8)
Dist##
= _HYPOT(x1
- x2
, y1
- y2
) 'Dist = SQR((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))
For whatever reason, I can generate the same pattern that the website has as their image, but I'm generating a different palette. They're creating red and blue, mine is creating green and blue. I imagine the problem is somewhere in their call to ColorRGB, since all the rest of the examples on page use some sort of color palette with that custom function, but I wouldn't swear to it...
Honestly, I don't even see how the BLEEP the final example on the page works at all, the way it's written!
#define dist(a, b, c, d) sqrt(double((a - c) * (a - c) + (b - d) * (b - d)))
int main(int argc, char *argv[])
{
screen(256, 256, 0, "Plasma");
double time;
while(!done())
{
time = getTime() / 50.0;
for(int y = 0; y < h; y++)
for(int x = 0; x < w; x++)
{
double value = sin(dist(x + time, y, 128.0, 128.0) / 8.0)
+ sin(dist(x, y, 64.0, 64.0) / 8.0)
+ sin(dist(x, y + time / 7, 192.0, 64) / 7.0)
+ sin(dist(x, y, 192.0, 100.0) / 8.0);
int color = int((4 + value)) * 32;
pset(x, y, ColorRGB(color, color * 2, 255 - color));
}
redraw();
}
return(0);
}
Where do we define w and h at? Or ColorRGB? What the heck is getTime? I don't know and can't find reference to any sort of C++ function with that name at all. The closest I can get is to go with timeGetTime() which gives us seconds since windows started. (Note that getTime isn't the same thing as gettime. C is case sensitive.)
If anyone has a clue about how to correct the color palette to match this demo, I'd love to see it. Otherwise, this is about as close as I can get to what they've posted on their website, with the link here:
https://lodev.org/cgtutor/plasma.htmlI've never added code to Rosetta Code before, but since I was looking at Ashish's example earlier, I thought it might be something which somebody might want to add for us. For anyone who edits and adds code to RC, feel free to add the above (or Ashish's) onto the site so we'll be represented there forever more. :)