1
0

More than 3 years have passed since last update.

今はなつかしやぁ、Java Applet

Last updated at Posted at 2021-08-24
::::::::::::::
AnotherStar.java
::::::::::::::
/**
* $Id: Pursuit3.html,v 1.1 2009/06/22 16:11:53 kishi Exp kishi $
* @author KISHI Yasuhiro
*/

import java.awt.Color;
import java.awt.Graphics;

public class AnotherStar {

    public AnotherStar( double d, double d1, double d2, double d3, double d4, double d5, Color color1, double d6 ) {
        cx = d;
        cy = d1;
        rx = d2;
        ry = d3;
        theta = d4;
        pitch = d5;
        color = color1;
        size = d6;
    }

    public void moveNext() {
        theta += pitch;
        x = cx + rx * Math.cos( theta );
        y = cy + ry * Math.sin( theta );
        x += 100D * Math.sin( ( -1D * theta ) / 6D );
        y += 50D * Math.cos( ( -1D * theta ) / 13D );
    }

    public void setColor( Color color1 ) {
        color = color1;
    }

    public void paint( Graphics g ) {
        g.setColor( color );
        g.fillOval( ( int ) x, ( int ) y, ( int ) size, ( int ) size );
    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }

    public int getRed() {
        return color.getRed();
    }

    public int getBlue() {
        return color.getBlue();
    }

    public int getGreen() {
        return color.getGreen();
    }

    private double x;
    private double y;
    private double cx;
    private double cy;
    private double rx;
    private double ry;
    private double size;
    private double theta;
    private double pitch;
    private Color color;
}
::::::::::::::
ColorEnum.java
::::::::::::::
/**
* $Id: Pursuit3.html,v 1.1 2009/06/22 16:11:53 kishi Exp kishi $
* @author KISHI Yasuhiro
*/

import java.awt.Color;
import java.io.PrintStream;

public class ColorEnum {

    public ColorEnum( Color color1 ) {
        color = color1;
    }

    public int getRed() {
        return color.getRed();
    }

    public int getBlue() {
        return color.getBlue();
    }

    public int getGreen() {
        return color.getGreen();
    }

    public Color getNextColor() {
        int i = getRed();
        int j = getGreen();
        int k = getBlue();
        if ( ++k > 255 ) {
            k = 0;
            if ( ++j > 255 ) {
                j = 0;
                k = 0;
                if ( ++i > 255 ) {
                    i = 0;
                    j = 0;
                    k = 0;
                }
            }
        }
        return new Color( i, j, k );
    }

    public void printCurrentStatus() {
        int i = getRed();
        int j = getGreen();
        int k = getBlue();
        System.out.println( i + "," + j + "," + k );
    }

    public static void main( String args[] ) {
        ColorEnum colorenum = new ColorEnum( new Color( 254, 254, 0 ) );
        for ( int i = 0; i < 0x186a0; i++ ) {
            Color color1 = colorenum.getNextColor();
            colorenum.printCurrentStatus();
            colorenum = new ColorEnum( color1 );
        }

    }

    private Color color;
}
::::::::::::::
Literal.java
::::::::::::::
/**
* $Id: Pursuit3.html,v 1.1 2009/06/22 16:11:53 kishi Exp kishi $
* @author KISHI Yasuhiro
*/

import java.awt.*;

public class Literal {

    public Literal() {
        font = new Font( "Dialog", 0, 32 );
    }

    public void moveNext() {
        if ( y-- < to_y )
            y = ( int ) from_y + 50;
    }

    public void setLiteral( String s ) {
        literal = s;
    }

    public void setFont( Font font1 ) {
        font = font1;
    }

    public void setColor( Color color1 ) {
        color = color1;
    }

    public Color getColor() {
        return color;
    }

    public void setXY( double d, double d1 ) {
        x = d;
        y = d1;
    }

    public void setVerticalRange( double d, double d1 ) {
        from_y = d;
        to_y = d1;
    }

    public void paint( Graphics g ) {
        g.setFont( font );
        g.setColor( color );
        g.drawString( literal, ( int ) x, ( int ) y );
    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }

    public int getRed() {
        return color.getRed();
    }

    public int getBlue() {
        return color.getBlue();
    }

    public int getGreen() {
        return color.getGreen();
    }

    private double x;
    private double y;
    private Color color;
    private String literal;
    private double from_y;
    private double to_y;
    private Font font;
}
::::::::::::::
Master.java
::::::::::::::
/**
* $Id: Pursuit3.html,v 1.1 2009/06/22 16:11:53 kishi Exp kishi $
* @author KISHI Yasuhiro
*/

public class Master {

    public Master( Star star1, double d ) {
        star = star1;
        influence = d;
    }

    public double getX() {
        return star.getX();
    }

    public double getY() {
        return star.getY();
    }

    public int getStarColorRed() {
        return star.getRed();
    }

    public int getStarColorBlue() {
        return star.getBlue();
    }

    public int getStarColorGreen() {
        return star.getGreen();
    }

    public double getInfluence() {
        return influence;
    }

    private Star star;
    private double influence;
}
::::::::::::::
Planet.java
::::::::::::::
/**
* $Id: Pursuit3.html,v 1.1 2009/06/22 16:11:53 kishi Exp kishi $
* @author KISHI Yasuhiro
*/

import java.awt.Color;
import java.awt.Graphics;

public class Planet {

    public Planet( Star star1, AnotherStar anotherstar, double d, double d1, double d2, Color color1 ) {
        star = star1;
        anotherStar = anotherstar;
        x = d;
        y = d1;
        velocity = d2;
        color = color1;
    }

    public void moveNext() {
        double d = star.getX() - x;
        double d1 = star.getY() - y;
        double d2 = anotherStar.getX() - x;
        double d3 = anotherStar.getY() - y;
        double d4 = Math.atan2( d1, d );
        double d5 = Math.atan2( d3, d2 );
        x += velocity * Math.cos( d4 );
        y += velocity * Math.sin( d4 );
        x += 0.5D * velocity * Math.cos( 2D * d5 );
        y += 0.5D * velocity * Math.sin( 0.5D * d5 );
    }

    public void paint( Graphics g ) {
        g.setColor( color );
        g.fillOval( ( int ) x, ( int ) y, 5, 5 );
    }

    private Star star;
    private AnotherStar anotherStar;
    private double x;
    private double y;
    private double velocity;
    private Color color;
}
::::::::::::::
PlanetNova.java
::::::::::::::
/**
* $Id: Pursuit3.html,v 1.1 2009/06/22 16:11:53 kishi Exp kishi $
* @author KISHI Yasuhiro
*/

import java.awt.Color;
import java.awt.Graphics;
import java.util.Enumeration;
import java.util.Vector;

public class PlanetNova {

    public PlanetNova( double d, double d1, double d2, double d3 ) {
        masters = new Vector();
        bumbo = 0.0D;
        x = d;
        y = d1;
        velocity = d2;
        size = d3;
    }

    public void addMaster( Star star, double d ) {
        masters.addElement( new Master( star, d ) );
        bumbo += d;
    }

    public void moveNext() {
        double d = 0.0D;
        r = 0.0D;
        g = 0.0D;
        r = 0.0D;
        for ( Enumeration enumeration = masters.elements(); enumeration.hasMoreElements(); ) {
            Master master = ( Master ) enumeration.nextElement();
            double d1 = master.getX() - x;
            double d2 = master.getY() - y;
            double d3 = Math.atan2( d2, d1 );
            x += ( velocity * Math.cos( d3 ) * master.getInfluence() ) / bumbo;
            y += ( velocity * Math.sin( d3 ) * master.getInfluence() ) / bumbo;
            double d4 = d1 * d1 + d2 * d2;
            r += ( double ) master.getStarColorRed() * ( 1.0D / d4 );
            g += ( double ) master.getStarColorGreen() * ( 1.0D / d4 );
            b += ( double ) master.getStarColorBlue() * ( 1.0D / d4 );
            d += 1.0D / d4;
        }

        r /= d;
        g /= d;
        b /= d;
    }

    public void paint( Graphics g1 ) {
        g1.setColor( new Color( ( int ) r % 256, ( int ) g % 256, ( int ) b % 256 ) );
        g1.drawOval( ( int ) x, ( int ) y, ( int ) size, ( int ) size );
    }

    private Vector masters;
    private double size;
    private double x;
    private double y;
    private double velocity;
    private double r;
    private double g;
    private double b;
    private double bumbo;
}
::::::::::::::
Pursuit3.java
::::::::::::::
/**
* $Id: Pursuit3.html,v 1.1 2009/06/22 16:11:53 kishi Exp kishi $
* @author KISHI Yasuhiro
*/

import java.applet.Applet;
import java.awt.*;
import java.io.PrintStream;
import java.util.*;

public class Pursuit3 extends Applet
    implements Runnable {

    public Pursuit3() {
        counter = 0;
        sleepCounter = 0;
        anime = null;
        isActive = true;
        planet = new Planet[ 100 ];
        other_planet = new Planet[ 100 ];
        planetNova = new PlanetNova[ 500 ];
        literal = new Literal();
        myFont = new Font( "Dialog", 0, 16 );
        messages = new Vector();
        literals = new Vector();
    }

    public void init() {
        d = getSize();
        x_size = d.width;
        y_size = d.height;
        offs = createImage( x_size, y_size );
        grf = offs.getGraphics();
        star = new Star( 300D, 300D, 100D, 200D, 3.1415926535897931D, 0.098174770424681035D, Color.blue, 30D );
        other_star = new Star( 320D, 300D, 300D, 200D, 3.1415926535897931D, -0.19634954084936207D, Color.green, 50D );
        vertical_star = new Star( 50D, ( double ) y_size / 2D, 0.0D, ( double ) y_size / 2D, 3.1415926535897931D, -0.1308996938995747D, Color.pink, 40D );
        anotherStar = new AnotherStar( 500D, ( double ) y_size / 2D, 100D, ( double ) y_size / 3D, 1.5707963267948966D, -0.065449846949787352D, Color.gray, 20D );
        for ( int i = 0; i < planet.length; i++ )
            planet[ i ] = new Planet( star, anotherStar, 0.1F * ( float ) i, 0.0D, 0.3F * ( float ) ( i + 1 ), new Color( ( 256 - planet.length ) + i, ( 256 - planet.length ) + i, 255 ) );

        for ( int j = 0; j < other_planet.length; j++ )
            other_planet[ j ] = new Planet( other_star, anotherStar, ( double ) x_size / 2D, ( double ) y_size - ( double ) ( 5F * ( float ) j ), 9D * Math.sin( ( ( double ) ( j + 1 ) * 3.1415926535897931D ) / ( double ) ( other_planet.length + 1 ) ), new Color( ( 256 - planet.length ) + j, 255 - j, 64 ) );

        for ( int k = 0; k < planetNova.length; k++ ) {
            Random random = new Random( k * 29 );
            Random random1 = new Random( k * 31 );
            Random random2 = new Random( k * 37 );
            Random random3 = new Random( k * 41 );
            Random random4 = new Random( k * 43 );
            planetNova[ k ] = new PlanetNova( 5D * random.nextGaussian() + 100D, 5F * ( float ) k + 200F, 0.6F * ( float ) ( k + 1 ), 3D + 5D * random1.nextGaussian() );
            planetNova[ k ].addMaster( star, 1.0D + random2.nextGaussian() );
            planetNova[ k ].addMaster( other_star, 2D + random3.nextGaussian() );
            planetNova[ k ].addMaster( vertical_star, 3D + random4.nextGaussian() );
        }

        messages.addElement( "\u30FB\u30FB\u30FBSpiral forever\u30FB\u30FB\u30FB" );
        messages.addElement( "Nothing's gonna change my world\u266A" );
        messages.addElement( "I'm  only scrolling over and over again. " );
        messages.addElement( "" );
        messages.addElement( "" );
        messages.addElement( "" );
        double d1 = 200D;
        for ( Enumeration enumeration = messages.elements(); enumeration.hasMoreElements(); ) {
            Literal literal1 = new Literal();
            literal1.setXY( 300D, d1 );
            literal1.setVerticalRange( y_size, 0.0D );
            literal1.setFont( new Font( "Dialog", 0, 10 ) );
            literal1.setColor( Color.blue );
            literal1.setLiteral( ( String ) enumeration.nextElement() );
            literals.addElement( literal1 );
            d1 += 20D;
        }

    }

    public void start() {
        if ( anime == null ) {
            anime = new Thread( this );
            anime.start();
        }
    }

    public void paint( Graphics g ) {
        grf.setColor( Color.black );
        grf.fillRect( 0, 0, x_size, y_size );
        star.moveNext();
        vertical_star.moveNext();
        anotherStar.moveNext();
        if ( isActive ) {
            if ( counter < 80 ) {
                grf.setColor( Color.green );
            } else {
                grf.setColor( Color.yellow );
                other_star.setColor( Color.yellow );
            }
            grf.setFont( myFont );
            grf.drawString( "\u73FE\u5728\u6D3B\u52D5\u4E2D...", 0, 20 );
            other_star.moveNext();
            if ( counter++ > 100 ) {
                isActive = false;
                sleepCounter = 0;
                other_star.setColor( Color.red );
            }
        } else {
            grf.setColor( Color.red );
            grf.setFont( myFont );
            grf.drawString( "\u73FE\u5728\u4F11\u6B62\u4E2D...", 0, 20 );
            if ( sleepCounter++ > 100 ) {
                isActive = true;
                counter = 0;
                other_star.setColor( Color.green );
            }
        }
        for ( int i = 0; i < planet.length; i++ )
            planet[ i ].moveNext();

        for ( int j = 0; j < other_planet.length; j++ )
            other_planet[ j ].moveNext();

        for ( int k = 0; k < planetNova.length; k++ )
            planetNova[ k ].moveNext();

        Literal literal1;
        for ( Enumeration enumeration = literals.elements(); enumeration.hasMoreElements(); literal1.moveNext() )
            literal1 = ( Literal ) enumeration.nextElement();

        star.paint( grf );
        other_star.paint( grf );
        vertical_star.paint( grf );
        anotherStar.paint( grf );
        for ( int l = 0; l < planet.length; l++ )
            planet[ l ].paint( grf );

        for ( int i1 = 0; i1 < other_planet.length; i1++ )
            other_planet[ i1 ].paint( grf );

        for ( int j1 = 0; j1 < planetNova.length; j1++ )
            planetNova[ j1 ].paint( grf );

        Literal literal2;
        for ( Enumeration enumeration1 = literals.elements(); enumeration1.hasMoreElements(); literal2.paint( grf ) )
            literal2 = ( Literal ) enumeration1.nextElement();

        g.drawImage( offs, 0, 0, x_size, y_size, this );
    }

    public void update( Graphics g ) {
        paint( g );
    }

    public void run() {
        while ( anime != null ) {
            repaint();
            try {
                Thread.sleep( 1L );
            } catch ( InterruptedException interruptedexception ) {
                System.out.println( "Error: " + interruptedexception );
            }
        }
    }

    private Dimension d;
    private Image offs;
    private Graphics grf;
    private int counter;
    private int sleepCounter;
    private Thread anime;
    private int x_size;
    private int y_size;
    private boolean isActive;
    private Star star;
    private Star other_star;
    private Star vertical_star;
    private AnotherStar anotherStar;
    private Planet planet[];
    private Planet other_planet[];
    private PlanetNova planetNova[];
    private Literal literal;
    private Font myFont;
    private Vector messages;
    private Vector literals;
}
::::::::::::::
Star.java
::::::::::::::
/**
* $Id: Pursuit3.html,v 1.1 2009/06/22 16:11:53 kishi Exp kishi $
* @author KISHI Yasuhiro
*/

import java.awt.Color;
import java.awt.Graphics;

public class Star {

    public Star( double d, double d1, double d2, double d3, double d4, double d5, Color color1, double d6 ) {
        cx = d;
        cy = d1;
        rx = d2;
        ry = d3;
        theta = d4;
        pitch = d5;
        color = color1;
        size = d6;
    }

    public void moveNext() {
        theta += pitch;
        x = cx + rx * Math.cos( theta );
        y = cy + ry * Math.sin( theta );
    }

    public void setColor( Color color1 ) {
        color = color1;
    }

    public void paint( Graphics g ) {
        g.setColor( color );
        g.fillOval( ( int ) x, ( int ) y, ( int ) size, ( int ) size );
    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }

    public int getRed() {
        return color.getRed();
    }

    public int getBlue() {
        return color.getBlue();
    }

    public int getGreen() {
        return color.getGreen();
    }

    private double x;
    private double y;
    private double cx;
    private double cy;
    private double rx;
    private double ry;
    private double size;
    private double theta;
    private double pitch;
    private Color color;
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0