0
我正在嘗試爲Android設置Mandelbrot。 我嘗試在畫布上繪製它。它的工作原理,但我想要一個顏色漸變。 這是我的代碼:Mandelbrot Android應用程序的顏色漸變無效
package de.turbofractal;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
public class FractalView extends View {
private int n,g,xMax,yMax;
private float zr,zrh,zr0,zi,zi0,ar,br,ai,bi;
private int[][] Iterationen = new int[2560][1440];
private Paint paint;
public FractalView(Context context) {
super(context);
paint = new Paint();
ar=-2; br=2; ai=-2; bi=2;
}
@Override
protected void onDraw(Canvas canvas) {
g = 20;
for(int xx = 1; xx <= xMax; xx++) {
for(int yy = 1; yy <= yMax; yy++) {
schirmzupap(ar,br,bi,ai,xx,yy,xMax,yMax);
n = 1;
zr0 = zr;
zi0 = zi;
while ((n<g) && (zr*zr+zi*zi<4)) {
zrh = zr;
zr = (zr*zr)-zi*zi+zr0;
zi = zrh*zi+zi*zrh+zi0;
n++;
}
paint.setARGB(255,0,0,Math.round((n/g)*255)); //<--------------------this is where the color gradient should be created. But the programm only draws full blue (0,0,255). Why is that?
canvas.drawPoint(xx, yy, paint);
}
}
invalidate();
}
private void schirmzupap(float ax,float bx,float ay,float by,int xschirm,int yschirm,int w,int h) {
zr = xschirm*(bx-ax)/w+ax;
zi = yschirm*(ay-by)/h+by;
}
@Override
public void onSizeChanged(int w, int h, int oldW, int oldH) {
xMax = w-1;
yMax = h-1;
}
}
編輯: 這是它是如何由Eclipse模擬器得出: http://i53.tinypic.com/2mwfs7c.png
但我想它要繪製這樣(編程用Delphi): http://i53.tinypic.com/ehg2et.png
這是正確的。基本上我只想要一個從黑色到藍色的顏色漸變。越高的n在不破壞邊界條件的情況下獲得像素被繪製得越藍,越黑。但目前所有的像素都是全藍(0,0,255)。 – Henry
編輯 - 起初我以爲你問爲什麼這是全藍的,但後來我意識到有一個整數除法問題。 – Nate
哦,那真是一個非常愚蠢的錯誤,但我是Java新手......非常感謝! – Henry