Thursday 13 August 2015

Galaxy Generation Algorithm

Today I've been thinking more about the galaxy generation, so I came up with an algorithm and implemented it. Here is how the algorithm works:

  1. Load a target image of a galaxy
  2. Divide the image into n by m cells
  3. For each cell:
    1. Sum the red, green and blue components of each pixel
    2. Calculate the average
    3. Divide by the maximum possible value (255 * width of n * height of m)
    4. Store this value for this cell -> v
    5. Calculate the rgb value for this cell with 255 * v
    6. Generate a certain number of randomly placed pixels with the rgb value found in step 3.5, the number of pixels is a user specified number multiplied by v
    7. Output image
    8. Rotate image a fraction of a degree
    9. Go back to step 1

    Here is the result:



     

No comments:

Post a Comment