/* TODO: A program that show the illusory contour
* does.
*/
import acm.program.*;
import acm.graphics.*;
import java.awt.*;
public class IllusoryContours extends GraphicsProgram {
/* The default width and height of the window. These constants will tell Java to
* create a window whose size is *approximately* given by these dimensions. You should
* not directly use these constants in your program; instead, use getWidth() and
* getHeight(), which return the *exact* width and height of the window.
*/
public static final int APPLICATION_WIDTH = 300;
public static final int APPLICATION_HEIGHT = 300;
public static final int CIRCLE_DIAMETER = 100;
public static double x1=0,y1=0,x2=0,y2=0,x3=0,y3=0,x4=0,y4=0;
public void run() {
getCenter();
showCircle();
showRect();
}
/*
* 得到四个圆心
* x代表圆的外切长方形的左上角的x坐标,而非圆心的x坐标
* y代表的远的外切长方形的左上角的y坐标,而非圆心的y坐标
*/
private void getCenter() {
x1 = getWidth() - CIRCLE_DIAMETER;
y1 = getHeight() - CIRCLE_DIAMETER;
x2 = 0;
y2 = 0;
x3 = getWidth() - CIRCLE_DIAMETER;
y3 = 0;
x4 = 0;
y4 = getHeight() - CIRCLE_DIAMETER;
}
private void showCircle(){
GOval circle1 = new GOval(x1,y1,CIRCLE_DIAMETER,CIRCLE_DIAMETER);
GOval circle2 = new GOval(x2,y2,CIRCLE_DIAMETER,CIRCLE_DIAMETER);
GOval circle3 = new GOval(x3,y3,CIRCLE_DIAMETER,CIRCLE_DIAMETER);
GOval circle4 = new GOval(x4,y4,CIRCLE_DIAMETER,CIRCLE_DIAMETER);
circle1.setFilled(true);
circle1.setFillColor(Color.black);
add(circle1);
circle2.setFilled(true);
circle2.setFillColor(Color.black);
add(circle2);
circle3.setFilled(true);
circle3.setFillColor(Color.black);
add(circle3);
circle4.setFilled(true);
circle4.setFillColor(Color.black);
add(circle4);
}
private void showRect() {
double x5 = CIRCLE_DIAMETER/2;
double y5 = CIRCLE_DIAMETER/2;
double rectWidth = getWidth() - CIRCLE_DIAMETER;
double rectHeight = getHeight() - CIRCLE_DIAMETER;
GRect rect = new GRect(x5,y5,rectWidth,rectHeight);
rect.setFilled(true);
rect.setFillColor(Color.white);
rect.setColor(Color.white);
add(rect);
}
}
CS106A assignment2 --problem2 IllusoryContours
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- | 前面命令输出结果作为后面命令的输入内容 || 前面命令执行失败的时候才执行后面的命令 & 前面命令执行后接着执...