home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-05-21 | 1.3 KB | 57 lines |
- // Camera.java - Onscreen Camera object
- //
- // Copyright (C) 1996 by Dale Gass
- // Non-exclusive license granted to MKS, Inc.
- //
-
- import java.lang.*;
- import java.util.*;
- import java.awt.*;
- import java.net.*;
- import java.applet.*;
-
- // Onscreen Camera object
-
- public class Camera {
- int x, y, angle;
- String describe;
-
- final static int camx[] = { -20, 20, 20, -20, -20, 0, -20, 20, 0 };
- final static int camy[] = { -10, -10, 10, 10, -10, -10, -30, -30, -10 };
-
- // Create the object with given position, angle, rotation, description
-
- public Camera(int x_, int y_, int angle_, String describe_) {
- x = x_;
- y = y_;
- angle = angle_;
- describe = describe_;
- }
-
- // Draw the object in given colour
-
- void draw(Graphics g, Color color) {
- int rotx[], roty[];
- double ran = angle * (2*Math.PI/360);
-
- rotx = new int[camx.length];
- roty = new int[camy.length];
-
- for (int i=0; i<camx.length; i++) {
- rotx[i] = (int) (Math.cos(ran) * camx[i] -
- Math.sin(ran) * camy[i]) + x;
- roty[i] = (int) (Math.cos(ran) * camy[i] +
- Math.sin(ran) * camx[i]) + y;
- }
-
- g.setColor(color);
- g.drawPolygon(rotx, roty, camx.length);
- }
-
- // Retrieve the description
-
- public String toString() {
- return describe;
- }
- }
-