Merge "Rough implemetation of ForEach. Remove launchID from root graphics script."
diff --git a/java/Fountain/res/raw/fountain.rs b/java/Fountain/res/raw/fountain.rs
index 8b69941..67f7ef5 100644
--- a/java/Fountain/res/raw/fountain.rs
+++ b/java/Fountain/res/raw/fountain.rs
@@ -12,8 +12,8 @@
 
 typedef struct __attribute__((packed, aligned(4))) Point_s {
     float2 delta;
-    rs_position2 pos;
-    rs_color4u color;
+    float2 position;
+    uchar4 color;
 } Point_t;
 Point_t *point;
 
@@ -28,8 +28,8 @@
     Point_t * p = point;
     for (int ct=0; ct < size; ct++) {
         p->delta.y += 0.15f;
-        p->pos += p->delta;
-        if ((p->pos.y > height) && (p->delta.y > 0)) {
+        p->position += p->delta;
+        if ((p->position.y > height) && (p->delta.y > 0)) {
             p->delta.y *= -0.3f;
         }
         p++;
@@ -42,16 +42,18 @@
 
 void addParticles(int rate, int x, int y)
 {
-    rsDebug("partColor", partColor);
-    rsDebug("partColor x", partColor.x);
-    rsDebug("partColor y", partColor.y);
-    rsDebug("partColor z", partColor.z);
-    rsDebug("partColor w", partColor.w);
+    //rsDebug("partColor", partColor);
+    //rsDebug("partColor x", partColor.x);
+    //rsDebug("partColor y", partColor.y);
+    //rsDebug("partColor z", partColor.z);
+    //rsDebug("partColor w", partColor.w);
 
     float rMax = ((float)rate) * 0.005f;
     int size = rsAllocationGetDimX(rsGetAllocation(point));
 
-    rs_color4u c = rsPackColorTo8888(partColor.x, partColor.y, partColor.z);
+    uchar4 c = rsPackColorTo8888(partColor.x, partColor.y, partColor.z);
+
+    //rsDebug("color ", ((int *)&c)[0]);
     Point_t * np = &point[newPart];
 
     float2 p = {x, y};
@@ -60,7 +62,7 @@
         float len = rsRand(rMax);
         np->delta.x = len * sin(angle);
         np->delta.y = len * cos(angle);
-        np->pos = p;
+        np->position = p;
         np->color = c;
         newPart++;
         np++;
diff --git a/java/Fountain/res/raw/fountain_bc.bc b/java/Fountain/res/raw/fountain_bc.bc
index 45475fa..7b2e88b 100644
--- a/java/Fountain/res/raw/fountain_bc.bc
+++ b/java/Fountain/res/raw/fountain_bc.bc
Binary files differ
diff --git a/java/Fountain/src/com/android/fountain/FountainRS.java b/java/Fountain/src/com/android/fountain/FountainRS.java
index ba09a16..6f60134 100644
--- a/java/Fountain/src/com/android/fountain/FountainRS.java
+++ b/java/Fountain/src/com/android/fountain/FountainRS.java
@@ -27,26 +27,36 @@
     public FountainRS() {
     }
 
+    private Resources mRes;
+    private RenderScriptGL mRS;
+    private ScriptC_Fountain mScript;
     public void init(RenderScriptGL rs, Resources res, int width, int height) {
         mRS = rs;
         mRes = res;
-        initRS();
+
+        ScriptField_Point points = new ScriptField_Point(mRS, PART_COUNT);
+
+        SimpleMesh.Builder smb = new SimpleMesh.Builder(mRS);
+        int vtxSlot = smb.addVertexType(points.getType());
+        smb.setPrimitive(Primitive.POINT);
+        SimpleMesh sm = smb.create();
+        sm.bindVertexAllocation(points.getAllocation(), vtxSlot);
+
+        mScript = new ScriptC_Fountain(mRS, mRes, true);
+        mScript.set_partMesh(sm);
+        mScript.bind_point(points);
+        mRS.contextBindRootScript(mScript);
     }
 
     Float4 tmpColor = new Float4();
     boolean holdingColor = false;
+    java.util.Random mRand = new java.util.Random();
     public void newTouchPosition(int x, int y, int rate) {
         if (rate > 0) {
-            if (true/*!holdingColor*/) {
-                tmpColor.x = ((x & 0x1) != 0) ? 0.f : 1.f;
-                tmpColor.y = ((x & 0x2) != 0) ? 0.f : 1.f;
-                tmpColor.z = ((x & 0x4) != 0) ? 0.f : 1.f;
-                if ((tmpColor.x + tmpColor.y + tmpColor.z) < 0.9f) {
-                    tmpColor.x = 0.8f;
-                    tmpColor.y = 0.5f;
-                    tmpColor.z = 1.0f;
-                }
-                android.util.Log.e("rs", "set color " + tmpColor.x + ", " + tmpColor.y + ", " + tmpColor.z);
+            if (!holdingColor) {
+                tmpColor.x = mRand.nextFloat() * 0.5f + 0.5f;
+                tmpColor.y = mRand.nextFloat();
+                tmpColor.z = mRand.nextFloat();
                 mScript.set_partColor(tmpColor);
             }
             mScript.invokable_addParticles(rate, x, y);
@@ -56,32 +66,6 @@
         }
 
     }
-
-
-    /////////////////////////////////////////
-
-    private Resources mRes;
-
-    private ScriptField_Point mPoints;
-    private ScriptC_Fountain mScript;
-    private RenderScriptGL mRS;
-    private SimpleMesh mSM;
-
-    private void initRS() {
-        mPoints = new ScriptField_Point(mRS, PART_COUNT);
-
-        SimpleMesh.Builder smb = new SimpleMesh.Builder(mRS);
-        int vtxSlot = smb.addVertexType(mPoints.getType());
-        smb.setPrimitive(Primitive.POINT);
-        mSM = smb.create();
-        mSM.bindVertexAllocation(mPoints.getAllocation(), vtxSlot);
-
-        mScript = new ScriptC_Fountain(mRS, mRes, true);
-        mScript.set_partMesh(mSM);
-        mScript.bind_point(mPoints);
-        mRS.contextBindRootScript(mScript);
-    }
-
 }
 
 
diff --git a/java/Fountain/src/com/android/fountain/ScriptField_Point.java b/java/Fountain/src/com/android/fountain/ScriptField_Point.java
index edd18d5..b091f39 100644
--- a/java/Fountain/src/com/android/fountain/ScriptField_Point.java
+++ b/java/Fountain/src/com/android/fountain/ScriptField_Point.java
@@ -31,7 +31,7 @@
 
         Element.Builder eb = new Element.Builder(rs);
         eb.add(Element.createVector(rs, Element.DataType.FLOAT_32, 2), "delta");
-        eb.add(Element.createAttrib(rs, Element.DataType.FLOAT_32, Element.DataKind.POSITION, 2), "pos");
+        eb.add(Element.createAttrib(rs, Element.DataType.FLOAT_32, Element.DataKind.POSITION, 2), "position");
         eb.add(Element.createAttrib(rs, Element.DataType.UNSIGNED_8, Element.DataKind.COLOR, 4), "color");
         mElement = eb.create();