📄 grass.java~
字号:
import objectdraw.*;import java.awt.*;// Class that allows a user to draw a grassy scenepublic class Grass extends WindowController { // level of the horizon private static final int GROUND_LINE = 270; // position and radius of the sun private static final int SUN_INSET = 50, SUN_SIZE = 75; // level and spacing of the blades of grass private static final int GRASS_TOP = 255, GRASS_SPACING = 2; double bladePosition; // x coordinate of next blade of grass public void begin() { // draw solid ground and sun new FilledRect(0, GROUND_LINE, canvas.getWidth(), canvas.getHeight()-GROUND_LINE, canvas ); new FilledOval(SUN_INSET, SUN_INSET, SUN_SIZE, SUN_SIZE, canvas); bladePosition = 0; } public void onMouseClick(Location point) { // grow a blade of grass with each mouse click if (bladePosition < canvas.getWidth()){ new Line(bladePosition, GRASS_TOP, bladePosition, GROUND_LINE, canvas); bladePosition = bladePosition + GRASS_SPACING; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -