Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: benny! on November 21, 2006

Title: [PixelToaster] Hypnosis
Post by: benny! on November 21, 2006
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
Code: [Select]
/******************************************************
/*** 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();
}

Title: Re: [PixelToaster] Hypnosis
Post by: rdc on November 21, 2006
I'm getting very, very sleepy... :) Looking good. Is PixelToaster an improvement over TinyPTC?
Title: Re: [PixelToaster] Hypnosis
Post by: benny! on November 21, 2006
.... Is PixelToaster an improvement over TinyPTC?

Not really imho. It's redesigned for C++ and supports now floating-point colors e.g.

 ::)

Quote
I'm getting very, very sleepy...

Glad the effect works ... ;)
Title: Re: [PixelToaster] Hypnosis
Post by: Shockwave on November 21, 2006
Nice effect Benny :)

I think that Pixeltoaster is a directx version of tinyptc, someone will corrrect me if I am wrong :)
Title: Re: [PixelToaster] Hypnosis
Post by: Jim on November 21, 2006
PixelToaster is a cool name.:D  It supports a couple of platforms and handles some good things like colour conversion and whatnot, which might or might not be handy.  Thing is, our PTC library is probably about as efficient as it can get, so I expect PixelToaster is no faster.  There's no magic bullet over and above what PTC does for speed without using hardware rendering.

Jim
Title: Re: [PixelToaster] Hypnosis
Post by: rdc on December 11, 2006
Benny,

Could you explain how you set up PixelToaster in VC++ Express? I would like to play with this, but I can't seem to get it working. Thanks!
Title: Re: [PixelToaster] Hypnosis
Post by: benny! on December 12, 2006
Benny,

Could you explain how you set up PixelToaster in VC++ Express? I would like to play with this, but I can't seem to get it working. Thanks!

I remember having some trouble getting it to work as well. Unfortunately I am at work right now ...
But as soon as I am back home I look at the project settings and try to explain how to set it up!!!
Title: Re: [PixelToaster] Hypnosis
Post by: rdc on December 12, 2006
Thanks man. It looks like it uses D3D, so I guess I'll need to d/l the sdk for that.
Title: Re: [PixelToaster] Hypnosis
Post by: benny! on December 12, 2006
Thanks man. It looks like it uses D3D, so I guess I'll need to d/l the sdk for that.

Definately you need D3D for Pixeltoaster. But it is worth the download - a lot
of other frameworks uses at least some of the libs. More info's when I am back
home...

[ Cannot promise to be online tonight ... I am invitied for dinner later on ... so
maybe I am back tomorrow evening ... sorry for the delay ;) ]
Title: Re: [PixelToaster] Hypnosis
Post by: rdc on December 12, 2006
No problem, and no rush. Whenever you get to it.
Title: Re: [PixelToaster] Hypnosis
Post by: benny! on December 13, 2006
@rdc:

When you downloaded the D3D SDK you can try the attached project. I packed the whole hypnosis project. Guess
that's the easiest way to compare any project settings and stuff. If you have any particular question then just ask,
mate. I help where I can ...
Title: Re: [PixelToaster] Hypnosis
Post by: benny! on December 13, 2006
Oops .. just realized that the packed file was too big. I temporarily uploaded it. You can download it
here :

www.weltenkonstrukteur.de/ext/Hypnosis-Prj.rar (http://www.weltenkonstrukteur.de/ext/Hypnosis-Prj.rar)

(this download link is temporary and will be just active within the next two weeks or so ... )
Title: Re: [PixelToaster] Hypnosis
Post by: rdc on December 13, 2006
I got it. Thanks a bunch. I'll d/l the SDK and try it out.
Title: Re: [PixelToaster] Hypnosis
Post by: rdc on December 13, 2006
Benny, just wanted to let you know I got it running. Thanks for the help.
Title: Re: [PixelToaster] Hypnosis
Post by: benny! on December 13, 2006
Benny, just wanted to let you know I got it running. Thanks for the help.

Cool - glad to hear that ... have fun with it !!!