blob: 48c4249f56fef1e5aa63db54e5db31d637536768 (
plain)
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
|
// Fountain test script
#pragma version(1)
#pragma rs java_package_name(com.android.fountain)
#include "frameworks/base/libs/rs/scriptc/rs_types.rsh"
#include "frameworks/base/libs/rs/scriptc/rs_math.rsh"
#include "frameworks/base/libs/rs/scriptc/rs_graphics.rsh"
static int newPart = 0;
rs_mesh partMesh;
typedef struct __attribute__((packed, aligned(4))) Point {
float2 delta;
float2 position;
uchar4 color;
} Point_t;
Point_t *point;
#pragma rs export_var(point, partMesh)
#pragma rs export_func(addParticles)
int root() {
rsgClearColor(0.f, 0.f, 0.f, 1.f);
const float height = rsgGetHeight();
const int size = rsAllocationGetDimX(rsGetAllocation(point));
Point_t * p = point;
for (int ct=0; ct < size; ct++) {
p->delta.y += 0.15f;
p->position += p->delta;
if ((p->position.y > height) && (p->delta.y > 0)) {
p->delta.y *= -0.3f;
}
p++;
}
rsgDrawMesh(partMesh);
return 1;
}
static float4 partColor[10];
void addParticles(int rate, float x, float y, int index, bool newColor)
{
if (newColor) {
partColor[index].x = rsRand(0.5f, 1.0f);
partColor[index].y = rsRand(1.0f);
partColor[index].z = rsRand(1.0f);
}
float rMax = ((float)rate) * 0.02f;
int size = rsAllocationGetDimX(rsGetAllocation(point));
uchar4 c = rsPackColorTo8888(partColor[index]);
Point_t * np = &point[newPart];
float2 p = {x, y};
while (rate--) {
float angle = rsRand(3.14f * 2.f);
float len = rsRand(rMax);
np->delta.x = len * sin(angle);
np->delta.y = len * cos(angle);
np->position = p;
np->color = c;
newPart++;
np++;
if (newPart >= size) {
newPart = 0;
np = &point[newPart];
}
}
}
|