diff --git a/app/src/main/java/com/quaap/computationaldemonology/GraphicDemonActivity.java b/app/src/main/java/com/quaap/computationaldemonology/GraphicDemonActivity.java index caa3587..2e37c07 100644 --- a/app/src/main/java/com/quaap/computationaldemonology/GraphicDemonActivity.java +++ b/app/src/main/java/com/quaap/computationaldemonology/GraphicDemonActivity.java @@ -17,16 +17,17 @@ public class GraphicDemonActivity extends Activity implements SensorEventListene private Sensor mAccelerometer; private Sensor mRotation; + private GraphicDmn mDmnview; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_graphic_demon); - GraphicDmn dmnview = (GraphicDmn) findViewById(R.id.dmnview); + mDmnview = (GraphicDmn) findViewById(R.id.dmnview); int which = getIntent().getIntExtra(GraphicDmn.GO, 7); - dmnview.startDraw(which); + mDmnview.startDraw(which); //unpause(); @@ -35,8 +36,8 @@ protected void onCreate(Bundle savedInstanceState) { private void pause() { mSensorManager.unregisterListener(this); - GraphicDmn dmnview = (GraphicDmn) findViewById(R.id.dmnview); - dmnview.pause(); + + mDmnview.pause(); } @@ -54,8 +55,7 @@ private void unpause() { mSensorManager.registerListener(this, mRotation, SensorManager.SENSOR_DELAY_NORMAL); } - GraphicDmn dmnview = (GraphicDmn) findViewById(R.id.dmnview); - dmnview.unpause(); + mDmnview.unpause(); } @@ -79,6 +79,11 @@ protected void onResume() { private static final int FROM_RADS_TO_DEGS = -57; + + float mYaw; + float mPitch; + float mRoll; + private void update(float[] vectors) { float[] rotationMatrix = new float[9]; SensorManager.getRotationMatrixFromVector(rotationMatrix, vectors); @@ -93,8 +98,13 @@ private void update(float[] vectors) { float pitch = orientation[1]*fac; float roll = orientation[2]*fac; - GraphicDmn dmnview = (GraphicDmn) findViewById(R.id.dmnview); - dmnview.deviceRotated(yaw, pitch, roll); + if (yaw!=mYaw || pitch!=mPitch || roll!=mRoll) { + mYaw = yaw; + mPitch = pitch; + mRoll = roll; + + mDmnview.deviceRotated(yaw, pitch, roll); + } // Log.d("dmn","Pitch: " + pitch); // Log.d("dmn","Roll: " + roll); diff --git a/app/src/main/java/com/quaap/computationaldemonology/functions/Awaken.java b/app/src/main/java/com/quaap/computationaldemonology/functions/Awaken.java index 485a831..221724f 100644 --- a/app/src/main/java/com/quaap/computationaldemonology/functions/Awaken.java +++ b/app/src/main/java/com/quaap/computationaldemonology/functions/Awaken.java @@ -26,13 +26,13 @@ public class Awaken extends Drawgorythm { private float alpha = 3; private float scale = .0001f; - private float scalev = .000001f; + private float scalev = .000008f; private Rect dstrect; private Rect srcrect; private Rect gradrect; private Bitmap img; private Bitmap img2; - private Bitmap gradient; + private Bitmap [] gradient; private Paint alphatweak; private Paint white = new Paint(); @@ -46,21 +46,24 @@ public class Awaken extends Drawgorythm { private List poss = new ArrayList<>(); private List dVs = new ArrayList<>(); private int num; - private Canvas c; + //private Canvas c; public Awaken(Context context) { super(context); //img = context.getResources().getDrawable(R.drawable.rift); dstrect = new Rect(); - - gradient = BitmapFactory.decodeResource(context.getResources(),R.drawable.gradient); - gradrect = new Rect(0,0,gradient.getWidth(),gradient.getHeight()); + gradient = new Bitmap[4]; + gradient[0] = BitmapFactory.decodeResource(context.getResources(),R.drawable.gradient2); + gradient[1] = BitmapFactory.decodeResource(context.getResources(),R.drawable.gradient3); + gradient[2] = BitmapFactory.decodeResource(context.getResources(),R.drawable.gradient4); + gradient[3] = BitmapFactory.decodeResource(context.getResources(),R.drawable.gradient5); + gradrect = new Rect(0,0,gradient[0].getWidth(),gradient[0].getHeight()); alphatweak = new Paint(); alphatweak.setColor(Color.WHITE); white.setColor(Color.WHITE); - num = Rand.getInt(7,15); + num = Rand.getInt(3,9); } @@ -82,10 +85,10 @@ public void canvasChanged(Canvas canvas) { dVs.add(new RectF(Rand.getFloatNeg1To1(), Rand.getFloatNeg1To1(), 0,0)); } - img = Bitmap.createBitmap(mWidth, mHeight, gradient.getConfig()); - img2 = Bitmap.createBitmap(mWidth, mHeight, gradient.getConfig()); - c = new Canvas(); - c.setBitmap(img2); + img = Bitmap.createBitmap(mWidth, mHeight, gradient[0].getConfig()); + img2 = Bitmap.createBitmap(mWidth, mHeight, gradient[0].getConfig()); + //c = new Canvas(); + //c.setBitmap(img2); //img = gradient; srcrect = new Rect(0, 0, img.getWidth(), img.getHeight()); @@ -108,14 +111,14 @@ public void stopping() { private class UpdaterThread extends Thread { boolean done=false; - int sleep = 50; + int sleep = 1000; @Override public void run() { while(!done) { - c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.SRC); + //c.drawColor(Color.TRANSPARENT, PorterDuff.Mode.SRC); for (int i = 0; i < num; i++) { RectF d = poss.get(i); RectF dV = dVs.get(i); @@ -130,7 +133,7 @@ public void run() { m.setRectToRect(new RectF(gradrect), d, Matrix.ScaleToFit.CENTER); - c.drawBitmap(gradient, m, white); + //c.drawBitmap(gradient[i%gradient.length], m, white); if (mTouchDY>0 && i%2==0 || mTouchDY<0 && i%2!=0) { //draws += .001*dY; @@ -140,10 +143,10 @@ public void run() { } if (scale>.004) { - scalev = -.00001f; // + Math.sin(draws/5)/1000; + scalev = -.00008f; // + Math.sin(draws/5)/1000; } else if (scale<-.002) { - scalev = .000001f; + scalev = .000008f; } scale += scalev; @@ -156,6 +159,7 @@ else if (scale<-.002) { } catch (InterruptedException e) { e.printStackTrace(); } + done = true; } } @@ -163,17 +167,18 @@ else if (scale<-.002) { Matrix r = new Matrix(); + int count = 0; @Override public void doDraw(Canvas canvas, long ticks) { int sign = 1; if (alpha > 250) { sign = -1; - alpha = 250; + //alpha = 250; } if (alpha<5) { sign = 1; - alpha = 5; + //alpha = 5; } alpha += .01 * sign + Math.sin(draws/2); @@ -182,12 +187,45 @@ public void doDraw(Canvas canvas, long ticks) { alphatweak.setAlpha((int)alpha); - r.reset(); - r.postRotate(-mRoll, mCenterX, mCenterY+mCenterY/2); + for (int i = 0; i < num; i++) { + RectF d = poss.get(i); + RectF dV = dVs.get(i); + + if (d.left<=10) dV.left = -dV.left; + if (d.top<=10) dV.top = -dV.top; + if (d.right>=mWidth-10) dV.left = -dV.left; + if (d.bottom>=mHeight*3/4) dV.top = -dV.top; + + d.set(d.left+dV.left - d.left*scale, d.top+dV.top - d.top*scale, + d.right+dV.left+ d.left*scale, d.bottom+dV.top + d.top*scale); + + m.setRectToRect(new RectF(gradrect), d, Matrix.ScaleToFit.CENTER); + + canvas.drawBitmap(gradient[i%gradient.length], m, alphatweak); + + if (mTouchDY>0 && i%2==0 || mTouchDY<0 && i%2!=0) { + //draws += .001*dY; + dV.left = Math.signum(mTouchX - d.left) * Math.abs(dV.left) * (float)Rand.getDouble(.5,1.5); + dV.top = Math.signum(mTouchY - d.top) * Math.abs(dV.top) * (float)Rand.getDouble(.5,1.5); + Log.d("Awake", "" + scale); + } + + if (scale>.004) { + scalev = -.00008f; // + Math.sin(draws/5)/1000; + } + else if (scale<-.002) { + scalev = .000008f; + } + scale += scalev; - synchronized (imgsync) { - canvas.drawBitmap(img, r, alphatweak); } +// r.reset(); +// r.postRotate(-mRoll, mCenterX, mCenterY+mCenterY/2); +// +// synchronized (imgsync) { +// canvas.drawBitmap(img, r, alphatweak); +// } + } } diff --git a/app/src/main/res/drawable/gradient2.png b/app/src/main/res/drawable/gradient2.png new file mode 100644 index 0000000..14e3ff9 Binary files /dev/null and b/app/src/main/res/drawable/gradient2.png differ diff --git a/app/src/main/res/drawable/gradient3.png b/app/src/main/res/drawable/gradient3.png new file mode 100644 index 0000000..448e2d2 Binary files /dev/null and b/app/src/main/res/drawable/gradient3.png differ diff --git a/app/src/main/res/drawable/gradient4.png b/app/src/main/res/drawable/gradient4.png new file mode 100644 index 0000000..1fa0592 Binary files /dev/null and b/app/src/main/res/drawable/gradient4.png differ diff --git a/app/src/main/res/drawable/gradient5.png b/app/src/main/res/drawable/gradient5.png new file mode 100644 index 0000000..4171da8 Binary files /dev/null and b/app/src/main/res/drawable/gradient5.png differ