[代碼] [Java]代碼 import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.layout.StackPane; http://www.fpshamen.com/linked/20130227.do; import javafx.scene.paint.Color; import javafx.stage.Stage; /** * 笛卡爾情書的隱祕r=a(1-sinθ) * * @author crazykay * @see 《興趣編程100例》心形圖 */ public class JavaFXApplicationHeart extends Application { @Override public void start(Stage primaryStage) { int width, height; Canvas canvas = new Canvas(350, 350); width = (int) canvas.getWidth(); height = (int) canvas.getHeight(); GraphicsContext gc = canvas.getGraphicsContext2D(); double x, y, r; for (int i = 0; i <= 90; i ) { for (int j = 0; j <= 90; j ) { //轉換爲直角座標系,設置偏移量,使圖畫居中 r = Math.PI / 45 * i * (1 - Math.sin(Math.PI / 45 * j)) * 19; x = r * Math.cos(Math.PI / 45 * j) * Math.sin(Math.PI / 45 * i) width / 2; y = -r * Math.sin(Math.PI / 45 * j) height / 4; gc.setFill(Color.RED); gc.fillOval(x, y, 2, 2); gc.fillOval(x, y, 1, 1); } } StackPane root = new StackPane(); root.getChildren().add(canvas); Scene scene = new Scene(root, Color.BLACK); primaryStage.setTitle("r=a(1-sinθ)"); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } http://wj.aaafaipiao.com/linked/20130227.do;