2009-06-25 85 views
-1

我想这个代码与Java转换成C#(位于here帮我处理代码转换为C#

我有一些WinForm的经验,但不是很多与像素上一个winform应用程序的绘图。

我觉得相当有信心,我可以在大部分的子方法转换即时通讯如何我想提请indiviual像素在屏幕上

任何帮助或工具转换过的Java与C#将只是不清楚大大apprehsated

// Buddhabrot 
// j.tarbell January, 2004 
// Albuquerque, New Mexico 
// complexification.net 

// based on code by Paul Bourke 
// astronomy.swin.edu.au/~pbourke/ 

// Processing 0085 Beta syntax update 
// j.tarbell April, 2005 

int dim = 800;    // screen dimensions (square window) 
int bailout = 200;   // number of iterations before bail 
int plots = 10000;  // number of plots to execute per frame (x30 = plots per second) 

// 2D array to hold exposure values 
int[] exposure = new int[dim*dim]; 
int maxexposure;   // maximum exposure value 
int time = 0; 
int exposures = 0; 

boolean drawing; 
PFont metaBold; 

// MAIN ---------------------------------------------------------------- 

void setup() { 
    // set up drawing area 
    size(800,800,P3D); 
    background(0); 
    // take it nice and easy 
    framerate(15); 
    // load typeface 
    metaBold = loadFont("Arial-48.vlw"); 
} 

void draw() { 
    plotPlots(); 
    time++; 
    if (time%30==0) { 
    // show progress every 2 seconds or so... 
    findMaxExposure(); 
    renderBrot(); 
    // show exposure value 
    fill(255); 
    noStroke(); 
    textFont(metaBold, 14); 
    text("bailout: "+bailout+" exposures: "+exposures, 5, dim-6); 
    } 
} 

void plotPlots() { 
    float x, y; 
    // iterate through some plots 
    for (int n=0;n<plots;n++) { 
    // Choose a random point in same range 
    x = random(-2.0,1.0); 
    y = random(-1.5,1.5); 
    if (iterate(x,y,false)) { 
     iterate(x,y,true); 
     exposures++; 
    } 
    } 
} 

void renderBrot() { 
    // draw to screen 
    for (int i=0;i<dim;i++) { 
    for (int j=0;j<dim;j++) { 
     float ramp = exposure[i*dim+j]/(maxexposure/2.5); 
     // blow out ultra bright regions 
     if (ramp > 1) { 
     ramp = 1; 
     } 
     color c = color(int(ramp*255), int(ramp*255), int(ramp*255)); 
     set(j,i,c); 
    } 
    } 
} 

// Iterate the Mandelbrot and return TRUE if the point exits 
// Also handle the drawing of the exit points 
boolean iterate(float x0, float y0, boolean drawIt) { 
    float x = 0; 
    float y = 0; 
    float xnew, ynew; 
    int ix,iy; 

    for (int i=0;i<bailout;i++) { 
    xnew = x * x - y * y + x0; 
    ynew = 2 * x * y + y0; 
    if (drawIt && (i > 3)) { 
     ix = int(dim * (xnew + 2.0)/3.0); 
     iy = int(dim * (ynew + 1.5)/3.0); 
     if (ix >= 0 && iy >= 0 && ix < dim && iy < dim) { 
     // rotate and expose point 
     exposure[ix*dim+iy]++; 
     } 

    } 
    if ((xnew*xnew + ynew*ynew) > 4) { 
     // escapes 
     return true; 
    } 
    x = xnew; 
    y = ynew; 
    } 
    // does not escape 
    return false; 
} 

void findMaxExposure() { 
    // assume no exposure 
    maxexposure=0; 
    // find the largest density value 
    for (int i=0;i<dim;i++) { 
    for (int j=0;j<dim;j++) { 
     maxexposure = max(maxexposure,exposure[i*dim+j]); 
    } 
    } 
} 

// Buddhabrot 
// j.tarbell January, 2004 
+3

没有Java的 - 它的处理 – 2009-06-25 20:00:31

+0

你能解释一些什么是缺少的(我不知道很多关于java) – Crash893 2009-06-25 20:49:15

+1

处理是一种编译到JVM的不同语言 - 这不是Java。 Processing是用Java构建的,可以生成JVM字节码并调用Java,但是没有Java-> C#转换器会知道如何处理它。 – 2009-06-25 20:57:22

回答

4

看看System.Drawing和Graphics类。

编辑:只是为了澄清混乱,OP的代码不是Java。这是Processing。它在评论中这样说,但是也可以说,因为没有类定义,没有导入,并且调用不是Java调用。它编译为字节码,并与Java进行互操作,但它不是Java--没有自动转换会有帮助。

1

要绘制invidual像素可以使用:

e.Graphics.FillRectangle(aBrush, x, y, 1, 1); 

你可能想看看here

0

我们玩猜猜基础班吗? :)

原始代码似乎不是完整的java,具有全局变量和自由函数。它是类声明的内容吗?

问题是,Java代码使用了什么框架?因为如果它是一个奇特的双缓冲系统,那么通过在屏幕上直接绘制像素,您可能无法在Winforms中获得相同的结果。

你可能会通过谷歌搜索的关键字,得到最好的结果:DirectX的C#

更新:的OP不知道它是什么语言。

2

如果你想操纵像素并在保持高帧率的情况下绘制到屏幕上,你可能要使用lockbits和unlockbits来查看System.Drawing.Bitmap。

可以找到一个很好的解释here。否则,你不能以任何体面的速度进行像素级别的编辑。

1

如果您转到processing.org并下载处理软件,则可以将此代码复制到IDE中。然后,如果您执行“文件>导出”,它将创建程序的Java applet版本,并附带Java源代码。那么也许你可以运行其他转换器来获取C#代码。(请注意,这段代码似乎是一个较旧版本的Processing;我必须将“framerate”更改为“frameRate”才能运行。另外,我必须执行命令“Tools> Create Font ...” “来创建需要的”Arial-48.vlw“字体文件。)