Skip to content

alyrow/Nebula-Generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nebula-Generator

A nebula generator written with libgdx

Ensure that you have jitpack dependencies source in your build.gradle:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Then, add this dependency:

dependencies {
	implementation 'com.github.alyrow:Nebula-Generator:v1.1.0'
}

Basic usages

A generator is defined by:

NebulaGenerator generator = new NebulaGenerator(width, height, noise_type, seed, octave,
                color, alpha, offset);

Where width and height are the size of the nebula, noise_type, seed and octave are settings wich define how the nebula looks. color defines the color of the nebula and alpha the level of alpha of the nebula. offset defines the displacement of the nebula.

After that you can generate the nebula to a pixmap or a texture with:

generator.generatePixmapNebula()
// Or
generator.generateTextureNebula()

If you want to combine multiple nebula, use NebulasGenerator:

NebulasGenerator nebulasGenerator = new NebulasGenerator(width, height);
nebulasGenerator.addGenerator(generator1);
nebulasGenerator.addGenerator(generator2);

Where width and height are the size of nebulas and generator1 and generator2 are NebulaGenerator.

After that you can generate nebulas to a pixmap or a texture with:

nebulasGenerator.generatePixmapNebulas()
// Or
nebulasGenerator.generateTextureNebulas()

You can also combine your nebula with another pixmap for exemple with stars, with or without gamma correction:

With NebulaGenerator:

Without gamma correction:
generator.generatePixmapNebulaBlendedWithAPixmap(your_pixmap_ex_stars);
// Or
generator.generateTextureNebulaBlendedWithAPixmap(your_pixmap_ex_stars);
With gamma correction:
generator.generatePixmapNebulaBlendedWithAPixmapGammaCorrection(your_pixmap_ex_stars);
// Or
generator.generateTextureNebulaBlendedWithAPixmapGammaCorrection(your_pixmap_ex_stars);

With NebulasGenerator:

Without gamma correction:
nebulasGenerator.generatePixmapNebulasBlendedWithAPixmap(your_pixmap_ex_stars);
// Or
nebulasGenerator.generateTextureNebulasBlendedWithAPixmap(your_pixmap_ex_stars);
With gamma correction:
nebulasGenerator.generatePixmapNebulasBlendedWithAPixmapGammaCorrection(your_pixmap_ex_stars);
// Or
nebulasGenerator.generateTextureNebulasBlendedWithAPixmapGammaCorrection(your_pixmap_ex_stars);

Screenshots

Multiple nebulas blended with a star background:

Without gamma correction and alpha = 1
NebulaGenerator generator1 = new NebulaGenerator(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), DEFAULT, 12955341, 8,
                new Color(0.1f,0.1f,1f,1), 1f, new Vector2(0,180));

NebulaGenerator generator2 = new NebulaGenerator(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), HONEY_NOISE, 78912345, 9,
                new Color(0.8f,0.4f,0.6f,1), 1f, new Vector2(0,0));

NebulasGenerator nebulasGenerator = new NebulasGenerator(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
nebulasGenerator.addGenerator(generator1);
nebulasGenerator.addGenerator(generator2);

Pixmap nebula = nebulasGenerator.generatePixmapNebulasBlendedWithAPixmap(new Pixmap(Gdx.files.absolute("path to stars background")));

Without gamma correction and alpha = 3
NebulaGenerator generator1 = new NebulaGenerator(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), DEFAULT, 12955341, 8,
                new Color(0.1f,0.1f,1f,1), 3f, new Vector2(0,180));

NebulaGenerator generator2 = new NebulaGenerator(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), HONEY_NOISE, 78912345, 9,
                new Color(0.8f,0.4f,0.6f,1), 3f, new Vector2(0,0));

NebulasGenerator nebulasGenerator = new NebulasGenerator(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
nebulasGenerator.addGenerator(generator1);
nebulasGenerator.addGenerator(generator2);

Pixmap nebula = nebulasGenerator.generatePixmapNebulasBlendedWithAPixmap(new Pixmap(Gdx.files.absolute("path to stars background")));

With gamma correction and alpha = 1
NebulaGenerator generator1 = new NebulaGenerator(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), DEFAULT, 12955341, 8,
                new Color(0.1f,0.1f,1f,1), 1f, new Vector2(0,180));

NebulaGenerator generator2 = new NebulaGenerator(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), HONEY_NOISE, 78912345, 9,
                new Color(0.8f,0.4f,0.6f,1), 1f, new Vector2(0,0));

NebulasGenerator nebulasGenerator = new NebulasGenerator(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
nebulasGenerator.addGenerator(generator1);
nebulasGenerator.addGenerator(generator2);

Pixmap nebula = nebulasGenerator.generatePixmapNebulasBlendedWithAPixmapGammaCorrection(new Pixmap(Gdx.files.absolute("path to stars background")));

With gamma correction and alpha = 3
NebulaGenerator generator1 = new NebulaGenerator(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), DEFAULT, 12955341, 8,
                new Color(0.1f,0.1f,1f,1), 3f, new Vector2(0,180));

NebulaGenerator generator2 = new NebulaGenerator(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), HONEY_NOISE, 78912345, 9,
                new Color(0.8f,0.4f,0.6f,1), 3f, new Vector2(0,0));

NebulasGenerator nebulasGenerator = new NebulasGenerator(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
nebulasGenerator.addGenerator(generator1);
nebulasGenerator.addGenerator(generator2);

Pixmap nebula = nebulasGenerator.generatePixmapNebulasBlendedWithAPixmapGammaCorrection(new Pixmap(Gdx.files.absolute("path to stars background")));

Fog:

Yes nebula can be used for other things than nebulas! Not perfect but a good start.

NebulaGenerator generator1 = new NebulaGenerator(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), DEFAULT, 12955341, 8,
                new Color(0.8f,0.8f,0.8f,1), 1f, new Vector2(0,-380));

NebulaGenerator generator2 = new NebulaGenerator(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), HONEY_NOISE, 78912345, 9,
                new Color(0.8f,0.8f,0.8f,1), 1f, new Vector2(0,-1000));

NebulasGenerator nebulasGenerator = new NebulasGenerator(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
nebulasGenerator.addGenerator(generator1);
nebulasGenerator.addGenerator(generator2);

Pixmap nebula = nebulasGenerator.generatePixmapNebulasBlendedWithAPixmap(new Pixmap(Gdx.files.absolute("path to forest.png")));
Orgininal image:

With fog: