package home.backGroundColorChange;
import java.util.Random;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.app.Activity;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
public class ClearActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGLView = new ClearGLSurfaceView(this);
setContentView(mGLView);
}
@Override
protected void onPause() {
super.onPause();
mGLView.onPause();
}
@Override
protected void onResume() {
super.onResume();
mGLView.onResume();
}
private GLSurfaceView mGLView;
}
class ClearGLSurfaceView extends GLSurfaceView
{
ClearRenderer mRenderer;
public ClearGLSurfaceView(Context context)
{
super(context);
mRenderer = new ClearRenderer();
setRenderer(mRenderer);
}
public boolean onTouchEvent(final MotionEvent event)
{
final Float blue_color=this.genarate_random_number();
queueEvent(new Runnable()
{
public void run()
{
mRenderer.setColor(event.getX() / getWidth(),
event.getY() / getHeight(), blue_color);
}
}
);
Log.d("getWidth="+getWidth()+" "+"getHeight="+getHeight()+"event.getX="+event.getX()+" "+"event.getY="+event.getY()+" ","blueColor="+blue_color);
return true;
}
public float genarate_random_number()
{
Random rand = new Random();
float pick = rand.nextFloat();
return pick;
}
}
class ClearRenderer implements GLSurfaceView.Renderer
{
private float mRed;
private float mGreen;
private float mBlue;
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// Do nothing special.
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
gl.glViewport(0, 0, w, h);
}
public void onDrawFrame(GL10 gl) {
gl.glClearColor(mRed, mGreen, mBlue, 0.0f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
}
public void setColor(float r, float g, float b)
{
mRed = r;
mGreen = g;
mBlue = b;
}
}
No comments:
Post a Comment