Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The formula I have is
- //Pixel(x,y)
- for(int xi=0; xi<n;xi++){
- double rx = Math.random();
- double ry = Math.random();
- double xs = x + (xi+rx)/n;
- double ys = y + (yi+ry)/n;
- ...
- }
- public class Main {
- static String name = "doc/a01.png";
- static int width = 480;
- static int height = 270;
- public static void main(String[] args) {
- BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
- for (int x = 0; x != width; x++) {
- for (int y = 0; y != height; y++) {
- double rx = Math.random();
- image.setRGB(x, y, StratifiedSampling(x,y));
- }
- }
- try {
- File outputfile = new File(name);
- ImageIO.write(image, "png", outputfile);
- System.out.println("Wrote image: " + name);
- } catch (IOException e) {
- System.out.println("Something went wrong: " + e);
- }
- }
- static int StratifiedSampling(int x,int y){
- double sum = 0;
- final int samples = 100;
- for(int xi=0; xi<samples;xi++){
- for(int yi=0; yi<samples;yi++){
- double rx = Math.random();
- double ry = Math.random();
- double xs = x + (xi+rx)/samples;
- double ys = y + (yi+ry)/samples;
- //System.out.println((int)xs+" "+(int)ys);
- sum = sum + colorForCircle((int)xs,(int)ys);
- }
- }
- return (int)sum/samples;
- }
- static int colorForCircle(int x1, int y1){
- double x2 = x1;
- double y2 = y1;
- //System.out.println( 0 + (255 - 0) * y1/height);
- int centerX = 240;
- int centerY = 135;
- double radius = 40;
- if( Math.pow( (x2 - centerX),2) + Math.pow((y2 - centerY),2) < Math.pow(radius,2)){
- return new Color(255, 0, 0).getRGB();
- }
- else {
- double t = y2/height;
- int value = (int) (t* 255);
- int value2 = (int) (Math.pow (t,1/2.2)* 255);
- return new Color(0, 0, value).getRGB();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement