summaryrefslogtreecommitdiffstats
path: root/src/com/android/noisefield/noisefield.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/noisefield/noisefield.rs')
-rw-r--r--src/com/android/noisefield/noisefield.rs101
1 files changed, 66 insertions, 35 deletions
diff --git a/src/com/android/noisefield/noisefield.rs b/src/com/android/noisefield/noisefield.rs
index f6b16d8..751f603 100644
--- a/src/com/android/noisefield/noisefield.rs
+++ b/src/com/android/noisefield/noisefield.rs
@@ -49,7 +49,7 @@ rs_mesh dotMesh;
rs_mesh gBackgroundMesh;
float densityDPI;
-float xOffset = 0.0;
+bool touchDown = false;
#define B 0x100
#define BM 0xff
@@ -60,30 +60,31 @@ static float g3[B + B + 2][3];
static float g2[B + B + 2][2];
static float g1[B + B + 2];
-static float noise_sCurve(float t)
-{
+// used for motion easing from touch to non-touch state
+static float touchInfluence = 0;
+
+static float touchX = 0;
+static float touchY = 0;
+
+static float noise_sCurve(float t) {
return t * t * (3.0f - 2.0f * t);
}
-static void normalizef2(float v[])
-{
+static void normalizef2(float v[]) {
float s = (float)sqrt(v[0] * v[0] + v[1] * v[1]);
v[0] = v[0] / s;
v[1] = v[1] / s;
}
-static void normalizef3(float v[])
-{
+static void normalizef3(float v[]) {
float s = (float)sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
v[0] = v[0] / s;
v[1] = v[1] / s;
v[2] = v[2] / s;
}
-void init()
-{
+void init() {
int i, j, k;
-
for (i = 0; i < B; i++) {
p[i] = i;
@@ -114,8 +115,7 @@ void init()
}
}
-static float noisef2(float x, float y)
-{
+static float noisef2(float x, float y) {
int bx0, bx1, by0, by1, b00, b10, b01, b11;
float rx0, rx1, ry0, ry1, sx, sy, a, b, t, u, v;
float *q;
@@ -155,10 +155,10 @@ static float noisef2(float x, float y)
return 1.5f * mix(a, b, sy);
}
-void positionParticles(){
+void positionParticles() {
Particle_t* particle = dotParticles;
int size = rsAllocationGetDimX(rsGetAllocation(dotParticles));
- for(int i=0; i<size; i++){
+ for(int i=0; i<size; i++) {
particle->position.x = rsRand(-1.0f, 1.0f);
particle->position.y = rsRand(-1.0f, 1.0f);
particle->speed = rsRand(0.0002f, 0.02f);
@@ -171,16 +171,26 @@ void positionParticles(){
}
}
-int root(){
- rsgClearColor(0.0, 0.0, 0.0, 1.0f);
-
- VertexColor* vert = vertexColors;
- int size = rsAllocationGetDimX(rsGetAllocation(vertexColors));
- for(int i=0; i<size; i++){
- vert->offsetX = xOffset;
- vert++;
+void touch(float x, float y) {
+ bool landscape = rsgGetWidth() > rsgGetHeight();
+ float wRatio;
+ float hRatio;
+ if(!landscape){
+ wRatio = 1.0;
+ hRatio = rsgGetHeight()/rsgGetWidth();
+ } else {
+ hRatio = 1.0;
+ wRatio = rsgGetWidth()/rsgGetHeight();
}
+ touchInfluence = 1.0;
+ touchX = x/rsgGetWidth() * wRatio * 2 - wRatio;
+ touchY = -(y/rsgGetHeight() * hRatio * 2 - hRatio);
+}
+
+int root() {
+ rsgClearColor(0.0, 0.0, 0.0, 1.0f);
+ int size = rsAllocationGetDimX(rsGetAllocation(vertexColors));
rsgBindProgramVertex(vertDots);
rsgBindProgramFragment(fragDots);
rsgBindTexture(fragDots, 0, textureDot);
@@ -194,11 +204,13 @@ int root(){
// dots
Particle_t* particle = dotParticles;
size = rsAllocationGetDimX(rsGetAllocation(dotParticles));
- for(int i=0; i<size; i++){
+ float rads;
+ float speed;
+ for(int i=0; i<size; i++) {
if(particle->life < 0 || particle->position.x < -1.2 ||
particle->position.x >1.2 || particle->position.y < -1.7 ||
- particle->position.y >1.7){
+ particle->position.y >1.7) {
particle->position.x = rsRand(-1.0f, 1.0f);
particle->position.y = rsRand(-1.0f, 1.0f);
particle->speed = rsRand(0.0002f, 0.02f);
@@ -209,35 +221,52 @@ int root(){
particle->alpha = particle->alphaStart;
}
+ float touchDist = sqrt(pow(touchX - particle->position.x, 2) +
+ pow(touchY - particle->position.y, 2));
+
float noiseval = noisef2(particle->position.x, particle->position.y);
+ if(touchDown || touchInfluence > 0.0) {
+ if(touchDown){
+ touchInfluence = 1.0;
+ }
+ rads = atan2(touchX - particle->position.x + noiseval,
+ touchY - particle->position.y + noiseval);
+ if(touchDist != 0){
+ speed = ( (0.25 + (noiseval * particle->speed + 0.01)) / touchDist * 0.3 );
+ speed = speed * touchInfluence;
+ } else {
+ speed = .3;
+ }
+ particle->position.x += cos(rads) * speed * 0.2;
+ particle->position.y += sin(rads) * speed * 0.2;
+ }
- float speed = noiseval * particle->speed + 0.01;
float angle = 360 * noiseval * particle->wander;
- float rads = angle * 3.14159265 / 180.0;
+ speed = noiseval * particle->speed + 0.01;
+ rads = angle * 3.14159265 / 180.0;
- particle->position.x += cos(rads) * speed * 0.24;
- particle->position.y += sin(rads) * speed * 0.24;
+ particle->position.x += cos(rads) * speed * 0.33;
+ particle->position.y += sin(rads) * speed * 0.33;
particle->life--;
particle->death++;
float dist = sqrt(particle->position.x*particle->position.x +
particle->position.y*particle->position.y);
- if(dist < 0.95){
+ if(dist < 0.95) {
dist = 0;
particle->alphaStart *= (1-dist);
-
} else {
dist = dist-0.95;
- if(particle->alphaStart < 1.0f){
+ if(particle->alphaStart < 1.0f) {
particle->alphaStart +=0.01;
particle->alphaStart *= (1-dist);
}
}
- if(particle->death < 101){
+ if(particle->death < 101) {
particle->alpha = (particle->alphaStart)*(particle->death)/100.0;
- } else if(particle->life < 101){
+ } else if(particle->life < 101) {
particle->alpha = particle->alpha*particle->life/100.0;
} else {
particle->alpha = particle->alphaStart;
@@ -246,6 +275,8 @@ int root(){
particle++;
}
+ if(touchInfluence > 0) {
+ touchInfluence-=0.01;
+ }
return 35;
-
-}
+} \ No newline at end of file