Giter Club home page Giter Club logo

javasim's Introduction

Table of Contents

  1. Features
  2. Installation
  3. Example
  4. Building From Source

JavaSim

Java simulation framework.

Features

  • Easy to extend Simulation class.
    • provides a sort of canvas to draw on.
    • easy animation with repeatedly-called "draw" function.
  • Program that reads your extended class can:
    • save generated images.
    • create animations.
    • run at variable rates.
    • run frame-by-frame.
    • view in full screen.

Installation

See the latest releases for downloads.

After running the application for the first time, a folder called JavaSim should appear in your Documents folder. Jar files for JavaSim simulations placed here will appear on the application's main screen. They can then be selected to load the simulation.

Example

The following program is designed to generate an image of a nephroid. Running File โ†’ Create Animated Gif with the default settings saves this image:

Nephroid Example

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;

import com.marklalor.javasim.simulation.preset.BlankImageSimulation;

//Last updated with JavaSim 1.3.0
package com.marklalor.simulation;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;

import com.marklalor.javasim.simulation.preset.BlankImageSimulation;

//Last updated with JavaSim 1.3.0
public class Nephroid extends BlankImageSimulation
{
    @Override
    public void draw(Graphics2D graphics)
    {
        //Move the origin from the corner to the center.
        graphics.translate(getImage().getWidth()/2, getImage().getHeight()/2);
        
        //Choose a semi-transparent black color.
        graphics.setColor(new Color(0f, 0f, 0f, 0.2f));
        
        //Get a radius that is 90% of the way to the edge of the screen.
        double radius = (Math.min(getImage().getWidth(), getImage().getHeight())/2) * 0.9;
        
        //Generate points on a circle using JavaSim's built-in "n", which automatically increments.
        Point point1 = getPoint(n, radius);
        Point point2 = getPoint(n*3, radius);
        
        //Draw a line between the two points.
        graphics.drawLine(point1.x, point1.y, point2.x, point2.y);
        
        //Stop after frame 360.
        if (n == 360)
            breakpoint();
    }
    
    //Get a point on the radius of a circle.
    private static Point getPoint(double angle, double radius)
    {
        int x = (int)(radius*Math.cos(Math.toRadians(angle)));
        int y = (int)(radius*Math.sin(Math.toRadians(angle)));
        return new Point(x, y);
    }
}

This bare bones program works by overriding draw(Graphics2D permanent, Graphics2D temporary). The differences between Graphics2D permanent and Graphics2D temporary are simple. Things drawn onto permanent persist throughout an animation, whereas objects drawn on to temporary are cleared each frame. This simulation draws one semitransparent black line onto the permanent graphics each frame, connecting each angle to the angle three times it.

See the getting started page for a full introduction on how and what to use.

Building From Source

JavaSim uses Apache Ant for building and Ant Task JarBundler (Tobias Fischer's fork) for packaging for OS X.

Building requires at least Ant and a Java 7 JDK.

Quick build (only runnable jar):

git clone https://github.com/MarkLalor/JavaSim.git
cd JavaSim/build
ant create_jar

This will create JavaSim.jar in the dist directory.

Full build (runnable jar, OSX .app, and .dmg)

Requires JarBundler and osascript (will certainly not build .dmg on Windows because it relies on applescript. JarBundler for .app should work on Windows, though!)

git clone https://github.com/MarkLalor/JavaSim.git
cd JavaSim/build
ant

This will create JavaSim.app, JavaSim-x.y.z.dmg, and JavaSim-x.y.z.jar in the dist directory.

javasim's People

Contributors

rowdyrotifer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.