Bonjour,

Je développe actuellement une petite application en JavaFX et je rencontre un problème que je n'arrive pas à résoudre... Je m'explique. Je crée des lignes, que j'intersectionne ensuite avec diverses formes. Ces lignes sont censées bouger, je le fait sans problème lorsque je n'intersectionne rien du tout, mais dès que l'intersection est faite, plus rien ne bouge !

Je vous donne le code que j'utilise :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import javafx.scene.shape.Rectangle;
import javafx.scene.transform.Rotate;
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;
import javafx.animation.Interpolator;
 
/**
 * @author Bastien Pietropaoli
 */
 
public class SpecialLine {
 
    protected var stroke:Integer = 5;
    protected var length:Integer = 1000;
    protected var angle:Integer = 45;
    protected var x:Integer = 0;
    protected var y:Integer = 0;
 
    protected var line = Rectangle {
        x: bind x, y: bind y
        width: bind length, height: bind stroke;
        transforms: [Rotate { pivotX : 0.0, pivotY : 0.0, angle: bind angle }]
    }
 
    protected var animation = Timeline {
        repeatCount: Timeline.INDEFINITE
        keyFrames : [
            KeyFrame {
                time : 2s
                values : {[x => x+40 tween Interpolator.LINEAR
                          y => y+40 tween Interpolator.LINEAR]}
            }
        ]
    }
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.shape.*;
import javafx.animation.*;
 
/**
 * @author Bastien Pietropaoli
 */
 
/*
 * The circle in the center :
 */
var circle = Circle {
    centerX: 320, centerY: 240
    radius: 100
}
 
/*
 * The four parts of the scene :
 */
var rectTopLeft = Rectangle {
    x: 0, y: 0
    width: 320, height: 240
}
var rectTopRight = Rectangle {
    x: 320, y: 0
    width: 320, height: 240
}
var rectBottomLeft = Rectangle {
    x: 0, y: 240
    width: 320, height: 240
}
var rectBottomRight = Rectangle {
    x: 320, y: 240
    width: 320, height: 240
}
 
/*
 * The four lists of lines :
 */
var topLeftLines:SpecialLine[] = for(i in [0..60]){
    SpecialLine{
        x: 100 - i*15
        y: 100 - i*15
        angle: -225
    }
}
var bottomLeftLines:SpecialLine[] = for(i in [0..60]){
    SpecialLine{
        x: 305 - i*15
        y: 305 - i*15
        angle: 45
    }
}
var topRightLines:SpecialLine[] = for(i in [0..60]){
    SpecialLine{
        x: 297 - i*15
        y: 297 - i*15
        angle: 45
    }
}
for(line in topRightLines){
    line.animation = Timeline {
        repeatCount: Timeline.INDEFINITE
        keyFrames : [
            KeyFrame {
                time : 2s
                values : {[line.x => line.x-40 tween Interpolator.LINEAR
                          line.y => line.y-40 tween Interpolator.LINEAR]}
            }
        ]
    };
}
var bottomRightLines:SpecialLine[] = for(i in [0..60]){
    SpecialLine{
        x: 108 - i*15
        y: 108 - i*15
        angle: -225
    }
}
for(line in bottomRightLines){
    line.animation = Timeline {
        repeatCount: Timeline.INDEFINITE
        keyFrames : [
            KeyFrame {
                time : 2s
                values : {[line.x => line.x-40 tween Interpolator.LINEAR
                          line.y => line.y-40 tween Interpolator.LINEAR]}
            }
        ]
    };
}
 
/*
 * The intersections :
 */
var topLeftCorner = bind ShapeIntersect {
    a: [ShapeSubtract {
        a: rectTopLeft
        b: circle
    },ShapeSubtract {
        a : circle
        b : [rectTopLeft,rectTopRight,rectBottomLeft]
    }]
    b: bind [for(line in topLeftLines){line.line}]
}
var topRightCorner = bind ShapeIntersect {
    a: [ShapeSubtract {
        a: rectTopRight
        b: circle
    },ShapeSubtract {
        a : circle
        b : [rectTopLeft,rectBottomRight,rectTopRight]
    }]
    b: bind [for(line in topRightLines){line.line}]
}
var bottomLeftCorner = bind ShapeIntersect {
    a: [ShapeSubtract {
        a: rectBottomLeft
        b: circle
    },ShapeSubtract {
        a : circle
        b : [rectBottomLeft,rectBottomRight,rectTopLeft]
    }]
    b: bind [for(line in bottomLeftLines){line.line}]
}
var bottomRightCorner = bind ShapeIntersect {
    a: [ShapeSubtract {
        a: rectBottomRight
        b: circle
    },ShapeSubtract {
        a : circle
        b : [rectBottomLeft,rectBottomRight,rectTopRight]
    }]
    b: bind [for(line in bottomRightLines){line.line}]
}
 
/*
 * Just play the animation :
 */
for(line in topLeftLines){line.animation.play()};
for(line in topRightLines){line.animation.play()};
for(line in bottomLeftLines){line.animation.play()};
for(line in bottomRightLines){line.animation.play()};
 
/*
 * The stage :
 */
Stage {
    title: "Optical illusion"
    width: 640
    height: 480
    scene: Scene {
        content: //[for(line in topLeftLines){line.line}]
                 [topRightCorner
                 topLeftCorner
                 bottomLeftCorner
                 bottomRightCorner]
    }
}
Je suis persuadé que cela vient d'un problème de bind mal placé, j'ai essayé à peu près tout ce qu'il était possible de bind... J'avoue ne pas trouver la solution et je commence un peu à craquer :p

Je vous préviens, le résultat pique un peu les yeux, c'est le but ;p

Merci d'avance si certains peuvent m'aider !