diff --git a/PeceraGUI.java b/PeceraGUI.java new file mode 100644 index 0000000..1e66894 --- /dev/null +++ b/PeceraGUI.java @@ -0,0 +1,147 @@ +import javax.swing.*; +import java.awt.*; +import java.util.Random; +/** + * + * @author car20 + */ +public class PeceraGUI extends JPanel { + + private static final int ANCHO = 60; + private static final int ALTO = 20; + + private static final String[][] PECES = { + { + " ,-", + " ,/.( __", + " ,-' `!._/ /", + " > @ )<| _ <", + " `-....,,;' \\\\_" + }, + { + " ,-", + " ,/.( __", + " ,-' `!._/ /", + " > @ )<| _ <", + " `-....,,;' \\\\_" + }, + { + "|\\ \\\\__ o", + "| \\_/ o \\ o", + "> _ (( <_ oo", + "| / \\__+___/", + "|/ |/" + } + }; + + private static final String[] ALGAS = { + "⠀ ⠀⠀⠀⠀⠀⠀⣴⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀ ⠀⠀⠀⠀⣸⠛⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡏⢠⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣧⡈⢿⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⢸⣶⡀⠀⠀⠀⠀⠙⣷⣄⠙⣦⡀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⠀⣿⠿⣄⠀⠀⠀⠀⢸⣿⡆⢸⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⢀⡇⢰⣿⠂⠀⠀⠀⣸⣿⠃⣸⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀", + "⠀⠀⠀⠀⣿⠁⣼⠁⠀⠀⠀⣰⡿⠁⣴⡿⠁⠀⠀⠀⠀", + "⠀⠀⠀⠀⣿⠀⣿⣆⠀⠀⢠⣿⠇⢸⣿⠃⠀⠀⠀⠀", + "⠀⠀⠀⠀⢹⣇⠘⣿⡄⠀⠘⣿⠀⣾⣿⡀⠀⠀", + "⠀⠀⠀⠀⣸⣿⠀⣿⡇⠀⣤⠙⠀⢸⣿⣧⡀⠀⠀", + "⠀⠀⠀⣰⣿⠏⢠⣿⡇⠀⢹⣷⣤⠈⢿⠁", + "⠀⠀⠠⡿⠃⣰⣿⠟⠀⠀", + "⠀⠀⠀⠀⠊⠉⠀⠀⠀⠀⠀" + }; + + private static int[] pecesX = new int[PECES.length]; + private static int[] pecesY = new int[PECES.length]; + private static int[] direccionesX = new int[PECES.length]; + + private static final Random random = new Random(); + + private int[] burbujasX = new int[10]; + private int[] burbujasY = new int[10]; + + public PeceraGUI() { + setPreferredSize(new Dimension(ANCHO * 10, ALTO * 20)); + setBackground(Color.BLACK); + setForeground(Color.WHITE); + setFont(new Font("Monospaced", Font.PLAIN, 12)); + + for (int i = 0; i < PECES.length; i++) { + pecesX[i] = random.nextInt(ANCHO - 10) + 1; + pecesY[i] = random.nextInt(ALTO - 5) + 1; + direccionesX[i] = random.nextBoolean() ? 1 : -1; + } + + // Inicializar burbujas + for (int i = 0; i < burbujasX.length; i++) { + burbujasX[i] = random.nextInt(ANCHO - 2) + 1; + burbujasY[i] = random.nextInt(ALTO - 2) + 1; + } + + Timer timer = new Timer(200, e -> { + moverPeces(); + moverBurbujas(); + repaint(); + }); + timer.start(); + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + dibujarMar(g); + } + + private void dibujarMar(Graphics g) { + g.setColor(Color.WHITE); + + // Dibujar burbujas + for (int i = 0; i < burbujasX.length; i++) { + g.drawString("o", burbujasX[i] * 10, burbujasY[i] * 20); + } + + // Dibujar peces + for (int i = 0; i < PECES.length; i++) { + for (int j = 0; j < PECES[i].length; j++) { + g.drawString(PECES[i][j], pecesX[i] * 10, (pecesY[i] + j) * 20); + } + } + + // Dibujar algas al fondo + for (int i = 0; i < ALGAS.length; i++) { + g.drawString(ALGAS[i], 5, (ALTO * 20) - (ALGAS.length - i) * 15); + } + } + + private void moverPeces() { + for (int i = 0; i < PECES.length; i++) { + pecesX[i] += direccionesX[i]; + + if (pecesX[i] + 10 >= ANCHO || pecesX[i] <= 0) { + direccionesX[i] *= -1; + } + } + } + + private void moverBurbujas() { + for (int i = 0; i < burbujasY.length; i++) { + if (i % 2 == 0) { + burbujasY[i] -= 1; // Mover más lento + } + + if (burbujasY[i] <= 0) { + burbujasY[i] = ALTO - 2; + burbujasX[i] = random.nextInt(ANCHO - 2) + 1; + } + } + } + + public static void main(String[] args) { + JFrame frame = new JFrame("Pecera ASCII"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.add(new PeceraGUI()); + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } +} \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 3b3cb71..0000000 --- a/README.md +++ /dev/null @@ -1,7 +0,0 @@ - -Proyecto Ascii - -Bonilla Palomino Carlos Raúl - -Palestina Villa Alexis Aarón - diff --git a/ascii.java b/ascii.java deleted file mode 100644 index e69de29..0000000 diff --git a/workspace.code-workspace b/workspace.code-workspace deleted file mode 100644 index 876a149..0000000 --- a/workspace.code-workspace +++ /dev/null @@ -1,8 +0,0 @@ -{ - "folders": [ - { - "path": "." - } - ], - "settings": {} -} \ No newline at end of file