-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPixelParticles.c
194 lines (169 loc) · 6.21 KB
/
PixelParticles.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include "PixelParticles.h"
#include "VGA.h"
#include "Random.h"
#include "Utils.h"
#include "Global.h"
#include "Profiling.h"
#include "Graphics/Bitmap.h"
#include "Graphics/Drawing.h"
#include <string.h>
static inline uint32_t PixelAverage(uint32_t a,uint32_t b)
{
uint32_t halfa=(a>>1)&(PixelAllButHighBits*0x01010101);
uint32_t halfb=(b>>1)&(PixelAllButHighBits*0x01010101);
uint32_t carry=a&b&(PixelLowBits*0x01010101);
return halfa+halfb+carry;
}
void PixelParticles()
{
uint8_t *framebuffer1=(uint8_t *)0x20000000;
uint8_t *framebuffer2=(uint8_t *)0x20010000;
// memset(framebuffer1,RawRGB(0,0,0),320*200);
// memset(framebuffer2,RawRGB(0,0,0),320*200);
SetVGAScreenMode320x200_60Hz(framebuffer1);
for(int i=0;i<NumberOfPixelParticles;i++)
{
data.pp.particles[i].x=RandomInteger()%Fix(320);
data.pp.particles[i].y=RandomInteger()%Fix(200);
}
Bitmap screen;
InitializeBitmap(&screen,320,200,320,framebuffer1);
DrawHorizontalLine(&screen,0,0,320,0xff);
DrawHorizontalLine(&screen,0,199,320,0xff);
InitializeBitmap(&screen,320,200,320,framebuffer2);
DrawHorizontalLine(&screen,0,0,320,0xff);
DrawHorizontalLine(&screen,0,199,320,0xff);
int t=0;
int32_t tx1=0,ty1=0;
int32_t tx2=0,ty2=0;
int32_t tx3=0,ty3=0;
int32_t s1=Fix(0.5);
int32_t s2=Fix(1);
int32_t s3=Fix(2);
while(CurrentBitBinRow(songp) < 1312)
{
WaitVBL();
// profiling_startframe();
uint8_t *source,*destination;
if(t&1)
{
source=framebuffer1;
destination=framebuffer2;
}
else
{
source=framebuffer2;
destination=framebuffer1;
}
SetFrameBuffer(source);
uint32_t line1=VGALine;
uint32_t *sourceptr=(uint32_t *)&source[320];
uint32_t *destinationptr=(uint32_t *)&destination[320];
uint32_t previous=RawRGB(0,0,0)*0x01010101;
uint32_t current=*sourceptr++;
for(int y=1;y<199;y++)
{
for(int x=0;x<320/4;x++)
{
uint32_t sum1=PixelAverage(sourceptr[-320/4-1],sourceptr[320/4-1]);
uint32_t next=*sourceptr++;
uint32_t sum2=PixelAverage((current<<8)|(previous>>24),(current>>8)|(next<<24));
uint32_t sum3=PixelAverage(sum1,sum2);
uint32_t sum4=PixelAverage(sum3,current);
*destinationptr++=sum4;
previous=current;
current=next;
}
}
uint32_t line2=VGALine;
Bitmap screen;
InitializeBitmap(&screen,320,200,320,destination);
tx1+=icos(t*3);
ty1+=isin(t*3);
tx2+=icos(-t*2);
ty2+=isin(-t*2);
tx3+=icos(-t*2);
ty3+=isin(-t*2);
if(
CurrentBitBinRow(songp) - 1184 == 84 ||
CurrentBitBinRow(songp) - 1184 == 90 ||
CurrentBitBinRow(songp) - 1184 == 96
) {
for(int i=0;i<3*(NumberOfPixelParticles/10);i++)
{
int32_t x=data.pp.particles[i].x;
int32_t y=data.pp.particles[i].y;
int32_t newx=x;
int32_t newy=y;
newx+=isin((y+ty1)>>6)>>1;
newx-=icos((x+tx1)>>6)>>1;
newx+=isin((y+ty2)>>7);
newy-=icos((x+tx2)>>7);
newx+=isin((y+ty3)>>8)<<1;
newy-=icos((x+tx3)>>8)<<1;
if(newx<0 || newx>=Fix(320) || newy<0 || newy>=Fix(200))
{
newx=RandomInteger()%Fix(320);
newy=RandomInteger()%Fix(200);
}
data.pp.particles[i].x=newx;
data.pp.particles[i].y=newy;
DrawPixelNoClip(&screen,FixedToInt(newx),FixedToInt(newy),RawRGB(7,2,2));
}
for(int i=3*(NumberOfPixelParticles/10);i<NumberOfPixelParticles;i++)
{
int32_t x=data.pp.particles[i].x;
int32_t y=data.pp.particles[i].y;
int32_t newx=x;
int32_t newy=y;
newx+=isin((y+ty1)>>6)>>1;
newx-=icos((x+tx1)>>6)>>1;
newx+=isin((y+ty2)>>7);
newy-=icos((x+tx2)>>7);
newx+=isin((y+ty3)>>8)<<1;
newy-=icos((x+tx3)>>8)<<1;
if(newx<0 || newx>=Fix(320) || newy<0 || newy>=Fix(200))
{
newx=RandomInteger()%Fix(320);
newy=RandomInteger()%Fix(200);
}
data.pp.particles[i].x=newx;
data.pp.particles[i].y=newy;
DrawPixelNoClip(&screen,FixedToInt(newx),FixedToInt(newy),RawRGB(7,6,3));
}
}
else {
for(int i=0;i<NumberOfPixelParticles;i++)
{
int32_t x=data.pp.particles[i].x;
int32_t y=data.pp.particles[i].y;
int32_t newx=x;
int32_t newy=y;
newx+=isin((y+ty1)>>6)>>1;
newx-=icos((x+tx1)>>6)>>1;
newx+=isin((y+ty2)>>7);
newy-=icos((x+tx2)>>7);
newx+=isin((y+ty3)>>8)<<1;
newy-=icos((x+tx3)>>8)<<1;
if(newx<0 || newx>=Fix(320) || newy<0 || newy>=Fix(200))
{
newx=RandomInteger()%Fix(320);
newy=RandomInteger()%Fix(200);
}
data.pp.particles[i].x=newx;
data.pp.particles[i].y=newy;
DrawPixelNoClip(&screen,FixedToInt(newx),FixedToInt(newy),RawRGB(7,6,3));
}
}
uint32_t line3=VGALine;
/*int diff1=line2-line1;
if(diff1<0) diff1+=480;
int diff2=line3-line2;
if(diff2<0) diff2+=480;
DrawHorizontalLine(&screen,0,0,diff1,RGB(0,255,0));
DrawHorizontalLine(&screen,0,199,diff2,RGB(0,255,0));*/
t++;
// profiling_endframe(destination+(320*199));
}
while(UserButtonState());
}