Advertisement
xeromino

emojiPacking

Mar 17th, 2017
164
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ArrayList<Emoji> emojis = new ArrayList<Emoji>();
  2. float minRadius = 10, maxRadius = 50;
  3. PImage img;
  4.  
  5. void setup() {
  6.   size(1080, 720);
  7.   emojis.add(new Emoji(width/2, height/2, maxRadius));
  8. }
  9.  
  10. void draw() {
  11.   background(0);
  12.  
  13.   float newX = random(maxRadius, width-maxRadius);
  14.   float newY = random(maxRadius, height-maxRadius);
  15.   float newR = random(minRadius, maxRadius);
  16.  
  17.   boolean intersection = false;
  18.  
  19.   for (int i=0; i<emojis.size(); i++) {
  20.     Emoji e = emojis.get(i);
  21.     float d = dist(newX, newY, e.x, e.y);
  22.     if (d<(newR + e.r)) {
  23.       intersection = true;
  24.       break;
  25.     }
  26.   }
  27.  
  28.   if (intersection == false) {
  29.     emojis.add(new Emoji(newX, newY, newR));
  30.   }
  31.  
  32.   for (int i=0; i<emojis.size(); i++) {
  33.     Emoji e = emojis.get(i);
  34.     e.show();
  35.   }
  36.   if (emojis.size()>120) {
  37.      minRadius = 5;
  38.      maxRadius = 20;
  39.   }
  40. }
  41.  
  42. class Emoji {
  43.  
  44.   float x, y, r;
  45.   PImage img;
  46.  
  47.   Emoji(float _x, float _y, float _r) {
  48.     x = _x;
  49.     y = _y;
  50.     r = _r;
  51.     img = loadImage("http://emoji.ink/assets/160x160/" + int(random(1, 2000)) + ".png");
  52.   }
  53.  
  54.   void show() {
  55.     img.resize(int(2*r),int(2*r));
  56.     imageMode(CENTER);
  57.     if(r<maxRadius*.8) {
  58.       img.filter(GRAY);
  59.     }
  60.     image(img, x, y);
  61.   }
  62. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement