Inspiration

We were inspired by insects as we thought they were quite cool and are fascinating

What it does

It kinda simulates how the movement of insects looks like from a distance

How we built it

We built it soley using java as that is what we have the most expierence with

Challenges we ran into

We originally wanted to make it a slime simulation but ran into some issues as the slimes did not behave properly so we scrapped that idea and turned parts of the old code into this

Accomplishments that we're proud of

We are of the fact that we go something to actually work as this is our first hackathon

What we learned

We to set more realalistic goals and improve our skills to tackle more complex project

What's next for Bug Simulation animation

Turn it into the slime project we originally wanted to make

// The "Code" class. import java.awt.*; import hsa.Console;

public class Code { static Console c; // The output console

public static void main (String[] args)
{
    c = new Console (130, 200);


    int game = 1,
        numSlimes = 500;
    //2000 is doable at spee 1.5
    //best on num <= 700
    //goal is 5000
    double[] angleSlimes = new double [numSlimes];
    for (int w = 0 ; w < numSlimes ; w++)
        angleSlimes [w] = (Math.random () * 360 + 1);



    int h = 132, i = 260;
    double[] [] grid = new double [i] [h];
    double[] [] pos = new double [numSlimes] [2];
    for (int y = 0 ; y < 2 ; y++)
        for (int x = 0 ; x < numSlimes ; x++)

            pos [x] [y] = 0;


    for (int y = 0 ; y < h ; y++)
        for (int x = 0 ; x < i ; x++)
        {
            grid [x] [y] = 0;

            //c.drawRect (5 * x, 5 * y, 5, 5);
        }

    c.setColor (Color.blue);
    while (game != -1)
    {
        game++;


        //updates slimes

        updateSlimes (game, numSlimes, angleSlimes, pos, grid);

        if (game % 6 == 0)
            c.clear ();







    }
} // main method


public static void updateSlimes (int game, int numSlimes, double[] angleSlimes, double[] [] pos, double[] [] grid)
{


    double speed = 1.5;
    double[] position = new double [2];

    if (game == 2)

        position = new double[]
        {
            499, 499
        }
    ;
    for (int n = 0 ; n < numSlimes ; n++)
    {

        for (int z = 0 ; z < 132 ; z++)
            for (int a = 0 ; a < 260 ; a++)
            {

                if (grid [a] [z] > 0)
                {
                    grid [a] [z] -= 1;
                }


            }

        double[] direction = new double[]
        {
            (Math.cos (angleSlimes [n])), (Math.sin (angleSlimes [n]))
        }
        ;

        if (game > 2)

            position = new double[]
            {

                pos [n] [0], pos [n] [1]
            }

        ;


        double[] newPosition = new double[]
        {
            (position [0] + (direction [0]) * speed), (position [1] + (direction [1]) * speed)
        }
        ;



        if (1 >= newPosition [0] || newPosition [0] >= (260 * 5) - 1 || 0 + 1 >= newPosition [1] || newPosition [1] >= 132 * 5 - 1)
        {
            newPosition [0] = (Math.min (260 * 5 - 0.1, Math.max (0, newPosition [0]))); //width
            newPosition [1] = (Math.min (132 * 5 - 0.1, Math.max (0, newPosition [1]))); //high
            do
                angleSlimes [n] = (Math.random () * 360 + 1);
            while (angleSlimes [n] > 360 || angleSlimes [n] < 0);


        }


        if ((0 + 1 < newPosition [0] && newPosition [0] < 260 * 5 - 1) && (0 + 1 < newPosition [1] && newPosition [1] < 132 * 5 - 1))
        {



            int[] shift = new int[]
            {
                0, 0
            }
            ;
            //update position in table
            pos [n] [0] = newPosition [0]; //x
            pos [n] [1] = newPosition [1]; //y


            if (newPosition [0] > position [0])
                shift [0] = 1;
            else //if (newPosition [0] < position [0])
                shift [0] = -1;
            if (newPosition [1] > position [1])
                shift [1] = 1;
            else //if (newPosition [1] < position [1])
                shift [1] = -1;

            int[] e = new int[]
            {
                (int) Math.round (position [0]), (int) Math.round (position [1])
            }
            ;
            boolean ctr = true;
            int index = 0;
            while (ctr)
            {
                e [index] += shift [index];

                c.fillRect (e [0], e [1], 2, 2);

                if (shift [index] == 1 && e [index] >= Math.round (newPosition [index]))
                    index++;
                else if (shift [index] == -1 && e [index] <= Math.round (newPosition [index]))
                    index++;
                if (index > 1)
                    ctr = false;


            }

            //
            /*
                newPosition [0] = newPosition [0] / 5;
                Math.round(newPosition [0]);
                int x = (int) newPosition [0];

                newPosition [1] = newPosition [1] / 5;
                Math.round(newPosition [1]);
                int y = (int) newPosition [1];

                grid [x] [y] = grid [x] [y] + 6;
            */

            //

        }
    }
}




public static void delay (int millisecs)  // Delay Method
{
    try
    {
        Thread.currentThread ().sleep (millisecs);
    }


    catch (InterruptedException e)
    {
    }
}

} // Code class

Built With

Share this project:

Updates