All pastes #207331 Raw Edit

Something

public java v1 · immutable
#207331 ·published 2006-10-17 23:22 UTC
rendered paste body
import java.awt.*;import java.awt.image.*;import java.io.*;class WriteIt{	public static void main(String[] args)	{		SceneWriter sw = new SceneWriter("tzm.gif", 3, 20, 36);		FileOutputStream out;		PrintStream ps;		try		{			out = new FileOutputStream("woo.pov");			ps = new PrintStream(out);			sw.writeShit(ps);		}		catch(Exception e)		{			System.out.println("Feil: " + e);		}	}}class SceneWriter{	PixelShip[] ship;	int ships;	public SceneWriter(String inFile, int ships, int shipWidth, int shipHeight)	{		this.ships = ships;		PixelShip.setSize(shipWidth, shipHeight);		ship = new PixelShip[ships];		transferPixels(inFile, ship);	}	public void writeShit(PrintStream ps)	{		// header++		ps.println("#include \"brick.inc\"\n");		int centerX = PixelShip.width * ships;		ps.println("camera\n{\n\tlocation <" + centerX + ",20,-10>\n\tlook_at <" + centerX + ",0,18>\n}\n");		ps.println("light_source\n{\n\t<50,80,-80>\n\trgb 1\n}\n");		for(int i = 0; i < ships; i++)		{			ship[i].writeBrickShip(ps, i);		}	}	private void transferPixels(String fileName, PixelShip [] target)	{		int w = PixelShip.width;		int h = PixelShip.height;		int[] pix = new int[w * h];		Image tempImage;		PixelGrabber pg;		for(int q = 0; q < ships; q++)		{			tempImage = null;			tempImage = Toolkit.getDefaultToolkit().createImage(fileName);			pg = null;			pg = new PixelGrabber(tempImage, q * w, 0, w, h, pix, 0, w);			try			{				pg.grabPixels();			}			catch(Exception e)			{				System.out.println("Feil: " + e);			}			ship[q] = new PixelShip();			ship[q].setPixels(pix);		}	}}class PixelShip{	Pixel[][] pixel;	static int width, height;	public PixelShip()	{		pixel = new Pixel[height][width];	}	public static void setSize(int w, int h)	{		width = w;		height = h;	}	public void setPixels(int[] srcPixel)	{		for(int y = 0; y < height; y++)		{			for(int x = 0; x < width; x++)			{				//pixel[y][x].color = srcPixel[y * width + x] & 0xffffff;				System.out.println(pixel.length + "/");				System.out.println(pixel[0].length + "#");				pixel[y][x].color = 0xffffff;			}		}		countBorders();		calcThickness();	}	public void writeBrickShip(PrintStream ps, int offset)	{		offset *= width * 2;		ps.println("union\n{\n");				for(int y = 0; y < height; y++)		{			for(int x = 0; x < width; x++)			{				if(pixel[y][x].isSolid())				{					ps.println("\tunion\n\t{");					ps.println("\t\tmakeBrick(<2,1,1>)");					ps.println("\t\tpigment { rgb " + getRGBVector(x, y) + " }");					ps.println("\t\ttranslate <" + (x * 2) + ",0," + y + ">");					ps.println("\t}");				}			}		}		ps.println("\ttranslate x * " + offset);		ps.println("}");	}	private String getRGBVector(int x, int y)	{		int c = pixel[y][x].color;		double r = (double)(c >> 16) / 255;		double g = (double)((c >> 8) & 0xff) / 255;		double b = (double)(c & 0xff) / 255;		return "<" + r + "," + g + "," + b + ">";	}	private void countBorders()	{		for(int y = 1; y < (height - 1); y++)		{			for(int x = 1; x < (width - 1); x++)			{				pixel[y][x].borders = 0;				for(int my = -1; my < 2; my++)				{					for(int mx = -1; mx < 2; mx++)					{						pixel[y][x].borders += pixel[x+mx][y+my].isSolid() ? 1 : 0;					}				}			}		}	}	private void calcThickness()	{	}}class Pixel{	public int color, borders = 0;	public double thickness;	public Pixel()	{}	public boolean isSolid()	{		return color != 0;	}}