2013-01-14 16 views
-4

喜抱歉,但我的數學和物理是太弱了,所以我試過很多次,但每次我失敗了一次,我需要你的幫助來完成我的應用程序PLZ轉換這個圈子裏心臟轉換圈到心臟2D的Android

import android.graphics.Bitmap; 
public class Circle { 
float origRadius,deltaRadius,radius,origX,deltaX,x,origY,deltaY,y; 
int color,alpha,steps,currentStep; 
Bitmap bitmap; 

public Circle(float xCenter, float yCenter, float radius, 
     int color, int steps) { 
    this.x = xCenter; 
    this.origX = xCenter; 
    this.deltaX = (float) (40.0 * Math.random() - 20.0); 

    this.y = yCenter; 
    this.origY = yCenter; 
    this.deltaY = (float) (40.0 * Math.random() - 20.0); 

    this.origRadius = radius; 
    this.radius = radius; 
    this.deltaRadius = 0.5f * radius; 

    this.color = color; 
    this.alpha = 0; 

    this.steps = steps; 
} 

void tick() { 
    this.currentStep++; 

    float fraction = (float) this.currentStep/(float) this.steps; 

    this.radius = this.origRadius + fraction * this.deltaRadius; 
    this.x = this.origX + fraction * this.deltaX; 
    this.y = this.origY + fraction * this.deltaY; 

    if (fraction <= 0.25f) { 
     this.alpha = (int) (128 * 4.0f * fraction); 
    } else { 
     this.alpha = (int) (-128 * (fraction - 1)/0.75f); 
    } 
} 

boolean isDone() { 
    return this.currentStep > this.steps; 
} 
}  

在此先感謝

+2

不。這不是這個網站的工作原理。爲什麼你的代碼失敗?你是否收到任何錯誤消息或意外的輸出? – 2013-01-14 18:41:33

+0

我創建了我的應用程序的圈子,但現在我想用心臟形狀代替它 – mayur

+1

http://www.mathematische-basteleien.de/heart.htm –

回答

2

MathWorld有一個偉大的心形函數; http://mathworld.wolfram.com/HeartCurve.html

基本上你必須在你的代碼中這樣做;

float fraction = (float) this.currentStep/(float) this.steps; 

- >

float t = this.currentStep * 2.0 * Math.PI/(float) this.steps; 

this.x = 16.0 * Math.pow(Math.sin(t), 3.0)); 
this.y = 13.0 * Math.cos(t) - 5.0 * Math.cos(2.0 * t) - 
      2.0 * Math.cos(3.0 * t) - Math.cos(4.0 * t); 

希望這有助於我在寫這一味所以忍耐一下,如果有一些錯誤。對於半徑你可能想要做這樣的事情;

this.x *= radius/16.0; 
this.y *= radius/16.0; 
+0

非常感謝你嘗試使用它 – mayur