Debian Codegraph @

src/menu/plasma.cpp

raw symbols SCIP
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 * @par Description:
18 * Cool plasma effects for the main menu.
19 *
20 */
21
22
23 #include "plasma.h"
24
25 #include "level/level.h"
26 #include "util.h"
27 #include "io/gfx/video.h"
28
29 #ifdef OJ_SDL3
30 #include <SDL3/SDL.h>
31 #else
32 #include <SDL.h>
33 #endif
34
35 /**
36 * Create the plasma.
37 */
38 Plasma::Plasma(){
39
40 p0=0;
41 p1=0;
42 p2=0;
43 p3=0;
44
45 //fSin, fCos: pi = 512
46 // -1024 < out < 1024
47 }
48
49 /**
50 * Draw the plasma.
51 *
52 * @return Error code
53 */
54 int Plasma::draw(){
55 int x,y;
56
57 int w,h,pitch;
58 unsigned char *px;
59 unsigned char colour;
60
61 // draw plasma
62
63 SDL_LockSurface(canvas);
64
65 w = canvas->w;
66 h = canvas->h;
67 pitch = canvas->pitch;
68
69 px = static_cast<unsigned char*>(canvas->pixels);
70
71 int t1 = p0;
72 int t2 = p1;
73 for(y=0;y<h;y++){
74 int t3 = p2;
75 int t4 = p3;
76 unsigned int colb = (fCos(t1*4)<<3)+(fCos(t2*4)<<3)+(32<<10);
77 for(x=0;x<w;x++){
78
79 colour = ((colb+(fCos(t3*4)<<3)+(fCos(t4*4)<<3))>>10) & 0xF;
80
81 t3 += 3;
82 t4 += 2;
83
84 px[x] = colour;
85 }
86 // go to next row
87 px += pitch;
88 t1 += 2;
89 t2 += 1;
90 }
91
92 p0 = p0 < 256 ? p0+1 : 1;
93 p1 = p1 < 256 ? p1+2 : 2;
94 p2 = p2 < 256 ? p2+3 : 3;
95 p3 = p3 < 256 ? p3+4 : 4;
96
97 SDL_UnlockSurface(canvas);
98
99 return E_NONE;
100
101 }