Advertisement
EvgeniiKraaaaaaaav

Bubbles

Nov 18th, 2019
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.04 KB | None | 0 0
  1. //https://vk.com/evgenykravchenko0
  2.  
  3.                 ___                                        ___                   ___    
  4.                /  /\                  ___                 /  /\                 /  /\    
  5.               /  /:/_                /__/\               /  /:/_               /  /:/_  
  6.              /  /:/ /\               \  \:\             /  /:/ /\             /  /:/ /\  
  7.             /  /:/ /:/_               \  \:\           /  /:/_/::\           /  /:/ /:/_
  8.            /__/:/ /:/ /\          ___  \__\:\         /__/:/__\/\:\         /__/:/ /:/ /\
  9.            \  \:\/:/ /:/         /__/\ |  |:|         \  \:\ /~~/:/         \  \:\/:/ /:/
  10.             \  \::/ /:/          \  \:\|  |:|          \  \:\  /:/           \  \::/ /:/
  11.              \  \:\/:/            \  \:\__|:|           \  \:\/:/             \  \:\/:/  
  12.               \  \::/              \__\::::/             \  \::/               \  \::/  
  13.                \__\/                   ~~~~               \__\/                 \__\/    
  14.                             ___                                            
  15.                            /__/\                ___                 ___    
  16.                            \  \:\              /  /\               /  /\    
  17.                             \  \:\            /  /:/              /  /:/    
  18.                         _____\__\:\          /__/::\             /__/::\    
  19.                        /__/::::::::\         \__\/\:\__          \__\/\:\__
  20.                        \  \:\~~\~~\/            \  \:\/\            \  \:\/\
  21.                         \  \:\  ~~~              \__\::/             \__\::/
  22.                          \  \:\                  /__/:/              /__/:/
  23.                           \  \:\                 \__\/               \__\/  
  24.                            \__\/                      
  25.  
  26. package com.example.graphicbubble;
  27.  
  28. import android.content.Context;
  29. import android.graphics.Canvas;
  30. import android.graphics.Color;
  31. import android.graphics.Paint;
  32. import android.os.Handler;
  33. import android.util.AttributeSet;
  34. import android.view.MotionEvent;
  35. import android.widget.ImageView;
  36. import android.view.View;
  37.  
  38. import java.util.ArrayList;
  39. import java.util.Random;
  40.  
  41. public class BubbleView extends ImageView implements View.OnTouchListener {
  42.     private Random rand = new Random();
  43.     private ArrayList<Bubble> bubbleList;
  44.     private int size  = 50;
  45.     private int delay = 33;
  46.     private Paint paint = new Paint();
  47.     private Handler handler = new Handler();
  48.  
  49.     public BubbleView(Context context, AttributeSet attributeSet) {
  50.         super(context, attributeSet);
  51.         bubbleList = new ArrayList<Bubble>();
  52.         //testBubbles();
  53.         setOnTouchListener(this);
  54.     }
  55.     private Runnable runnable = new Runnable() {
  56.         @Override
  57.         public void run() {
  58.             invalidate();
  59.         }
  60.     };
  61.     protected void onDraw (Canvas canvas) {
  62.         for (Bubble b: bubbleList) {
  63.             b.draw(canvas);
  64.         }
  65.         handler.postDelayed(runnable, delay);
  66.     }
  67.     @Override
  68.     public boolean onTouch(View v, MotionEvent motionEvent) {
  69.         for (int i = 0; i < motionEvent.getPointerCount(); i++) {
  70.             int x = (int) motionEvent.getX();
  71.             int y = (int) motionEvent.getY();
  72.             int s = 2 * size;
  73.             bubbleList.add(new Bubble(x, y, s));
  74.         }
  75.         return true;
  76.     }
  77.  
  78.  
  79.     private class Bubble {
  80.         private int x;
  81.         private int y;
  82.         private int size;
  83.         private int color;
  84.         public Bubble (int newX, int newY, int newSize) {
  85.             x    = newX;
  86.             y    = newY;
  87.             size = newSize;
  88.             color = Color.argb(rand.nextInt(256),
  89.                     rand.nextInt(256),
  90.                     rand.nextInt(256),
  91.                     rand.nextInt(256));
  92.         }
  93.          public  void draw(Canvas canvas) {
  94.             paint.setColor(color);
  95.             canvas.drawOval(x - size / 2, y - size / 2,
  96.                     x + size / 2, y + size / 2, paint);
  97.         }
  98.     }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement