Plasma effect: Difference between revisions

Added ASCII and Graphics implementations in C.
(added ceylon)
(Added ASCII and Graphics implementations in C.)
Line 12:
* [http://www.bidouille.org/prog/plasma Plasma (bidouille.org)]
<br><br>
=={{header|C}}==
===ASCII version for Windows===
If you don't want to bother with Graphics libraries, try out this nifty implementation on Windows :
<lang C>
/*Abhishek Ghosh, 4th October 2017*/
 
#include<windows.h>
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<math.h>
 
#define pi M_PI
 
int main()
{
CONSOLE_SCREEN_BUFFER_INFO info;
int cols, rows;
time_t t;
int i,j;
 
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
cols = info.srWindow.Right - info.srWindow.Left + 1;
rows = info.srWindow.Bottom - info.srWindow.Top + 1;
HANDLE console;
console = GetStdHandle(STD_OUTPUT_HANDLE);
system("@clear||cls");
srand((unsigned)time(&t));
for(i=0;i<rows;i++)
for(j=0;j<cols;j++){
SetConsoleTextAttribute(console,fabs(sin(pi*(rand()%254 + 1)/255.0))*254);
printf("%c",219);
}
getchar();
return 0;
}
</lang>
===Graphics version===
And here's the Graphics version, requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library. Prints out usage on incorrect invocation.
<lang C>
/*Abhishek Ghosh, 4th October 2017*/
 
#include<graphics.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
 
#define pi M_PI
 
void plasmaScreen(int width,int height){
int x,y,sec;
double dx,dy,dv;
time_t t;
initwindow(width,height,"WinBGIm Plasma");
while(1){
time(&t);
sec = (localtime(&t))->tm_sec;
for(x=0;x<width;x++)
for(y=0;y<height;y++){
dx = x + .5 * sin(sec/5.0);
dy = y + .5 * cos(sec/3.0);
dv = sin(x*10 + sec) + sin(10*(x*sin(sec/2.0) + y*cos(sec/3.0)) + sec) + sin(sqrt(100*(dx*dx + dy*dy)+1) + sec);
setcolor(COLOR(255*fabs(sin(dv*pi)),255*fabs(sin(dv*pi + 2*pi/3)),255*fabs(sin(dv*pi + 4*pi/3))));
putpixel(x,y,getcolor());
}
delay(1000);
}
}
 
int main(int argC,char* argV[])
{
if(argC != 3)
printf("Usage : %s <Two positive integers separated by a space specifying screen size>",argV[0]);
else{
plasmaScreen(atoi(argV[1]),atoi(argV[2]));
}
return 0;
}
</lang>
=={{header|C++}}==
[[File:plasma.png]]
503

edits