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]
}
} |
Partager