Hi,
I tried to run
PixelToaster on
Visual C++ 2005 Express and to test it I ported a nice
effect from a java applet to C++. To make it a bit smoother I added a little gradient to the fx.
However, don't applaud me for the original fx because it is not mine (unfortunately

)...
Use your mouse to change the effect.
Here's the code
/******************************************************
/*** Hypnosis FX
/***
/*** original java version by Mario Klingemann
/*** converted to pixeltoaser and added a gradient fx
/***
/*** benny!weltenkonstrukteur.de in 2oo6
/******************************************************/
#include "PixelToaster.h"
#include <math.h>
using namespace PixelToaster;
class Hypnosis : public Listener
{
public:
Hypnosis()
{
quit = false;
}
int run()
{
// open display
const int width = 400;
const int height = 200;
const float PI = 3.14159265;
vector<Pixel> pixels( width * height );
int w2=width/2;
int h2=height/2;
int w1=width-1;
int h1=height-1;
float maxdist=sqrt((float)(h2*h2+w2*w2));
float dx,dy,angle,dist = 0.0f;
int d,p = 0;
float c = 600.0f;
float w = 0;
if ( !display.open( "Hypnosis. (Move your mouse)", width, height ) )
return 1;
// register listener
display.listener( this );
// keep updating the display until the user quits
while ( !quit )
{
clear ( pixels );
c+=(dxMouseY-h2)/32.0;
w=4.0+(dxMouseX/5.0);
for (int y=0;y<height;y++){
dy=float(h2-y);
for (int x=0;x<width;x++){
dx=float(w2-x);
angle=c+atan2(dy,dx)*w/PI;
dist=sqrt(dx*dx+dy*dy);
d=int((angle+dist)/w);
if (( d & 1 )==1){
//pixels[x+y*width] = white;
pixels[x+y*width].r = 0.05f + (x + y) * 0.0025f;;
pixels[x+y*width].g = 0.05f + (x + y) * 0.00125f;
pixels[x+y*width].b = 0.08f + (x + y) * 0.008f;
}
}
}
display.update( pixels );
}
return 0;
}
protected:
void onMouseMove( Mouse mouse )
{
dxMouseY = mouse.y;
dxMouseX = mouse.x;
}
void onClose()
{
quit = true;
}
private:
Display display;
bool quit;
float dxMouseX, dxMouseY;
void clear( std::vector<Pixel> & pixels )
{
for ( unsigned int index = 0; index < pixels.size(); ++index )
{
pixels[index].r = 0.0f;
pixels[index].g = 0.0f;
pixels[index].b = 0.0f;
}
}
};
int main()
{
Hypnosis hypnosis;
hypnosis.run();
}


