-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[contribs] Add the firework's example.
see #697 Signed-off-by: Stéphane Galland <galland@arakhne.org>
- Loading branch information
1 parent
89b158b
commit a60f29e
Showing
28 changed files
with
1,451 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
contribs/io.sarl.examples/io.sarl.examples.plugin/intro/examples_intro.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
contribs/io.sarl.examples/io.sarl.examples.plugin/intro/javafx_intro.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div id="content-header"> | ||
<h4 style="color: #f59616; line-height: 1.5;">SARL Examples with JavaFX</h4> | ||
<p> | ||
<span style="line-height: 1.3; font-size: 60%;">A collection of examples based on the JavaFX user interface.</span> | ||
</p> | ||
</div> | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+91.2 KB
...amples/io.sarl.examples.plugin/projects/io-sarl-demos-fireworks/Firework_en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+87 KB
...rl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-fireworks/MVC_en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
130 changes: 130 additions & 0 deletions
130
...arl.examples/io.sarl.examples.plugin/projects/io-sarl-demos-fireworks/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# MVC pattern | ||
|
||
This application follows a MVC (Model-View-Controller) pattern for the GUI communication. | ||
|
||
![MVC pattern applied on this project](MVC_en.png) | ||
|
||
|
||
# Fireworks demonstration | ||
|
||
|
||
The goal of this demo is to bring out some fireworks using SARL agents. | ||
The application is composed of 4 agents. The whole structure holonic. | ||
|
||
![Agents organization in the fireworks demo](Firework_en.png) | ||
|
||
The main agent is the *LaunchingArea* which is linked with the GUI and and contains the other agents inside its inner context. | ||
This agent creates the *RocketLauncher*, one by rocket asked by the user. It also transmits the gravity and other parameters. | ||
This agent also registers the GUI on a dedicated OpenEventSpace for communication. | ||
|
||
```Scala | ||
agent LaunchingArea { | ||
|
||
... | ||
|
||
/* | ||
* Get setup event from the GUI | ||
*/ | ||
on SetupSettings { | ||
this.rocketsQuantity = occurrence.rocketsQuantity | ||
this.fireQuantity = occurrence.fireQuatity | ||
this.gravity = occurrence.gravity | ||
this.maxWidth = occurrence.maxWidth | ||
} | ||
|
||
/* | ||
* Agent initialisation when spawned by the GUI | ||
* A communication space is opened between | ||
* the GUI and this agent | ||
*/ | ||
on Initialize [!occurrence.parameters.empty] { | ||
var ctrl = occurrence.parameters.get(0) as FXMLViewerController | ||
var ispace = defaultContext.createSpace( | ||
OpenEventSpaceSpecification, UUID.randomUUID) | ||
ctrl.setGUISpace(ispace) | ||
ispace.register(asEventListener) | ||
|
||
ctrl.listenAndDraw(grid) | ||
|
||
info("Finishing initialization of Launching Area") | ||
|
||
} | ||
|
||
... | ||
} | ||
``` | ||
|
||
![Application with the GUI](firework_screenshot.png) | ||
|
||
Then, each RocketLauncher creates a *Rocket*. When this one is destroyed, the *RocketLauncher* is going to generate another one. This allows to displace the verification of the existence of the *Rocket* out of the LaunchingArea. It also isolates the *Rocket* and avoid that emitted events disrupt the managing of the simulation. | ||
|
||
```Scala | ||
agent RocketLauncher { | ||
|
||
... | ||
|
||
/* | ||
* A new rocket is launched when the previous | ||
* one is destroyed | ||
*/ | ||
on MemberLeft [!isFromMe(occurrence) && !exited] { | ||
// wake allows to send the event at the agent itself | ||
wake(new Launch) | ||
} | ||
... | ||
} | ||
``` | ||
|
||
*Rocket* agents are the heart of this demo. Each one create a task with a fixed delay where they updates their position by writing it in a object shared with the GUI, here named *Positions*. When the *Rocket* reach the end of its lifetime, they create *Fire* agent within their inner context according to the quantity asked by the user and then wait for the destruction of every *Fire* to kill themselves. | ||
|
||
```Scala | ||
agent Rocket { | ||
|
||
... | ||
|
||
on Initialize { | ||
|
||
... | ||
|
||
/* | ||
* Create a new background task to update | ||
* the agent position at a fixed delay | ||
*/ | ||
move = atFixedDelay( | ||
Configuration.RocketLifeCycleSchedulingRate) [ | ||
try { | ||
wake(new UpdateRocketPosition); | ||
} catch (e : Exception) { | ||
e.printStackTrace | ||
} | ||
] | ||
} | ||
|
||
on UpdateRocketPosition [isFromMe(occurrence) && | ||
!frozen && !exploded] { | ||
var vect = new Vector(2) | ||
x = x + speedx | ||
y = y + speedy | ||
vect.clear() | ||
vect.add(x) | ||
vect.add(y) | ||
lifetime = lifetime - 10 | ||
|
||
/* Updates the Position object */ | ||
if (grid !== null) | ||
grid.setRocketPosition(id, vect) | ||
if (lifetime <= 0) { | ||
exploded = true | ||
move.cancel(true) | ||
grid.hideHocketPosition(id) | ||
wake(new Explode) | ||
} | ||
} | ||
|
||
... | ||
} | ||
|
||
``` | ||
The *Fire* is the last agent of the demo. It have a list of positions and is subjected to gravity. As *Rocket* agent, the *Fire* launch a task at a fixed delay to update its actual position, add it at the end of the actual list and then update the *Positions* object. When its lifetime is over, the *Fire* is destroyed. | ||
|
||
When the GUI is closed, an event *Exit* is sent to the *LaunchingArea* which transmits it to the other agents she owns. It waits for their elimination to destroy the next one, until itself. |
Binary file added
BIN
+307 KB
...o.sarl.examples.plugin/projects/io-sarl-demos-fireworks/firework_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions
57
...emos-fireworks/src/main/resources/io/sarl/demos/fireworks/gui/FireworksFxApplication.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.scene.canvas.Canvas?> | ||
<?import javafx.scene.control.Button?> | ||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.control.ScrollBar?> | ||
<?import javafx.scene.control.Tooltip?> | ||
<?import javafx.scene.layout.AnchorPane?> | ||
<?import javafx.scene.layout.Pane?> | ||
|
||
<Pane fx:id="main_pane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="608.0" prefWidth="933.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="io.sarl.demos.fireworks.gui.FireworksFxViewerController"> | ||
<children> | ||
<Canvas fx:id="draw_zone" height="583.0" layoutX="199.0" layoutY="13.0" rotate="180.0" width="715.0" /> | ||
<Button fx:id="setup_button" layoutX="26.0" layoutY="45.0" mnemonicParsing="false" onAction="#actionSetup" text="%SetupButtonText"> | ||
<tooltip> | ||
<Tooltip text="%SetupButtonTooltip" /> | ||
</tooltip></Button> | ||
<Button fx:id="launch_button" disable="true" layoutX="26.0" layoutY="89.0" mnemonicParsing="false" onAction="#actionLaunch" text="%LaunchButtonText"> | ||
<tooltip> | ||
<Tooltip text="%LaunchButtonTooltip" /> | ||
</tooltip></Button> | ||
<AnchorPane layoutX="30.0" layoutY="145.0"> | ||
<children> | ||
<ScrollBar fx:id="gravity_input" max="3.0" onMouseEntered="#actionGravityDisplay" prefHeight="17.0" prefWidth="159.0" unitIncrement="0.1" value="0.5"> | ||
<tooltip> | ||
<Tooltip text="%GravityTooltip" /> | ||
</tooltip></ScrollBar> | ||
<Label fx:id="gravity_display" layoutX="135.0" layoutY="17.0" prefHeight="17.0" prefWidth="46.0" text="0,5" textAlignment="RIGHT" /> | ||
<Label layoutY="17.0" prefHeight="17.0" prefWidth="46.0" text="%GravityLabelText" /> | ||
</children> | ||
</AnchorPane> | ||
<AnchorPane layoutX="27.0" layoutY="255.0"> | ||
<children> | ||
<Label layoutX="4.0" layoutY="17.0" text="%FireQuantityLabelText" /> | ||
<Label fx:id="fire_quantity_display" layoutX="135.0" layoutY="17.0" prefHeight="17.0" prefWidth="46.0" text="30" textAlignment="RIGHT" /> | ||
<ScrollBar fx:id="fire_quantity_input" layoutX="4.0" max="50.0" min="5.0" onMouseEntered="#actionFireQuantityDisplay" prefHeight="17.0" prefWidth="159.0" value="30.0"> | ||
<tooltip> | ||
<Tooltip text="%FireQuantityTooltip" /> | ||
</tooltip></ScrollBar> | ||
</children> | ||
</AnchorPane> | ||
<AnchorPane layoutX="30.0" layoutY="199.0"> | ||
<children> | ||
<ScrollBar fx:id="rocket_quantity_input" max="40.0" min="1.0" onMouseEntered="#actionRocketQuantityDisplay" prefHeight="17.0" prefWidth="159.0" value="20.0"> | ||
<tooltip> | ||
<Tooltip text="%RocketQuantityTooltip" /> | ||
</tooltip></ScrollBar> | ||
<Label layoutY="20.0" text="%RocketQuantityLabelText" /> | ||
<Label fx:id="rocket_quantity_display" layoutX="135.0" layoutY="20.0" prefHeight="17.0" prefWidth="46.0" text="20" textAlignment="RIGHT" /> | ||
</children> | ||
</AnchorPane> | ||
<Button fx:id="stop_button" disable="true" layoutX="117.0" layoutY="89.0" mnemonicParsing="false" onAction="#actionStop" text="%StopButtonText"> | ||
<tooltip> | ||
<Tooltip text="%StopButtonTooltip" /> | ||
</tooltip></Button> | ||
</children> | ||
</Pane> |
13 changes: 13 additions & 0 deletions
13
...ireworks/src/main/resources/io/sarl/demos/fireworks/gui/FireworksFxApplication.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
TITLE=SARL Demo: Fireworks Animation | ||
SetupButton=Configure | ||
LaunchButton=Launch | ||
StopButton=Stop | ||
GravityLabel=Gravity | ||
RocketQuantityLabel=Rocket quantity | ||
FireQuantityLabel=Fire quantity | ||
SetupButtonTooltip=Setup the entire environment according to the data given below | ||
LaunchButtonTooltip=Launch fireworks | ||
StopButtonTooltip=Stop and freeze fireworks | ||
GravityTooltip=Change demo gravity | ||
RocketQuantityTooltip=Change rocket quantity of the demo | ||
FireQuantityTooltip=Change fire quantity of the demo |
13 changes: 13 additions & 0 deletions
13
...works/src/main/resources/io/sarl/demos/fireworks/gui/FireworksFxApplication_fr.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
TITLE=SARL Démo: Animation de feux d'artifice | ||
SetupButtonText=Configurer | ||
LaunchButtonText=Lancer | ||
StopButtonText=Stop | ||
GravityLabelText=Gravité | ||
RocketQuantityLabelText=Quantité de roquettes | ||
FireQuantityLabelText=Quantité de feu | ||
SetupButtonTooltip=Configure l'environement en fonction des données plus bas | ||
LaunchButtonTooltip=Lance l'animation de feux d'artifices | ||
StopButtonTooltip=Stop et gèle les feux d'artifices | ||
GravityTooltip=Change la gravité de la démo | ||
RocketQuantityTooltip=Change la quantité de roquettes de la démo | ||
FireQuantityTooltip=Change la quantité de feu émise par les roquettes |
46 changes: 46 additions & 0 deletions
46
...-sarl-demos-fireworks/src/main/resources/io/sarl/demos/fireworks/gui/ViewerController.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* @Author: Bartuccio Antoine | ||
* @Date: 2017-05-26 16:41:58 | ||
* @Last Modified by: klmp200 | ||
* @Last Modified time: 2017-05-26 17:29:05 | ||
*/ | ||
|
||
// Nice white #F9FAFB | ||
// Nice black #2B2B2B | ||
|
||
#main_pane { | ||
-fx-background-color: #2B2B2B; | ||
} | ||
|
||
.scroll-bar { | ||
-fx-background-color: rgb(57, 57, 57); | ||
} | ||
|
||
.scroll-bar .thumb { | ||
-fx-background-color: rgb(169, 169, 169); | ||
-fx-background-radius: 0em; | ||
-fx-background-inserts: 0, 0, 0; | ||
} | ||
|
||
.scroll-bar .increment-arrow, | ||
.scroll-bar .decrement-arrow { | ||
-fx-color: rgb(169, 169, 169); | ||
} | ||
|
||
.scroll-bar:hover .increment-arrow, | ||
.scroll-bar:hover .decrement-arrow { | ||
-fx-color: #2B2B2B; | ||
-fx-background-color: rgb(169, 169, 169); | ||
} | ||
|
||
.label { | ||
-fx-text-fill: #F9FAFB; | ||
} | ||
|
||
.button { | ||
-fx-background-radius: 0em; | ||
-fx-background-inserts: 0, 0, 0; | ||
-fx-focus-color: transparent; | ||
-fx-text-fill: #2B2B2B; | ||
-fx-background-color: rgb(169, 169, 169); | ||
} |
Oops, something went wrong.