[Solved] Particle Text: Need help !

edited May 2016 in How To...

Hi, Can anyone tell me how to create text with particles? Just explain me so that I can develop my own code. I have seen so many code on openprocessing but I was unable to understand.

Answers

  • edited April 2014 Answer ✓

    I failed miserably to answer your chain question correctly so I think think answer will be going that same route. -_- I am guessing you are meaning that you want to form letters with particles. I guess I'll throw some fragments of code together my way and slowly break it down so you can assemble a master program.

    My steps to program this something like what you were talking about:

    Start by setting up a main program and a particle class ready to receive an x & y co-ordinate and make an empty ArrayList that we can add the classes into. I would then use the screen to 'mask' the shape that you want to turn into particles as the screen is a perfect stencil. If you want text then you of course just text("text", 10, 10); in your setup routine. Next you will need to find the pixels from your mask (still in setup). You could use the pixels[] array but for simplistic purposes i'm going to use get(); You will need to have a loop inside a loop (x & y) ready to read the pixels: for(int x = 0; x < width; x++) { for(int y = 0; y < height; y++) {

    Now inside your loops you will want to have a test for if your text is in that pixel or not by using get(x, y); to look for the colour of your text. If your if() returns your correct text colour then add a particle to your ArrayList with particles.add(new particle(x, y)); Lastly you can display and update your particles at your own taste with all the cool effects you want <3.

    Here is my code if you can't assemble it from these steps:

    ArrayList particles = new ArrayList();
    void setup() {
      size(200, 200);
      background(0);
      fill(255);
      textSize(90);
      text("DC", 30, 130);
      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          if (get(x, y) == color(255)) {
            particles.add(new Particle(x, y));
          }
        }
      }
    }
    void draw() {
      background(0);
      for (int i = 0; i < particles.size(); i++) {
        Particle p = (Particle) particles.get(i);
        p.display();
        p.update();
      }
    }
    class Particle {
      int x, y;
      Particle(int x0, int y0) {
        x = x0;
        y = y0;
      }
      void display() {
        stroke(255, 0, 0);
        point(x, y);
      }
      void update() {
        x += floor(random(-1, 2));
        y += floor(random(-1, 2));
      }
    }
    
  • Another approach is to use the Geomerative library, which lets you get points on the outline of a font. Each point can be a particle.

  • edited April 2014

    @velvetkevorkian Thanks for telling me about the library :) which I definitely use in the future but I am new processing user and I am learning how to do creative coding without any library but ya it would be easier for me to use these library, thanks again. :)

    @DCRaven First of all thank you so much ! I understood your code in one glance. :) It is pretty easy, get the pixel color if it is red add a particle and then move them. Exactly what I wanted and you were not failed to help me in my last post. :)

    Second, I am really sorry if I was rude in my last post. Actually English is not my mother language so constructing sentences for me a bit difficult. :(

    Also I have used your code from the last post and implement similar effect in my code and honestly saying your code was really helpful. Actually, I wanted someone to correct my linkage code which blyk did, thanks to him too.

    At last I would show you my experiments with your code. :) thanks again :)

  • Answer ✓

    Yes If you had a project you wanted me to see I would gladly take a look at your work :)

Sign In or Register to comment.