首页 > 解决方案 > 用长方形做一个圆

问题描述

因为我数学不太好。我需要一些帮助。

我想创建一个圆,但我不想使用 (x,y, rad),而是使用矩形创建一个圆。我的画布宽度和高度是 1200(像素)。我想按以下方式放置我的圆圈:x = WIDTH/3*2,y = HEIGHT/3。半径为500。

我已经开始创建一个矩形的 for 循环,但是出了点问题。这是我所做的:

//not really important, just colors
Color Planet1 = new Color(68,243,252);
Color Planet2 = new Color(179, 225, 249);

int nbDegrade = 100;

// What I wanted to make is 2 for loops, to make 2 half circles.
        for(int i = 1; i < 250; ++i) {
            //this is setting a color with color mixture code
            painter.setColor(mixture(Planet1, Planet2,(double)i/nbDegrade));
            //fillRectangle code (x, y, width, height)
            painter.fillRectangle(WIDTH/3*2 + i,HEIGHT/3 - i,1,i *2);
}

我觉得我必须使用 tan 函数,但不知道该怎么做。

标签: java

解决方案


推荐阅读