Skip to content

Commit

Permalink
2nd attempt. still too slow
Browse files Browse the repository at this point in the history
  • Loading branch information
quaap committed Aug 4, 2018
1 parent df3319b commit 771d98e
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

}

Expand All @@ -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();

}

Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -46,21 +46,24 @@ public class Awaken extends Drawgorythm {
private List<RectF> poss = new ArrayList<>();
private List<RectF> 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);

}

Expand All @@ -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());

Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -156,24 +159,26 @@ else if (scale<-.002) {
} catch (InterruptedException e) {
e.printStackTrace();
}
done = true;

}
}
}


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);
Expand All @@ -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);
// }

}
}
Binary file added app/src/main/res/drawable/gradient2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/gradient3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/gradient4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/gradient5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 771d98e

Please sign in to comment.