1 
2 /**
3  *
4  * @file plasma.cpp
5  *
6  * Part of the OpenJazz project
7  *
8  * @par History:
9  * - 23rd June 2010: Created plasma.cpp
10  *
11  * @par Licence:
12  * Copyright (c) 2010 Alireza Nejati
13  *
14  * OpenJazz is distributed under the terms of
15  * the GNU General Public License, version 2.0
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  *
21  * @par Description:
22  * Cool plasma effects for the main menu.
23  *
24  */
25 
26 
27 #include "plasma.h"
28 
29 #include "level/level.h"
30 #include "util.h"
31 #include "io/gfx/video.h"
32 #include <SDL.h>
33 
34 #ifdef SCALE
35 	#include "io/gfx/scale2x/scalebit.h"
36 #endif
37 
38 
39 /**
40  * Create the plasma.
41  */
Plasma()42 Plasma::Plasma(){
43 
44 	p0=0;
45 	p1=0;
46 	p2=0;
47 	p3=0;
48 
49 	//fSin, fCos: pi = 512
50 	// -1024 < out < 1024
51 }
52 
53 /**
54  * Draw the plasma.
55  *
56  * @return Error code
57  */
draw()58 int Plasma::draw(){
59 	int x,y;
60 
61 	int t1,t2,t3,t4;
62 	int w,h,pitch;
63 	unsigned char *px;
64 	unsigned char colour;
65 	unsigned int colb;
66 
67 	// draw plasma
68 
69 	SDL_LockSurface(canvas);
70 
71 	w 		= canvas->w;
72 	h 		= canvas->h;
73 	pitch 	= canvas->pitch;
74 
75 	px = (unsigned char *)canvas->pixels;
76 
77     t1 = p0;
78     t2 = p1;
79     for(y=0;y<h;y++){
80         t3 = p2;
81         t4 = p3;
82 		colb = (fCos(t1*4)<<3)+(fCos(t2*4)<<3)+(32<<10);
83         for(x=0;x<w;x++){
84 
85 			colour = ((colb+(fCos(t3*4)<<3)+(fCos(t4*4)<<3))>>10) & 0xF;
86 
87             t3 += 3;
88             t4 += 2;
89 
90             px[x] = colour;
91 		}
92 		// go to next row
93 		px += pitch;
94         t1 += 2;
95         t2 += 1;
96 	}
97 
98 	p0 = p0 < 256 ? p0+1 : 1;
99 	p1 = p1 < 256 ? p1+2 : 2;
100 	p2 = p2 < 256 ? p2+3 : 3;
101 	p3 = p3 < 256 ? p3+4 : 4;
102 
103 	SDL_UnlockSurface(canvas);
104 
105 	return E_NONE;
106 
107 }
108 
109