Advertisement
Guest User

DrawCircles

a guest
Oct 26th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. FrameLayout frame = (FrameLayout) findViewById(R.id.frame);
  2.  
  3. for(int i=0;i<=9;i++){
  4. DrawCircles c = new DrawCircles(getApplicationContext());
  5. frame.addView(c);
  6. }
  7.  
  8.  
  9. public class DrawCircles extends View {
  10.  
  11. int red = (int) (Math.random() * 255);
  12. int green = (int) (Math.random() * 255);
  13. int blue = (int) (Math.random() * 255);
  14.  
  15. public DrawCircles(Context con)
  16. {
  17. super(con);
  18. }
  19. @SuppressLint("DrawAllocation")
  20. @Override
  21. public void onDraw(Canvas c)
  22. {
  23. super.onDraw(c);
  24.  
  25.  
  26. int minRadius = 100;
  27. Random random = new Random();//define this outside you onDraw fucntion
  28. int w = getWidth();
  29. int h = getHeight();
  30.  
  31. int randX = random.nextInt(w);
  32. int randY = random.nextInt(h);
  33. int randR = minRadius + random.nextInt(100);
  34.  
  35. Log.e("randX",">>"+randX+","+randR);
  36.  
  37. int color = Color.rgb(red, green, blue);
  38. int rand = (int)(Math.random() * 200);
  39. Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
  40. p.setAntiAlias(true);
  41. p.setStyle(Paint.Style.STROKE);
  42. p.setStrokeWidth(100);
  43. p.setColor(color);
  44. p.setStyle(Paint.Style.FILL);
  45. // c.drawCircle(rand, rand, rand, p);
  46. c.drawCircle(randX, randY, randR, p);
  47.  
  48. clear(c);
  49.  
  50. }
  51. public void clear(Canvas c)
  52. {
  53. c.drawColor(Color.TRANSPARENT);
  54. }
  55. public void drawColor(int transparent) {
  56. // TODO Auto-generated method stub
  57.  
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement