mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 19:08:55 -04:00
inkblot Movie: a cellular automaton
This commit is contained in:
parent
7ffcca7b68
commit
b294026a78
28
panda/src/movies/inkblotMovie.I
Normal file
28
panda/src/movies/inkblotMovie.I
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Filename: inkblotMovie.I
|
||||||
|
// Created by: jyelon (02Jul07)
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PANDA 3D SOFTWARE
|
||||||
|
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||||
|
//
|
||||||
|
// All use of this software is subject to the terms of the Panda 3d
|
||||||
|
// Software license. You should have received a copy of this license
|
||||||
|
// along with this source code; you will also find a current copy of
|
||||||
|
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||||
|
//
|
||||||
|
// To contact the maintainers of this program write to
|
||||||
|
// panda3d-general@lists.sourceforge.net .
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: InkblotMovie::get_fps
|
||||||
|
// Access: Published
|
||||||
|
// Description: Get the frame rate of the inkblot movie.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE int InkblotMovie::
|
||||||
|
get_fps() const {
|
||||||
|
return _fps;
|
||||||
|
}
|
||||||
|
|
65
panda/src/movies/inkblotMovie.cxx
Normal file
65
panda/src/movies/inkblotMovie.cxx
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
// Filename: inkblotMovie.cxx
|
||||||
|
// Created by: jyelon (02Jul07)
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PANDA 3D SOFTWARE
|
||||||
|
// Copyright (c) 2001 - 2007, Disney Enterprises, Inc. All rights reserved
|
||||||
|
//
|
||||||
|
// All use of this software is subject to the terms of the Panda 3d
|
||||||
|
// Software license. You should have received a copy of this license
|
||||||
|
// along with this source code; you will also find a current copy of
|
||||||
|
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||||
|
//
|
||||||
|
// To contact the maintainers of this program write to
|
||||||
|
// panda3d-general@lists.sourceforge.net .
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "inkblotVideo.h"
|
||||||
|
#include "inkblotMovie.h"
|
||||||
|
#include "config_movies.h"
|
||||||
|
|
||||||
|
TypeHandle InkblotMovie::_type_handle;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: InkblotMovie::Constructor
|
||||||
|
// Access: Published
|
||||||
|
// Description: xxx
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
InkblotMovie::
|
||||||
|
InkblotMovie(const string &name, double len, int sizex, int sizey, int fps) :
|
||||||
|
Movie(name,len)
|
||||||
|
{
|
||||||
|
_ignores_offset = true;
|
||||||
|
if (sizex < 1) sizex=1;
|
||||||
|
if (sizey < 1) sizey=1;
|
||||||
|
if (fps < 1) fps=1;
|
||||||
|
_size_x = sizex;
|
||||||
|
_size_y = sizey;
|
||||||
|
_fps = fps;
|
||||||
|
_dummy_video = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: Movie::get_video
|
||||||
|
// Access: Published, Virtual
|
||||||
|
// Description: Fetch a video stream. Always constructs a new
|
||||||
|
// MovieVideo or subclass of MovieVideo.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
PT(MovieVideo) InkblotMovie::
|
||||||
|
get_video(double offset) const {
|
||||||
|
return new InkblotVideo(get_name(), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: Movie::get_audio
|
||||||
|
// Access: Published, Virtual
|
||||||
|
// Description: Fetch an audio stream. Always constructs a new
|
||||||
|
// MovieAudio or subclass of MovieAudio.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
PT(MovieAudio) InkblotMovie::
|
||||||
|
get_audio(double offset) const {
|
||||||
|
return new MovieAudio(get_name(), this);
|
||||||
|
}
|
||||||
|
|
79
panda/src/movies/inkblotMovie.h
Normal file
79
panda/src/movies/inkblotMovie.h
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
// Filename: inkblotMovie.h
|
||||||
|
// Created by: jyelon (02Jul07)
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PANDA 3D SOFTWARE
|
||||||
|
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||||
|
//
|
||||||
|
// All use of this software is subject to the terms of the Panda 3d
|
||||||
|
// Software license. You should have received a copy of this license
|
||||||
|
// along with this source code; you will also find a current copy of
|
||||||
|
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||||
|
//
|
||||||
|
// To contact the maintainers of this program write to
|
||||||
|
// panda3d-general@lists.sourceforge.net .
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef INKBLOTMOVIE_H
|
||||||
|
#define INKBLOTMOVIE_H
|
||||||
|
|
||||||
|
#include "pandabase.h"
|
||||||
|
#include "texture.h"
|
||||||
|
#include "pointerTo.h"
|
||||||
|
#include "movie.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Class : InkblotMovie
|
||||||
|
// Description : This cellular automaton generates an attractive
|
||||||
|
// pattern of swirling colors. It is called "Digital
|
||||||
|
// Inkblots," it was invented by Jason Rampe, who in
|
||||||
|
// turn based it on Rudy Rucker's automaton "Rug."
|
||||||
|
// Both automata were included in the program "Mirek's
|
||||||
|
// Cellebration," which is a fantastic exploration
|
||||||
|
// of different kinds of cellular automata. I
|
||||||
|
// encourage anyone to download it, it's a blast.
|
||||||
|
// I find that 128x128 at about 15 fps is just right
|
||||||
|
// for this automaton.
|
||||||
|
//
|
||||||
|
// I have included a cellular automaton here mainly
|
||||||
|
// as a simple example of how to derive from class
|
||||||
|
// Movie, and to demonstrate that a "Movie" can be
|
||||||
|
// anything that generates a series of video frames,
|
||||||
|
// not just an AVI file.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
class EXPCL_PANDA_MOVIES InkblotMovie : public Movie {
|
||||||
|
|
||||||
|
PUBLISHED:
|
||||||
|
InkblotMovie(const string &name, double len,
|
||||||
|
int sizex=256, int sizey=256, int fps=10);
|
||||||
|
|
||||||
|
INLINE int get_fps() const;
|
||||||
|
virtual PT(MovieVideo) get_video(double offset=0.0) const;
|
||||||
|
virtual PT(MovieAudio) get_audio(double offset=0.0) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int _fps;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static TypeHandle get_class_type() {
|
||||||
|
return _type_handle;
|
||||||
|
}
|
||||||
|
static void init_type() {
|
||||||
|
Movie::init_type();
|
||||||
|
register_type(_type_handle, "InkblotMovie",
|
||||||
|
Movie::get_class_type());
|
||||||
|
}
|
||||||
|
virtual TypeHandle get_type() const {
|
||||||
|
return get_class_type();
|
||||||
|
}
|
||||||
|
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static TypeHandle _type_handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "inkblotMovie.I"
|
||||||
|
|
||||||
|
#endif
|
18
panda/src/movies/inkblotVideo.I
Normal file
18
panda/src/movies/inkblotVideo.I
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Filename: inkblotVideo.I
|
||||||
|
// Created by: jyelon (02Jul07)
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PANDA 3D SOFTWARE
|
||||||
|
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||||
|
//
|
||||||
|
// All use of this software is subject to the terms of the Panda 3d
|
||||||
|
// Software license. You should have received a copy of this license
|
||||||
|
// along with this source code; you will also find a current copy of
|
||||||
|
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||||
|
//
|
||||||
|
// To contact the maintainers of this program write to
|
||||||
|
// panda3d-general@lists.sourceforge.net .
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
140
panda/src/movies/inkblotVideo.cxx
Normal file
140
panda/src/movies/inkblotVideo.cxx
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
// Filename: inkblotVideo.cxx
|
||||||
|
// Created by: jyelon (02Jul07)
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PANDA 3D SOFTWARE
|
||||||
|
// Copyright (c) 2001 - 2007, Disney Enterprises, Inc. All rights reserved
|
||||||
|
//
|
||||||
|
// All use of this software is subject to the terms of the Panda 3d
|
||||||
|
// Software license. You should have received a copy of this license
|
||||||
|
// along with this source code; you will also find a current copy of
|
||||||
|
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||||
|
//
|
||||||
|
// To contact the maintainers of this program write to
|
||||||
|
// panda3d-general@lists.sourceforge.net .
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "inkblotVideo.h"
|
||||||
|
#include "inkblotMovie.h"
|
||||||
|
#include "config_movies.h"
|
||||||
|
|
||||||
|
TypeHandle InkblotVideo::_type_handle;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// The Color-Map
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
struct color {
|
||||||
|
int r,g,b;
|
||||||
|
};
|
||||||
|
|
||||||
|
static color colormap[17] = {
|
||||||
|
{ 255,0,0 },
|
||||||
|
{ 255,255,0 },
|
||||||
|
{ 0,255,0 },
|
||||||
|
{ 0,255,255 },
|
||||||
|
{ 0,0,255 },
|
||||||
|
{ 0,0,0 },
|
||||||
|
{ 255,0,0 },
|
||||||
|
{ 255,255,0 },
|
||||||
|
{ 0,255,0 },
|
||||||
|
{ 0,255,255 },
|
||||||
|
{ 0,0,255 },
|
||||||
|
{ 0,0,0 },
|
||||||
|
{ 255,0,0 },
|
||||||
|
{ 255,255,0 },
|
||||||
|
{ 0,255,0 },
|
||||||
|
{ 0,255,255 },
|
||||||
|
{ 0,0,255 },
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: InkblotVideo::Constructor
|
||||||
|
// Access: Published
|
||||||
|
// Description: xxx
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
InkblotVideo::
|
||||||
|
InkblotVideo(const string &name, CPT(Movie) source) :
|
||||||
|
MovieVideo(name, source)
|
||||||
|
{
|
||||||
|
_sourcep = (const InkblotMovie*)(const Movie*)_source;
|
||||||
|
int padx = size_x() + 2;
|
||||||
|
int pady = size_y() + 2;
|
||||||
|
_cells = new unsigned char[padx * pady];
|
||||||
|
_cells2 = new unsigned char[padx * pady];
|
||||||
|
memset(_cells, 255, padx * pady);
|
||||||
|
memset(_cells2, 255, padx * pady);
|
||||||
|
_frames_read = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: InkblotVideo::Destructor
|
||||||
|
// Access: Published, Virtual
|
||||||
|
// Description:
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
InkblotVideo::
|
||||||
|
~InkblotVideo() {
|
||||||
|
delete[] _cells;
|
||||||
|
delete[] _cells2;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: InkblotVideo::fetch_into_buffer
|
||||||
|
// Access: Published, Virtual
|
||||||
|
// Description: See MovieVideo::fetch_into_buffer.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void InkblotVideo::
|
||||||
|
fetch_into_buffer(double time, unsigned char *data, bool rgba) {
|
||||||
|
|
||||||
|
nassertv(time >= _next_start);
|
||||||
|
|
||||||
|
int padx = size_x() + 2;
|
||||||
|
int pady = size_y() + 2;
|
||||||
|
int fps = _sourcep->get_fps();
|
||||||
|
|
||||||
|
while (_next_start <= time) {
|
||||||
|
_last_start = (_frames_read * 1.0) / fps;
|
||||||
|
_frames_read += 1;
|
||||||
|
_next_start = (_frames_read * 1.0) / fps;
|
||||||
|
for (int y=1; y<pady-1; y++) {
|
||||||
|
for (int x=1; x<padx-1; x++) {
|
||||||
|
int tot =
|
||||||
|
_cells[(x+1)+(y+1)*padx] +
|
||||||
|
_cells[(x+1)+(y+0)*padx] +
|
||||||
|
_cells[(x+1)+(y-1)*padx] +
|
||||||
|
_cells[(x+0)+(y+1)*padx] +
|
||||||
|
_cells[(x+0)+(y+0)*padx] +
|
||||||
|
_cells[(x+0)+(y-1)*padx] +
|
||||||
|
_cells[(x-1)+(y+1)*padx] +
|
||||||
|
_cells[(x-1)+(y+0)*padx] +
|
||||||
|
_cells[(x-1)+(y-1)*padx];
|
||||||
|
_cells2[x + y*padx] = (tot/9)+3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unsigned char *t = _cells;
|
||||||
|
_cells = _cells2;
|
||||||
|
_cells2 = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int y=1; y<pady - 1; y++) {
|
||||||
|
for (int x=1; x<padx - 1; x++) {
|
||||||
|
int val = _cells[x + y*padx];
|
||||||
|
color &c1 = colormap[(val>>4)+0];
|
||||||
|
color &c2 = colormap[(val>>4)+1];
|
||||||
|
int lerp = val & 15;
|
||||||
|
data[0] = (c1.r * (16-lerp) + c2.r * lerp) / 16;
|
||||||
|
data[1] = (c1.g * (16-lerp) + c2.g * lerp) / 16;
|
||||||
|
data[2] = (c1.b * (16-lerp) + c2.b * lerp) / 16;
|
||||||
|
if (rgba) {
|
||||||
|
data[3] = 255;
|
||||||
|
data += 4;
|
||||||
|
} else {
|
||||||
|
data += 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
67
panda/src/movies/inkblotVideo.h
Normal file
67
panda/src/movies/inkblotVideo.h
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// Filename: inkblotVideo.h
|
||||||
|
// Created by: jyelon (02Jul07)
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// PANDA 3D SOFTWARE
|
||||||
|
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||||
|
//
|
||||||
|
// All use of this software is subject to the terms of the Panda 3d
|
||||||
|
// Software license. You should have received a copy of this license
|
||||||
|
// along with this source code; you will also find a current copy of
|
||||||
|
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||||
|
//
|
||||||
|
// To contact the maintainers of this program write to
|
||||||
|
// panda3d-general@lists.sourceforge.net .
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef INKBLOTVIDEO_H
|
||||||
|
#define INKBLOTVIDEO_H
|
||||||
|
|
||||||
|
#include "pandabase.h"
|
||||||
|
#include "texture.h"
|
||||||
|
#include "pointerTo.h"
|
||||||
|
#include "inkblotMovie.h"
|
||||||
|
#include "movieVideo.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Class : InkblotVideo
|
||||||
|
// Description : A cellular automaton that generates an amusing
|
||||||
|
// pattern of swirling colors.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
class EXPCL_PANDA_MOVIES InkblotVideo : public MovieVideo {
|
||||||
|
|
||||||
|
PUBLISHED:
|
||||||
|
InkblotVideo(const string &name, CPT(Movie) source);
|
||||||
|
virtual ~InkblotVideo();
|
||||||
|
virtual void fetch_into_buffer(double time, unsigned char *block, bool rgba);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const InkblotMovie *_sourcep;
|
||||||
|
unsigned char *_cells;
|
||||||
|
unsigned char *_cells2;
|
||||||
|
int _fps;
|
||||||
|
int _frames_read;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static TypeHandle get_class_type() {
|
||||||
|
return _type_handle;
|
||||||
|
}
|
||||||
|
static void init_type() {
|
||||||
|
MovieVideo::init_type();
|
||||||
|
register_type(_type_handle, "InkblotVideo",
|
||||||
|
MovieVideo::get_class_type());
|
||||||
|
}
|
||||||
|
virtual TypeHandle get_type() const {
|
||||||
|
return get_class_type();
|
||||||
|
}
|
||||||
|
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static TypeHandle _type_handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "inkblotVideo.I"
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user