gpt4 book ai didi

java - 创建一个 Squircle

转载 作者:行者123 更新时间:2023-12-04 20:50:26 26 4
gpt4 key购买 nike

我是一年级程序员。我正在尝试创建一个 squircle。 (带圆角的正方形)。

到目前为止我已经成功了。我得到了 a、b 和 r 的常数。如果有人可以提供帮助,我将非常感激。我对此一无所知。所以要好:)

package squircle;

import java.awt.*;
import javax.swing.*;
import java.lang.Math;

public class Main extends javax.swing.JApplet {

public void paint(Graphics g){

// (x-a)^4 + (y-b)^4 = r^4

// y = quadroot( r^4 - (x-a)^4 + b)
// x values must fall within a-r < x < a+r

int[] xPoints = new int[200];
int[] yPoints = new int[200];
int[] mypoints = new int[200];

for(int c = 0; c <200; c++){

int a = 100;
int r = 100;
int b = 100;
double x = c ;


double temp = (r*r*r*r);
double temp2 = x-a;
double temp3 = ((temp2)*(temp2)*(temp2)*(temp2));
double temp6 = Math.sqrt(temp-temp3);
double y = (Math.sqrt(temp6) + b );
double z = (y*-1)+300;

mypoints[c]=(int)z;

// if (c>100){
// y = y*1;
// }
// else if(c<100){
// y = y*1;
// }

xPoints[c]=(int)x;
yPoints[c]=(int)y;


// change the equation to find x co-ordinates
// change it to find y co-ordinates.

// r is the minor radius
// (a,b) is the location of the centre

// a = 100
// b = 100
// r = 100
// x value must fall within 0 or 200

}

g.drawPolygon(xPoints, yPoints, xPoints.length);
g.drawPolygon(xPoints, (mypoints), xPoints.length);
}
}

最佳答案

您没有使用 Graphics#drawRoundRect() 是家庭作业还是其他原因?

关于java - 创建一个 Squircle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1863727/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com