Author Topic: [PixelToaster] Hypnosis  (Read 1963 times)

0 Members and 1 Guest are viewing this topic.

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4365
  • Karma: 226
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
[PixelToaster] Hypnosis
« 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();
}

« Last Edit: November 21, 2006 by benny! »
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1480
  • Karma: 139
    • View Profile
    • Clark Productions
Re: [PixelToaster] Hypnosis
« Reply #1 on: November 21, 2006 »
I'm getting very, very sleepy... :) Looking good. Is PixelToaster an improvement over TinyPTC?

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4365
  • Karma: 226
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [PixelToaster] Hypnosis
« Reply #2 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 ... ;)
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17294
  • Karma: 489
  • evil/good
    • View Profile
    • My Homepage
Re: [PixelToaster] Hypnosis
« Reply #3 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 :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5243
  • Karma: 393
    • View Profile
Re: [PixelToaster] Hypnosis
« Reply #4 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
Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1480
  • Karma: 139
    • View Profile
    • Clark Productions
Re: [PixelToaster] Hypnosis
« Reply #5 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!

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4365
  • Karma: 226
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [PixelToaster] Hypnosis
« Reply #6 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!!!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1480
  • Karma: 139
    • View Profile
    • Clark Productions
Re: [PixelToaster] Hypnosis
« Reply #7 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.

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4365
  • Karma: 226
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [PixelToaster] Hypnosis
« Reply #8 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 ;) ]
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1480
  • Karma: 139
    • View Profile
    • Clark Productions
Re: [PixelToaster] Hypnosis
« Reply #9 on: December 12, 2006 »
No problem, and no rush. Whenever you get to it.

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4365
  • Karma: 226
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [PixelToaster] Hypnosis
« Reply #10 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 ...
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4365
  • Karma: 226
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [PixelToaster] Hypnosis
« Reply #11 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

(this download link is temporary and will be just active within the next two weeks or so ... )
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1480
  • Karma: 139
    • View Profile
    • Clark Productions
Re: [PixelToaster] Hypnosis
« Reply #12 on: December 13, 2006 »
I got it. Thanks a bunch. I'll d/l the SDK and try it out.

Offline rdc

  • Pentium
  • *****
  • Posts: 1480
  • Karma: 139
    • View Profile
    • Clark Productions
Re: [PixelToaster] Hypnosis
« Reply #13 on: December 13, 2006 »
Benny, just wanted to let you know I got it running. Thanks for the help.

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4365
  • Karma: 226
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [PixelToaster] Hypnosis
« Reply #14 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 !!!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won: