/*
* File name: ClockScheduler.java (package eas.simulation.users.lukas.clock)
* Author(s): Lukas König
* Java version: 6.0
* Generation date: 28.12.2010 (23:12:13)
*
* (c) This file and the EAS (Easy Agent Simulation) framework containing it
* is protected by Creative Commons by-nc-sa license. Any altered or
* further developed versions of this file have to meet the agreements
* stated by the license conditions.
*
* In a nutshell
* -------------
* You are free:
* - to Share -- to copy, distribute and transmit the work
* - to Remix -- to adapt the work
*
* Under the following conditions:
* - Attribution -- You must attribute the work in the manner specified by the
* author or licensor (but not in any way that suggests that they endorse
* you or your use of the work).
* - Noncommercial -- You may not use this work for commercial purposes.
* - Share Alike -- If you alter, transform, or build upon this work, you may
* distribute the resulting work only under the same or a similar license to
* this one.
*
* + Detailed license conditions (Germany):
* http://creativecommons.org/licenses/by-nc-sa/3.0/de/
* + Detailed license conditions (unported):
* http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en
*
* This header must be placed in the beginning of any version of this file.
*/
package eas.users.demos.clock;
import java.util.List;
import eas.math.geometry.Vector2D;
import eas.plugins.masterScheduler.AbstractDefaultMaster;
import eas.simulation.ConstantsSimulation;
import eas.simulation.Wink;
import eas.simulation.spatial.sim2D.standardAgents.CircleAgent;
import eas.startSetup.ParCollection;
import eas.startSetup.SingleParameter;
import eas.startSetup.parameterDatatypes.Datatypes;
/**
* @author Lukas König
*
*/
public class ClockScheduler extends AbstractDefaultMaster<ClockEnvironment> {
/**
*
*/
private static final long serialVersionUID = -971623473739492213L;
@Override
public ClockEnvironment[] generateRunnables(ParCollection params) {
params.setParValue("CameraRotationSpeedForFollowingAgent", 7.0);
params.setParValue("PaintPinkBoundingBox?", false);
params.setParValue("showAgentIDs?", false);
ClockEnvironment env = new ClockEnvironment(0, params);
double radFastPointer = 15 / 6;
double radMinuteSegments = 22;
if (params.getParValueBoolean("SmoothSeconds")
&& params.getParValueBoolean("ShowFastPointer?")) {
env.addAgent(new SmallAgent(0, env, params), new Vector2D(0, -10), 0);
for (int i = 0; i < 100; i += 5) {
env.addAgent(new SegmentSmallAgent(i + 1000, env, params),
new Vector2D(Math.sin((double) i / 30 * Math.PI) * radFastPointer,
Math.cos((double) i / 30 * Math.PI) * radFastPointer - 10),
-i * 6);
}
}
env.addAgent(new SecondAgent(61, env, params), new Vector2D(0, 0), 75);
env.addAgent(new MinuteAgent(62, env, params), new Vector2D(0, 0), 90);
env.addAgent(new HourAgent(63, env, params));
if (params.getParValueBoolean("showMinuteSegments")) {
for (int i = 0; i < 60; i++) {
if (i % 5 == 0) {
env.addAgent(new Segment5Agent(i + 1, env, params),
new Vector2D(Math.sin((double) i / 30 * Math.PI) * radMinuteSegments,
Math.cos((double) i / 30 * Math.PI) * radMinuteSegments),
-i * 6);
} else {
env.addAgent(new SegmentAgent(i, env, params),
new Vector2D(Math.sin((double) i / 30 * Math.PI) * radMinuteSegments,
Math.cos((double) i / 30 * Math.PI) * radMinuteSegments),
-i * 6);
}
}
}
env.addAgent(
new CircleAgent(100, env, params),
new Vector2D(0, 0),
0,
new Vector2D(0.1, 0.1));
// env.addAgent(new ClockAgent(1000, env, params), new Vector2D(0, 0), 0, new Vector2D(25, 25));
return new ClockEnvironment[] { env };
}
@Override
public String id() {
return ConstantsSimulation.DEFAULT_MASTER_SCHEDULER_ID + "-clock";
}
@Override
public List<SingleParameter> getParameters() {
List<SingleParameter> list = super.getParameters();
list.add(new SingleParameter(
"showMinuteSegments",
Datatypes.BOOLEAN,
false,
"Show minute segments as agents.",
this.id().toUpperCase()));
list.add(new SingleParameter(
"ShowFastPointer?",
Datatypes.BOOLEAN,
true,
"Only available when smoothSeconds turned on.",
this.id().toUpperCase()));
return list;
}
@Override
public boolean isTerminationRequested(ClockEnvironment runnable,
Wink currentTime, ParCollection params) {
return false;
}
@Override
public synchronized void runDuringSimulation(ClockEnvironment env,
Wink simZyk, ParCollection params) {
super.runDuringSimulation(env, simZyk, params);
try {
Thread.sleep(25);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}