How to draw circles to form letters

Hello, I'm new to use processing, and quite excited to discover all the things that we can do with it.

I would like to know if there is a way to draw geometric shapes (circles, rectangles, lines, etc. ) following a path which represent letters. For example I would like to use many circles to make a letter "a" or "b", etc.

I will look like something like this :

If there is no way, I guess I will need to generate manually the path for each letters...

Thank you!

Answers

  • edited March 2018 Answer ✓
    PImage img;
    
    void setup() {
      size(800, 600);
      textSize(300);
      background(0);
      fill(255);
      textAlign(CENTER);
      text("DOG", 400, 400);
      img = get();
      background(255);
    }
    
    void draw() {
      float x, y, r;
      background(255);
      for ( int t = 0; t < 10000; t++) {
        x = random(width);
        y = random(height);
        if ( img.get(int(x), int(y)) != color(0) ) {
          stroke(255, 0, 0);
          if ( random(1) < .5 ) {
            stroke(0);
          }
          r = random(2, 6);
          strokeWeight(random(1,3));
          fill(255);
          ellipse(x, y, r, r);
        }
      }
      noLoop();
    }
    
    void mousePressed(){
      redraw();
    }
    
  • Answer ✓
    PImage img;
    
    class Spot {
      float x, y, r, w, dx, dy, s;
      boolean isRed;
      Spot() {
        x = random(width);
        y = random(height);
        while ( !on() ) {
          x = random(width);
          y = random(height);
        }  
        s = random(1, 4);
        float a = random(TWO_PI);
        dx = s*cos(a);
        dy = s*sin(a);
        r = random(2, 6);
        w = random(1, 3);
        isRed = random(1) < .5;
      }
      void draw() {
        float px = x;
        float py = y;
        x+=dx;
        y+=dy;
        if ( !on() ) {
          x = px;
          y = py;
          float a = random(TWO_PI);
          dx = s*cos(a);
          dy = s*sin(a);
        }
        strokeWeight(w);
        stroke(0);
        if ( isRed ) stroke(255, 0, 0);
        fill(255);
        ellipse(x, y, r, r);
      }
      boolean on() {
        return( img.get(int(x), int(y)) != color(0) );
      }
    }
    
    Spot[] spots = new Spot[1000];
    
    void setup() {
      size(800, 600);
      textSize(300);
      background(0);
      fill(255);
      textAlign(CENTER);
      text("DOG", 400, 400);
      img = get();
      background(255);
      for ( int t = 0; t < spots.length; t++) {
        spots[t] = new Spot();
      }
    }
    
    void draw() {
      background(255);
      for( Spot s : spots ) s.draw();
    }
    
  • Answer ✓
    PImage img;
    
    class Spot {
      float x, y, r, w, dx, dy, s;
      boolean isRed, locked;
      Spot() {
        x = random(width);
        y = random(height);
        //while ( !on() ) {
        //  x = random(width);
        //  y = random(height);
        //}  
        s = random(1, 4);
        float a = random(TWO_PI);
        dx = s*cos(a);
        dy = s*sin(a);
        r = random(2, 6);
        w = random(1, 3);
        isRed = random(1) < .5;
        locked = false;
      }
      void draw() {
        float px = x;
        float py = y;
        x+=dx;
        y+=dy;
        x+=width;
        y+=height;
        x%=width;
        y%=height;
        if ( on() ) {
          //if( !isRed ){
            locked = true;
          //}
        } else if( locked ) {
          x = px;
          y = py;
          float a = random(TWO_PI);
          dx = s*cos(a);
          dy = s*sin(a);
        }
        strokeWeight(w);
        stroke(0);
        if ( isRed ) stroke(255, 0, 0);
        fill(255);
        ellipse(x, y, r, r);
      }
      boolean on() {
        return( img.get(int(x), int(y)) != color(0) );
      }
    }
    
    Spot[] spots = new Spot[1000];
    
    void setup() {
      size(800, 600);
      textSize(300);
      background(0);
      fill(255);
      textAlign(CENTER);
      text("CAT", 400, 400);
      img = get();
      background(255);
      for ( int t = 0; t < spots.length; t++) {
        spots[t] = new Spot();
      }
    }
    
    void draw() {
      background(255);
      for( Spot s : spots ) s.draw();
    }
    
  • Wow, that's amazing! And the alternative solutions with moving circles are wonderful! Thanks a lot!!

Sign In or Register to comment.