Site3Da.java
java · 185 lines · part of White Outline (Cartoon Shading) · raw
import java.awt.image.*;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Event;
import java.awt.Image;
import java.awt.Font;
class World
{
//---- Data
double[] x, y, z, tx, ty, tz, sx, sy;
//---- Main code
public World()
{
x = new double[256];
y = new double[256];
z = new double[256];
tx = new double[256];
ty = new double[256];
tz = new double[256];
sx = new double[256];
sy = new double[256];
for(int j=0; j<num; j++) for(int i=0; i<num; i++)
{
x[i*16+j] = i-8;
y[i*16+j] = j-8;
z[i*16+j] = 0;
}
}
//---- Render
public void Render(Graphics g)
{
int i;
//- Transform
//- Screen space
for(i=0; i<256; i++)
{
sx[i] = 10.0 * tx[i] / tz[i];
sy[i] = 10.0 * ty[i] / tz[i];
}
//- Render
for(i=0; i<256; i++)
{
}
}
}
public class Site3D extends java.applet.Applet implements Runnable
{
//- Data
Thread runThread = null;
static int imw = 320, imh = 240;
Image im = null;
Graphics img = null;
int[][] buffer;
//- Main code
public void init()
{
System.out.println("LKS 3D Site v0.01");
}
public void start()
{
if(runThread == null)
{
runThread = new Thread(this);
runThread.start();
}
}
public void stop()
{
if(runThread != null)
{
runThread.stop();
runThread = null;
}
}
public void run()
{
imw = size().width;
imh = size().height;
im = createImage(imw, imh);
img = im.getGraphics();
img.setColor(Color.black);
img.fillRect(0, 0, imw, imh);
while(true)
{
repaint();
try { runThread.sleep(10); } catch (InterruptedException e) { return; }
}
}
public void update(Graphics g)
{
paint(g);
}
int k = 0;
public void paint(Graphics g)
{
if(im != null)
{
img.setColor(Color.black);
img.fillRect(0, 0, imw, imh);
g.drawImage(im, 0, 0, this);
g.setColor((k++&1) == 0 ? Color.blue : Color.yellow);
g.fillRect(0, 0, 10, 10);
}
}
int mouse_x = 0, mouse_y = 0;
int mouse_oldx = 0, mouse_oldy = 0;
boolean mouse_drag = true;
public boolean mouseDown(Event evt, int x, int y)
{
mouse_oldx = x;
mouse_oldy = y;
mouse_x = x;
mouse_y = y;
mouse_drag = true;
return true;
}
public boolean mouseDrag(Event e, int x, int y)
{
mouse_x = x;
mouse_y = y;
repaint();
return true;
}
public boolean mouseUp(Event evt, int x, int y)
{
mouse_drag = false;
return true;
}
}