This commit is contained in:
Debucquoy
2023-09-20 15:18:20 +02:00
parent 00d0cdfaf3
commit 4fd7542f03
228 changed files with 351 additions and 12 deletions

View File

@ -0,0 +1,77 @@
package spirale;
import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
import javafx.scene.control.*;
import javafx.scene.canvas.*;
import javafx.stage.Stage;
import javafx.geometry.Pos;
public class App extends Application {
private BorderPane root;
private Button next;
private HBox top;
private Generator gen;
private Canvas can;
@Override
public void start(Stage primaryStage){
final int[] last_pos_x = {400};
final int[] last_pos_y = { 400 };
final int[] last_pos_state = { 0 };
gen = new Fibonacci();
can = new Canvas(800,800);
GraphicsContext con = can.getGraphicsContext2D();
con.setFill(Color.BLUE);
root = new BorderPane();
top = new HBox();
next = new Button("Next");
next.setOnAction((x) -> {
int curr = gen.next();
System.out.println(curr);
int next_pos_x = last_pos_x[0], next_pos_y = last_pos_y[0];
switch (last_pos_state[0]) {
case 0:
next_pos_x = last_pos_x[0];
next_pos_y = last_pos_y[0] + curr;
break;
case 1:
next_pos_x = last_pos_x[0] + curr;
next_pos_y = last_pos_y[0];
break;
case 2:
next_pos_x = last_pos_x[0];
next_pos_y = last_pos_y[0] - curr;
break;
case 3:
next_pos_x = last_pos_x[0] - curr;
next_pos_y = last_pos_y[0];
break;
}
last_pos_state[0]++;
last_pos_state[0] = last_pos_state[0] % 4;
con.strokeLine(last_pos_x[0], last_pos_y[0], next_pos_x, next_pos_y);
last_pos_x[0] = next_pos_x;
last_pos_y[0] = next_pos_y;
});
top.getChildren().add(next);
top.setAlignment(Pos.CENTER);
root.setTop(top);
root.setCenter(can);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setTitle("Mon paneau");
primaryStage.show();
}
public static void main(String[] args) {
launch();
}
}

View File

@ -0,0 +1,15 @@
package spirale;
public class Fibonacci implements Generator{
private int last1 = 0, last2 = 0;
public int next(){
int tmp = last1 + last2;
if(tmp == 0){
tmp = 1;
}
last2 = last1;
last1 = tmp;
return tmp;
}
}

View File

@ -0,0 +1,5 @@
package spirale;
public interface Generator {
int next();
}

View File

@ -0,0 +1,14 @@
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package spirale;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class AppTest {
@Test void appHasAGreeting() {
App classUnderTest = new App();
assertNotNull(classUnderTest.getGreeting(), "app should have a greeting");
}
}