📄 carmovie.java
字号:
// main() displays a movie of
// a car driving along a road.
// (29 Sep 03)
import java.awt.*;
public class CarMovie extends Movie{
/** Return picture of house and trees.
Scene fits in a rectangle,
width 40, height 30,
bottom-left corner at (0,0).
*/
private static Picture houseAndTrees() {
/* Define the sun. Centre at (0,0).*/
Picture sun =
Picture.circle(Color.yellow).size(2);
/* Define a tree.
Height = 20.
Origin at middle of base of trunk. */
Color brown = new Color(0.2f, 0.25f, 0.1f);
Color green = new Color(0f, 0.6f, 0.2f);
Picture trunk =
Picture.box(brown).scale(2,15).at(-1,0);
Picture crown =
Picture.circle(green).size(6).at(0,14);
Picture tree = crown.over(trunk);
/* Define the house.
Height and width of house = 20.
Bottom-left corner at (0,0). */
Color black = Color.black;
Color white = Color.white;
Color red = new Color(1f, 0.2f, 0f);
Color lightBlue = new Color(0.7f, 0.7f, 1f);
Picture wall =
Picture.box(white).scale(20,10)
.under(Picture.box(black).scale(3,3).at(5,4))
.under(Picture.box(red).scale(3,7).at(13,0));
Picture roof =
Picture.triangle(0,10, 10,20, 20,10, red)
.over(Picture.box(white).scale(3,10).at(13,10));
Picture house = roof.over(wall);
return
house.size(0.8).at(12,0)
.over(tree.at(4.5,0))
.over(tree.size(0.7).at(31,0))
.over(tree.size(0.85).at(36,0))
.over(sun.at(11,24));
}
/****************************************************/
/** Return picture of car.
Length of car = 100.
Origin at bottom-left corner.
*/
private static Picture car() {
Color c = Color.yellow; // Colour of car body.
Picture body =
Picture.box(c).scale(100,10)
.over(Picture.triangle(0,10, 10,10, 10,20, c))
.over(Picture.triangle(70,10, 100,10, 70,20, c))
.over(Picture.box(c).scale(60,10).at(10,10))
.over(Picture.box(c).scale(2,20).turn(30).at(70,16));
Picture wheel =
Picture.circle(Color.lightGray).size(5)
.over(Picture.circle(Color.darkGray).size(8));
Picture driver =
Picture.circle(Color.pink).size(7).at(50,27)
.under(Picture.circle(Color.white).size(7).at(50,16));
return
body
.over(driver)
.at(0,4)
.under(wheel.at(20,7))
.under(wheel.at(85,7));
}
/****************************************************/
public Picture scene(double t) {
double speed = 1.0;
// = speed of car in picture units per movie time unit.
/* Adjust size of car to fit scene. */
Picture car = car().size(0.15);
return
car.at(-30+speed*t, 0)
.over(houseAndTrees());
}
/****************************************************/
public static void main(String[] a) {
Movie m = new CarMovie();
m.setAntialiasingOn(false);
m.setFrameRate(30);
m.show(0,0,40,30,7,Color.blue);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -