-4

こんにちは、申し訳ありませんが、数学と物理が苦手なので、何度も挑戦しましたが、失敗するたびに、アプリを完成させるためにあなたの助けが必要です plz この円をハートに変換してください

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;
}
}    

前もって感謝します

4

1 に答える 1

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);

これが役に立てば幸いです。私はこれをやみくもに書いているので、間違いがある場合はご容赦ください。radius については、次のようにするとよいでしょう。

this.x *= radius / 16.0;
this.y *= radius / 16.0;
于 2013-01-14T19:04:12.283 に答える