Sunday, 10 March 2024

Friday, 10 November 2023

Vector Field Simulator in Java

Mainly a Java port of https://github.com/anvaka/fieldplay (This is what happens when you try to recreate code just from looking at its output)

Depends on OpenSimplex2S for particular demos.


(Video file has reduced resolution than original.)



Thursday, 23 March 2023

Evolving the Monalisa with Genetic Algorithm

This is a demo run of a Java project to evolve a rudimentary impression of "Monalisa" with respect to the given target. 500 translucent rectangles are used with a pseudo Genetic Algorithm (only mutation). Hyperparameters are set manually and adapted to the image fitness score. Manhattan distance measure between the pixel colors is used for calculating the fitness score. The video is played at 4x the real speed. 

Friday, 4 February 2022

WordlePC: Desktop version of Wordle, written in Java

  • The popular word game Wordle has finally been released in desktop .exe format.
  • The program is written in Java, packed as Runnable Jar and wrapped with Launch4j.
  • The program requires JRE7 to run.
  • Download the file from here.
  • As the program doesn't have any certificate to prove its validity, the Google Drive download site might portray the file as "dangerous". Rest assured that it is not.

Sunday, 3 October 2021

BlockBreaker Game in Java

  • This is a simple BlockBreaker game in Java with multiple levels.
  • Download the .exe file from here.
  • Use the left and right keys to control the paddle.

Interactive Fiction/Text Game in Java

    This is a simple Interactive Fiction interface made in Java. The user can control the character in the game by typing simple instructions like "GET KEY" ,"RUN NORTH" ,etc. The game is not case-sensitive. However, object names have to be referred to using the given name ID. Using "BOX" , or "WOODEN BOX" where the shown name is "WOODEN_BOX" will not work. The user has to type "WOODEN_BOX" only. New levels will be added soon.

  • Go to this drive link.
  • Read the README.txt file for instructions.
  • After following the steps mentioned in the README file, read the instructions on the command prompt window that should have popped open now. Type HELP and press enter for more information

Wednesday, 7 July 2021

Derivative Calculator in Java

Download the .exe file from here

This derivative calculator calculates over dx.

Press f11 for further information while running the .exe file

Hyperbolic trigonometric functions are not allowed. Use normal maths syntax and * for multiplication.

The .exe file has not been signed, so it may be displayed as malware in the drive download link.


Monday, 10 May 2021

Snake Game for Android/iOS/iPhone Systems

  • This is a simple snake game made using HTML
  • This can be used on basically on Firefox, Chrome, IE and few others. This is because only this browsers support the canvas tag used in the code.
  • Just download the file from the Google Drive link and then run it on your Android/iOS/iPhone system.
  • Click here for the drive link.

Tuesday, 13 April 2021

Snake Game: Java

Download the .exe from here to play the game.

The game requires JRE 7 which can be downloaded here

Saturday, 3 April 2021

Java 3D Rotation (with Perspective, Color and Mouse Control)

  • The view can be controlled by dragging the mouse over the JFrame.
  • The first part in the main method labelled DYNAMIC can be edited to change the JFrame size (i.e, the view size) and the opacity of the objects.
  • Run the code in a file named vrjar
  • The jar can be downloaded from here (requires JRE 7 that can be downloaded here)

import java.awt.AWTException;

import java.awt.Color;

import java.awt.Graphics;

import java.awt.MouseInfo;

import java.awt.Point;

import java.awt.Robot;

import java.awt.event.InputEvent;

import java.awt.event.MouseEvent;

import java.awt.event.MouseMotionAdapter;

 

import javax.swing.JFrame;

import javax.swing.JPanel;

 

public class vrjar {

 

       @SuppressWarnings("serial")

       public static void main(String[] args) throws InterruptedException {

              //Dynamic

              final int s = 300;

              final int op = 20;

              //Statics

              final JFrame frm = new JFrame("3DViewer");

              frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              frm.setSize(s + 15, s + 39);

              frm.setLayout(null);

              frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              final pointcolor a[] = new pointcolor[(s + 1) * (s + 1) * (s + 1)];

              final int ct[] = {0};

              for (int i = 0; i < s; i++) {

                     a[ct[0]] = new pointcolor(s / 2, s / 2, i, Color.green);

                     ct[0]++;

                     a[ct[0]] = new pointcolor(s / 2, i, s / 2, Color.red);

                     ct[0]++;

                     a[ct[0]] = new pointcolor(i, s / 2, s / 2, Color.blue);

                     ct[0]++;

              }

              for (int i = s / 2 - 50; i < s / 2 + 50; i++) {

                     for (int j = s / 2 - 50; j < s / 2 + 50; j++) {

                           a[ct[0]] = new pointcolor(i, j, s / 2 + 50, Color.blue);

                           ct[0]++;

                           a[ct[0]] = new pointcolor(i, j, s / 2 - 50, Color.blue);

                           ct[0]++;

                     }

              }

              for (int i = s / 2 - 50; i < s / 2 + 50; i++) {

                     for (int j = s / 2 - 50; j < s / 2 + 50; j++) {

                           a[ct[0]] = new pointcolor(i, s / 2 + 50, j, Color.green);

                           ct[0]++;

                           a[ct[0]] = new pointcolor(i, s / 2 - 50, j, Color.green);

                           ct[0]++;

                     }

              }

              for (int i = s / 2 - 50; i < s / 2 + 50; i++) {

                     for (int j = s / 2 - 50; j < s / 2 + 50; j++) {

                           a[ct[0]] = new pointcolor(s / 2 + 50, i, j, Color.red);

                           ct[0]++;

                           a[ct[0]] = new pointcolor(s / 2 - 50, i, j, Color.red);

                           ct[0]++;

                     }

              }

              for(int i=s/2-50;i<s/2+50;i++){

                     a[ct[0]]=new pointcolor(s/2-50,s/2-50,i,Color.black);ct[0]++;

                     a[ct[0]]=new pointcolor(s/2+50,s/2-50,i,Color.black);ct[0]++;

                     a[ct[0]]=new pointcolor(s/2-50,s/2+50,i,Color.black);ct[0]++;

                     a[ct[0]]=new pointcolor(s/2+50,s/2+50,i,Color.black);ct[0]++;

                     a[ct[0]]=new pointcolor(s/2-50,i,s/2-50,Color.black);ct[0]++;

                     a[ct[0]]=new pointcolor(s/2+50,i,s/2-50,Color.black);ct[0]++;

                     a[ct[0]]=new pointcolor(s/2-50,i,s/2+50,Color.black);ct[0]++;

                     a[ct[0]]=new pointcolor(s/2+50,i,s/2+50,Color.black);ct[0]++;

                     a[ct[0]]=new pointcolor(i,s/2-50,s/2-50,Color.black);ct[0]++;

                     a[ct[0]]=new pointcolor(i,s/2+50,s/2-50,Color.black);ct[0]++;

                     a[ct[0]]=new pointcolor(i,s/2-50,s/2+50,Color.black);ct[0]++;

                     a[ct[0]]=new pointcolor(i,s/2+50,s/2+50,Color.black);ct[0]++;

              }

              for (int i = 0; i < s; i++) {

                     for (int j = 0; j < s; j++) {

                           for (int k = 0; k < s; k++) {

                                  double x = i - s / 2;

                                  double y = j - s / 2;

                                  double z = k - s / 2;

                                  double acc = 2;

                                  double lhs = x*x+y*y+z*z;

                                  double rhs = 2500;

                                  if (Math.floor((lhs) / Math.pow(10, acc)) * Math.pow(10, acc) == Math.floor((rhs) / Math.pow(10, acc)) * Math.pow(10, acc)) {

                                         a[ct[0]] = new pointcolor(i, j, k, Color.yellow);

                                         ct[0]++;

                                  }

                           }

                     }

              }

              final JPanel pnl[] = {new JPanel()};

              final Point loc[] = {new Point(0, 0)};

              final double xthet[] = {0};

              final double ythet[] = {0};

              final int sens = 1;

              frm.addMouseMotionListener(new MouseMotionAdapter() {

                     @Override

                     public void mouseMoved(MouseEvent arg0) {

                           loc[0] = MouseInfo.getPointerInfo().getLocation();

                     }

                     @Override

                     public void mouseDragged(MouseEvent arg0) {

                           frm.remove(pnl[0]);

                           double xthl = xthet[0];

                           double ythl = ythet[0];

                           if (Math.abs(loc[0].y - arg0.getYOnScreen()) > Math.abs(loc[0].x - arg0.getXOnScreen())) {

                                  xthl = Math.toRadians(360 + (loc[0].y - arg0.getYOnScreen()) % 360 / sens) + xthet[0];

                           } else {

                                  ythl = Math.toRadians(360 + (-loc[0].x + arg0.getXOnScreen()) % 360 / sens) + ythet[0];

                           }

                           final double xth = xthl;

                           final double yth = ythl;

                           loc[0] = arg0.getLocationOnScreen();

                           xthet[0] = xth;

                           ythet[0] = yth;

                           //final double loc[][]=new double[s+100][s+100];

                           pnl[0] = new JPanel() {

                                  @Override

                                  protected void paintComponent(Graphics g) {

                                         g.setColor(Color.black);

                                         for (int i = 0; i < ct[0]; i++) {

                                                double x = a[i].x - s / 2;

                                                double y = a[i].y - s / 2;

                                                double z = a[i].z - s / 2;

                                                //X-Yaw

                                                double ytemp = y;

                                                y = Math.cos(xth) * y - Math.sin(xth) * z;

                                                z = Math.cos(xth) * z + Math.sin(xth) * ytemp;

                                                //Y-Pitch

                                                double xtemp = x;

                                                x = x * Math.cos(yth) + z * Math.sin(yth);

                                                z = z * Math.cos(yth) - xtemp * Math.sin(yth);

                                                g.setColor(new Color(0, 0, 0, 1f));

                                                double d = (z + s) / 360;

                                                if (a[i].x == s - 1 && a[i].y == s / 2 && a[i].z == s / 2) {

                                                       g.drawString("X", (int)(x * d + s / 2), (int)(y * d + s / 2));

                                                }

                                                if (a[i].x == s / 2 && a[i].y == s - 1 && a[i].z == s / 2) {

                                                       g.drawString("Y", (int)(x * d + s / 2), (int)(y * d + s / 2));

                                                }

                                                if (a[i].x == s / 2 && a[i].y == s / 2 && a[i].z == s - 1) {

                                                       g.drawString("Z", (int)(x * d + s / 2), (int)(y * d + s / 2));

                                                }

                                                /*if (z>=loc[(int) (x+s/2)][(int) (y+s/2)]) {

                    loc[(int) (x+s/2)][(int) (y+s/2)]=z;*/

                                                g.setColor(new Color(a[i].col.getRed(), a[i].col.getGreen(), a[i].col.getBlue(), op));

                                                g.fillRect((int)(x * d + s / 2), (int)(y * d + s / 2), 2, 2);

                                                //}

 

                                         }

                                  }

                           };

                           pnl[0].setSize((int)(s * Math.sqrt(3)), (int)(s * Math.sqrt(3)));

                           frm.add(pnl[0]);

                           frm.invalidate();

                           frm.validate();

                           frm.repaint();

 

                     }

              });

              frm.setVisible(true);

              try {

                     Robot r=new Robot();

                     r.mouseMove(frm.getLocation().x+40, frm.getLocation().y+40);

                     r.mousePress(InputEvent.BUTTON2_DOWN_MASK);

                     r.mouseMove(frm.getLocation().x+30, frm.getLocation().y+30);

                     r.mouseRelease(InputEvent.BUTTON2_DOWN_MASK);

              } catch (AWTException e) {

                     // TODO Auto-generated catch block

                     e.printStackTrace();

              }

 

       }

 

}





Algorithmic Pixel Art: The Beauty of Aliasing

Discussed  here More images in  Google drive Some outputs: Forward to anyone who says aliasing is ugly.