diff --git a/src/main/java/com/aparapi/examples/mandel/AfMain.java b/src/main/java/com/aparapi/examples/mandel/AfMain.java new file mode 100644 index 0000000000000000000000000000000000000000..ee4ab7f3023e81b7edc6e3ed43fe980442dd43de --- /dev/null +++ b/src/main/java/com/aparapi/examples/mandel/AfMain.java @@ -0,0 +1,91 @@ +package com.aparapi.examples.mandel; + +import com.aparapi.Range; + +public class AfMain { + + protected int W = 768; + protected int H = 768; + protected int max_iterations = 1000; + + protected int[] rgb; + + private float cx1 = -2; + private float cy1 = -2; + private float cx2 = +2; + private float cy2 = +2; + + private AfGUI gui; + + private Range range; + private AfKernel kernel; + + + public AfMain() { + + rgb = new int[W*H]; + + gui = new AfGUI(this); + + range = Range.create(W*H); + kernel = new AfKernel(); + + System.out.println(kernel.toString()); + System.out.println(kernel.getTargetDevice().toString()); + + } + + public void move(int x, int y, float zoom) + { + float nx1 = cx1+x*(cx2-cx1)/W; + float ny1 = cy1+y*(cy2-cy1)/H; + + float cw = zoom * (cx2-cx1); + float ch = zoom * (cy2-cy1); + + if(cw<ch) + ch=cw; + else + cw=ch; + + cx1 = nx1 - 0.5f * cw; + cy1 = ny1 - 0.5f * ch; + cx2 = nx1 + 0.5f * cw; + cy2 = ny1 + 0.5f * ch; + + } + + public void refresh() { + + System.out.printf("Mandelbrot %2.4f,%2.4f %2.4f,%2.4f \n",cx1,cy1,cx2,cy2); + + long startTime = System.nanoTime(); + + kernel.init(cx1, cy1, cx2, cy2, W, H, max_iterations, rgb); + kernel.execute(range); + + long endTime = System.nanoTime(); + long timeElapsed = endTime - startTime; + System.out.printf("Elapsed : %d ms\n", timeElapsed / 1000000); + + gui.refresh(); + + } + + + + public static void main(String[] args){ + + System.setProperty("com.aparapi.dumpProfilesOnExit", "true"); + + AfMain f = new AfMain(); + System.out.printf("Af Fractals - canvas : %dx%d - max_iterations : %,d \n",f.W,f.H,f.max_iterations); + + f.refresh(); + + } + + + + +}