Added bird generator from the official project.
247
src/fr/devinsy/catgenerator/core/BirdGenerator.java
Normal file
|
@ -0,0 +1,247 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
|
||||
*
|
||||
* This file is part of CatGenerator, simple service statistics tool.
|
||||
*
|
||||
* CatGenerator is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* CatGenerator is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with CatGenerator. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package fr.devinsy.catgenerator.core;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class BirdGenerator.
|
||||
*/
|
||||
public class BirdGenerator
|
||||
{
|
||||
private static Logger logger = LoggerFactory.getLogger(BirdGenerator.class);
|
||||
|
||||
/**
|
||||
* Builds the avatar.
|
||||
*
|
||||
* @return the buffered image
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static BufferedImage buildAvatar() throws IOException
|
||||
{
|
||||
BufferedImage result;
|
||||
|
||||
String seed = RandomStringUtils.randomAlphanumeric(10);
|
||||
result = buildAvatar(seed);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the avatar.
|
||||
*
|
||||
* @param size
|
||||
* the size
|
||||
* @return the buffered image
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static BufferedImage buildAvatar(final int size) throws IOException
|
||||
{
|
||||
BufferedImage result;
|
||||
|
||||
result = buildAvatar();
|
||||
result = CatGeneratorUtils.resize(result, size, size);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the cat.
|
||||
*
|
||||
* @param seed
|
||||
* the seed
|
||||
* @param size
|
||||
* the size
|
||||
* @throws IOException
|
||||
*/
|
||||
public static BufferedImage buildAvatar(final String seed) throws IOException
|
||||
{
|
||||
BufferedImage result;
|
||||
|
||||
if (StringUtils.isBlank(seed))
|
||||
{
|
||||
result = buildAvatar();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create an empty image.
|
||||
result = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D grapher = result.createGraphics();
|
||||
grapher.setBackground(Color.WHITE);
|
||||
grapher.clearRect(0, 0, 256, 256);
|
||||
|
||||
// Add stuff.
|
||||
// Initialize the random generator.
|
||||
Random generator = new Random(Integer.parseInt(DigestUtils.md5Hex(seed).substring(0, 6), 16));
|
||||
drawImage(grapher, "tail", generator.nextInt(9) + 1);
|
||||
drawImage(grapher, "hoop", generator.nextInt(10) + 1);
|
||||
drawImage(grapher, "body", generator.nextInt(9) + 1);
|
||||
drawImage(grapher, "wing", generator.nextInt(9) + 1);
|
||||
drawImage(grapher, "eyes", generator.nextInt(9) + 1);
|
||||
drawImage(grapher, "bec", generator.nextInt(9) + 1);
|
||||
drawImage(grapher, "accessorie", generator.nextInt(20) + 1);
|
||||
|
||||
grapher.dispose();
|
||||
}
|
||||
//
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the cat.
|
||||
*
|
||||
* @param seed
|
||||
* the seed
|
||||
* @param size
|
||||
* the size
|
||||
* @return the buffered image
|
||||
* @throws IOException
|
||||
*/
|
||||
public static BufferedImage buildAvatar(final String seed, final int size) throws IOException
|
||||
{
|
||||
BufferedImage result;
|
||||
|
||||
BufferedImage avatar = buildAvatar(seed);
|
||||
result = CatGeneratorUtils.resize(avatar, size, size);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate cat logo.
|
||||
*
|
||||
* @param seed
|
||||
* the seed
|
||||
* @param target
|
||||
* the target
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static void buildAvatarFromPeeperCarrotWebsite(final String seed, final File target) throws IOException
|
||||
{
|
||||
URL source = new URL("https://www.peppercarrot.com/extras/html/2016_cat-generator/avatar.php?seed=" + seed);
|
||||
FileUtils.copyURLToFile(source, target, 5000, 5000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the avatar to.
|
||||
*
|
||||
* @param target
|
||||
* the target
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static void buildAvatarTo(final File target) throws IOException
|
||||
{
|
||||
BufferedImage result = buildAvatar();
|
||||
|
||||
ImageIO.write(result, FilenameUtils.getExtension(target.getName()), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the avatar to.
|
||||
*
|
||||
* @param size
|
||||
* the size
|
||||
* @param target
|
||||
* the target
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static void buildAvatarTo(final int size, final File target) throws IOException
|
||||
{
|
||||
BufferedImage result = buildAvatar(size);
|
||||
ImageIO.write(result, FilenameUtils.getExtension(target.getName()), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the avatar to.
|
||||
*
|
||||
* @param seed
|
||||
* the seed
|
||||
* @param target
|
||||
* the target
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static void buildAvatarTo(final String seed, final File target) throws IOException
|
||||
{
|
||||
BufferedImage result = buildAvatar(seed);
|
||||
ImageIO.write(result, FilenameUtils.getExtension(target.getName()), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the avatar to.
|
||||
*
|
||||
* @param seed
|
||||
* the seed
|
||||
* @param size
|
||||
* the size
|
||||
* @param target
|
||||
* the target
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static void buildAvatarTo(final String seed, final int size, final File target) throws IOException
|
||||
{
|
||||
BufferedImage result = buildAvatar(seed, size);
|
||||
ImageIO.write(result, FilenameUtils.getExtension(target.getName()), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw image.
|
||||
*
|
||||
* @param grapher
|
||||
* the grapher
|
||||
* @param name
|
||||
* the name
|
||||
* @param index
|
||||
* the index
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
private static void drawImage(final Graphics2D grapher, final String name, final int index) throws IOException
|
||||
{
|
||||
URL url = BirdGenerator.class.getResource("/fr/devinsy/catgenerator/core/images/cat" + name + "_" + index + ".png");
|
||||
BufferedImage part = ImageIO.read(url);
|
||||
grapher.drawImage(part, null, 0, 0);
|
||||
}
|
||||
}
|
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_1.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_10.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_11.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_12.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_13.png
Normal file
After Width: | Height: | Size: 298 B |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_14.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_15.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_16.png
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_17.png
Normal file
After Width: | Height: | Size: 298 B |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_18.png
Normal file
After Width: | Height: | Size: 298 B |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_19.png
Normal file
After Width: | Height: | Size: 298 B |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_2.png
Normal file
After Width: | Height: | Size: 298 B |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_20.png
Normal file
After Width: | Height: | Size: 298 B |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_3.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_4.png
Normal file
After Width: | Height: | Size: 298 B |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_5.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_6.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_7.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_8.png
Normal file
After Width: | Height: | Size: 3 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/accessorie_9.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/bec_1.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/bec_2.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/bec_3.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/bec_4.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/bec_5.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/bec_6.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/bec_7.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/bec_8.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/bec_9.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/body_1.png
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/body_2.png
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/body_3.png
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/body_4.png
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/body_5.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/body_6.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/body_7.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/body_8.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/body_9.png
Normal file
After Width: | Height: | Size: 4 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/eye_4.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/eye_5.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/eye_6.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/eye_7.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/eyes_1.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/eyes_2.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/eyes_3.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/eyes_8.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/eyes_9.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/hoop_1.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/hoop_2.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/hoop_3 #1.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/hoop_3.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/hoop_4.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/hoop_5.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/hoop_6.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/hoop_7.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/hoop_8.png
Normal file
After Width: | Height: | Size: 298 B |
BIN
src/fr/devinsy/catgenerator/core/images/bird/hoop_9.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/tail_1.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/tail_2.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/tail_3.png
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/tail_4.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/tail_5.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/tail_6.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/tail_7.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/tail_8.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/tail_9.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/wing_1.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/wing_2.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/wing_3.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/wing_4.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/wing_5.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/wing_6.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/wing_7.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/wing_8.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
src/fr/devinsy/catgenerator/core/images/bird/wing_9.png
Normal file
After Width: | Height: | Size: 1.8 KiB |