First of all, you have a couple of problems in your code:
- Integer division is leading to only the third option being considered, because 1/3 = 0 and 2/3 = 0. Use 1./3. and 2./3. instead.
- You have exchanged coordinates for the last option,
x0 = 1.0; y0 = sqrt3;
should be x0 = sqrt3; y0 = 1.0;
instead.
Once you output the points to a file called data
(I used System.out.println("" + x + " " + y);
within your loop), you can do the following in gnuplot:
set size ratio -1
plot "data" u 2:1 pt 7 ps 0.3
To monitor how the triangle gets created dot by dot you can use a loop with a pause:
set xrange [0:2]
set yrange [0:1.8]
do for [i=0:4999] {
plot "data" u 2:1 every ::::i pt 7 ps 0.3
pause 0.1
}
Or you can create an animated gif with a series of png files:
set term pngcairo
do for [i=0:4999] {
set output "".i.".png"
plot "data" u 2:1 every ::::i pt 7 ps 0.3
}
Expect the above to be slow. You can skip some of the frames to make it quicker. Then do this outside gnuplot:
convert -delay 10 -loop 0 *.png animation.gif
For this example I used 50 points increments and changed -delay
to 100:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…