Friday, December 27, 2013

Drawig images.
































































































































I followed this Draw textured spheres | JavaWorld article and built the code that is written there.































































































































But it does not generate a sphere or ball. Am i using it wrong, or am i missing something?
































































































































































































Java Code:







































































































































import java.awt.*;
import java.awt.image.*;
import javax.swing.JFrame;

public class Graafika extends JFrame{
public Graafika(){
int width = 200;
int height = 200;
Sphere obj = new Sphere(100, 20, new SineTexture(5, 100, 5));
int[] imageData = new int[width * height];

int sup = 2;
double supInv = 1.0 / sup;
for (int j = 0; j < height; ++ j) {
for (int i = 0; i < width; ++ i) {
RGB pixel = new RGB (0.0, 0.0, 0.0);
for (int k = 0; k < sup; ++ k) {
for (int l = 0; l < sup; ++ l) {
Vec ray = new Vec ((i * 2. - width) / 2. + k * supInv,
(j * 2. - height) / 2. + l * supInv, 150.0);
RGB rgb = obj.getIntersection (ray);
pixel.add (rgb);
}
}
pixel.scale (supInv * supInv);
imageData[i + width * j] = pixel.toRGB ();
}
}

MemoryImageSource source = new MemoryImageSource(width, height, imageData,0, width);
source.setAnimated(true);
source.setFullBufferUpdates(true);
Image tile = createImage(source);
source.newPixels();

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 300);
setLocationRelativeTo(null);
setTitle("Graafika");
setResizable(false);
setVisible(true);
}

public static void main(String[] args){
new Graafika();
}
}





































































































































Can someone tell me what i did wrong or what did i miss.






























































































































































































No comments:

Post a Comment