展开全部
importjavafx.application.Application;
importjavafx.scene.Scene;
importjavafx.scene.canvas.Canvas;
importjavafx.scene.canvas.GraphicsContext;
importjavafx.scene.layout.StackPane;
importjavafx.scene.paint.Color;
importjavafx.stage.Stage;
/**
*笛卡尔情书的秘密r=a(1-sinθ)
*
*@authorcrazykay
*@see《趣味编程100例》心形图
*/
publicclassJavaFXApplicationHeartextendsApplication{
@Override
publicvoidstart(StageprimaryStage){
intwidth,height;
Canvascanvas=newCanvas(350,350);
width=(int)canvas.getWidth();
height=(int)canvas.getHeight();
GraphicsContextgc=canvas.getGraphicsContext2D();
doublex,y,r;
for(inti=0;i<=90;i++){
for(intj=0;j<=90;j++){
//转换为直角坐标系,设置偏62616964757a686964616fe78988e69d8331333337626131移量,使图像居中
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);
}
}
StackPaneroot=newStackPane();
root.getChildren().add(canvas);
Scenescene=newScene(root,Color.BLACK);
primaryStage.setTitle("r=a(1-sinθ)");
primaryStage.setScene(scene);
primaryStage.show();
}
publicstaticvoidmain(String[]args){
launch(args);
}
}
网上找的java的代码。原理能看懂了,改C++应该也不费事。界面的话opencv或者opengl往上怼就行了