本文整理汇总了Java中edu.umd.cs.piccolo.activities.PActivity类的典型用法代码示例。如果您正苦于以下问题:Java PActivity类的具体用法?Java PActivity怎么用?Java PActivity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PActivity类属于edu.umd.cs.piccolo.activities包,在下文中一共展示了PActivity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: delete
import edu.umd.cs.piccolo.activities.PActivity; //导入依赖的package包/类
/**
* Deletes a specified tool.
* <p>
* Shows an animation of a tool shrinking towards a point.
* Then deletes the tool.
*
* @param toolNode the tool to delete
* @param p a position transformed through the view transform of the bottom camera
*/
public void delete( final AbstractToolNode toolNode, Point2D p ) {
assert ( isInTrash( p ) );
// shrink the tool to the specified point
final double scale = 0.1;
final long duration = 300; // ms
PActivity a1 = toolNode.animateToPositionScaleRotation( p.getX(), p.getY(), scale, toolNode.getRotation(), duration );
// then delete the tool
PActivity a2 = new PActivity( -1 ) {
protected void activityStep( long elapsedTime ) {
_toolProducer.removeTool( toolNode.getTool() );
terminate(); // ends this activity
}
};
_trashCanNode.addActivity( a2 );
a2.startAfter( a1 );
}
示例2: ParticleApplication
import edu.umd.cs.piccolo.activities.PActivity; //导入依赖的package包/类
public ParticleApplication() {
particleModel = new ParticleModel( maxX, maxY );
particlePanel = new ParticlePanel( particleModel, this );
frame = new JFrame( "Self-Driven Particles" );
frame.setContentPane( particlePanel );
frame.setSize( 900, 600 );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
particlePanel.getRoot().addActivity( new PActivity( -1 ) {
protected void activityStep( long elapsedTime ) {
super.activityStep( elapsedTime );
particleModel.step( 1.0 );
}
} );
for ( int i = 0; i < 100; i++ ) {
addParticle();
}
}
示例3: OrderParameter90
import edu.umd.cs.piccolo.activities.PActivity; //导入依赖的package包/类
public OrderParameter90( BasicTutorialCanvas basicPage ) {
super( basicPage );
setText( "Some Dynamical Systems can be characterized by their degree of orderliness. " +
"This quantity is termed the 'order parameter'. " +
"In this model, the order parameter reflects the similarity of particles' headings. " +
"Try to get the order parameter above 0.9" );
orderParamText = new PText();
orderParamText.setTextPaint( Color.blue );
orderParamText.setFont( new PhetFont( 16, true ) );
decimalFormat = new DecimalFormat( "0.00" );
activity = new PActivity( -1 ) {
protected void activityStep( long elapsedTime ) {
super.activityStep( elapsedTime );
updateText();
if ( isOrderParamaterAwesome() ) {
advance();
}
}
};
}
示例4: animateCameraViewTransformTo
import edu.umd.cs.piccolo.activities.PActivity; //导入依赖的package包/类
/**
* Animates the camera's view transform into the provided one over the
* duration provided.
*
* @param camera camera being animated
* @param targetTransform the transform to which the camera's transform will
* be animated
* @param duration the number of milliseconds the animation should last
*
* @return an activity object that represents the animation
*/
protected PActivity animateCameraViewTransformTo(final PCamera camera, final AffineTransform targetTransform,
final int duration) {
boolean wasOldAnimation = false;
// first stop any old animations.
if (navigationActivity != null) {
navigationActivity.terminate();
wasOldAnimation = true;
}
if (duration == 0) {
camera.setViewTransform(targetTransform);
return null;
}
final AffineTransform source = camera.getViewTransformReference();
if (source.equals(targetTransform)) {
return null;
}
navigationActivity = camera.animateViewToTransform(targetTransform, duration);
navigationActivity.setSlowInSlowOut(!wasOldAnimation);
return navigationActivity;
}
示例5: moveCameraOnPath
import edu.umd.cs.piccolo.activities.PActivity; //导入依赖的package包/类
/**
* Moves along a path
* @param p the point
* @param jump true if jumping
*/
public void moveCameraOnPath(Point2D p, boolean jump) {
Rectangle2D area = hull.getAreaToZoom(p);
int minZoomHeight = (int)viewedCanvas.getCamera().getHeight();
if (area.getHeight() < minZoomHeight)
area.setFrame(area.getX(), area.getCenterY() - minZoomHeight/2, area.getWidth(), minZoomHeight);
if (jump || smoothPanning) {
// The following allows a camera animation to start while another animation
// is already running.
if (currentCameraAnimation != null && currentCameraAnimation.isStepping()) {
currentCameraAnimation.terminate(PActivity.TERMINATE_WITHOUT_FINISHING);
}
if (jump) {
currentCameraAnimation = viewedCanvas.getCamera().animateViewToCenterBounds(area, true, 300);
currentCameraAnimation.setSlowInSlowOut(true);
} else {
currentCameraAnimation = viewedCanvas.getCamera().animateViewToCenterBounds(area, true, 150);
currentCameraAnimation.setSlowInSlowOut(false);
}
// Play one step right now, otherwise nothing will happen while dragging the mouse since animations
// won't have time to play.
currentCameraAnimation.setStartTime(System.currentTimeMillis() - currentCameraAnimation.getStepRate());
currentCameraAnimation.processStep(System.currentTimeMillis());
} else
viewedCanvas.getCamera().setViewBounds(area);
}
示例6: setViewBounds
import edu.umd.cs.piccolo.activities.PActivity; //导入依赖的package包/类
/**
* Changes the view bounds of a camera with a smooth animation.
*/
protected void setViewBounds(PCamera camera, PBounds b) {
if (!smoothPanning) {
camera.setViewBounds(b);
} else {
// The following allows a camera animation to start while another animation
// is already running.
if (isAnimatingPan()) {
currentCameraAnimation.terminate(PActivity.TERMINATE_WITHOUT_FINISHING);
}
currentCameraAnimation = camera.animateViewToCenterBounds(b, true, 150);
currentCameraAnimation.setSlowInSlowOut(false);
// Play one step right now, otherwise nothing will happen while dragging the mouse since animations
// won't have time to play.
currentCameraAnimation.setStartTime(System.currentTimeMillis() - currentCameraAnimation.getStepRate());
currentCameraAnimation.processStep(System.currentTimeMillis());
}
}
示例7: getNumberOfActiveActivities
import edu.umd.cs.piccolo.activities.PActivity; //导入依赖的package包/类
private int getNumberOfActiveActivities() {
int numberActiveActivities = 0;
for ( PActivity activity : activities ) {
if ( activity.isStepping() ) { numberActiveActivities++; }
}
return numberActiveActivities;
}
示例8: terminateActivities
import edu.umd.cs.piccolo.activities.PActivity; //导入依赖的package包/类
public void terminateActivities() {
for ( PActivity activity : new ArrayList<PActivity>( activities ) ) {
activities.remove( activity );
activity.terminate( PActivity.TERMINATE_WITHOUT_FINISHING );
}
activities.clear();
}
示例9: animateToToolboxStack
import edu.umd.cs.piccolo.activities.PActivity; //导入依赖的package包/类
public void animateToToolboxStack( Point2D point, double scale ) {
animateToPositionScaleRotation( point.getX(), point.getY(), scale, 0, BuildAFractionModule.ANIMATION_TIME ).setDelegate( new CompositeDelegate( new DisablePickingWhileAnimating( this, true ), new PActivityDelegateAdapter() {
@Override public void activityFinished( final PActivity activity ) {
super.activityFinished( activity );
updateExpansionButtonsEnabled();
context.containerNodeAnimationToToolboxFinished( ContainerNode.this );
}
} ) );
animateToShowSpinners();
}
示例10: animateToPosition
import edu.umd.cs.piccolo.activities.PActivity; //导入依赖的package包/类
private void animateToPosition( final ContainerNode containerNode, final Vector2D position, PActivityDelegate delegate ) {
containerNode.animateToPositionScaleRotation( position.x, position.y,
getContainerScale(), 0, BuildAFractionModule.ANIMATION_TIME ).
setDelegate( new CompositeDelegate( new DisablePickingWhileAnimating( containerNode, true ), delegate, new PActivityDelegateAdapter() {
@Override public void activityFinished( final PActivity activity ) {
containerNode.updateExpansionButtonsEnabled();
}
} ) );
}
示例11: animateToStackLocation
import edu.umd.cs.piccolo.activities.PActivity; //导入依赖的package包/类
public void animateToStackLocation( Vector2D v, final boolean deleteOnArrival ) {
animateToPositionScaleRotation( v.x, v.y, 1, 0, BuildAFractionModule.ANIMATION_TIME ).setDelegate( new CompositeDelegate(
new DisablePickingWhileAnimating( this, true ),
new UpdateAnimatingFlag( animating ),
new PActivityDelegateAdapter() {
@Override public void activityFinished( final PActivity activity ) {
if ( deleteOnArrival ) {
delete();
}
}
} ) );
}
示例12: animateTo
import edu.umd.cs.piccolo.activities.PActivity; //导入依赖的package包/类
/**
* Animates to a point using a specified duration.
* Animation begins immediately.
* The animation path is a straight line.
*
* @param x
* @param y
* @param duration duration in milliseconds
* @return the PActivity that was scheduled, or null if none was scheduled
* @throws IllegalStateException if this node is not yet in the Piccolo tree
*/
public PActivity animateTo( final double x, final double y, final long duration ) {
if ( !started ) {
if ( getRoot() == null ) {
throw new IllegalStateException( "node has no root" );
}
PActivity activity = animateToPositionScaleRotation( x, y, 1 /*scale*/, 0 /*theta*/, duration );
return activity;
}
else {
return null;
}
}
示例13: scrollTo
import edu.umd.cs.piccolo.activities.PActivity; //导入依赖的package包/类
private void scrollTo( int index ) {
if ( index >= 0 && index < kitLayer.getChildrenCount() ) {
if ( activity != null ) {
//Terminate without finishing the previous activity so the motion doesn't stutter
activity.terminate( PActivity.TERMINATE_WITHOUT_FINISHING );
}
selectedKit.set( index );
double x = background.getFullBounds().getWidth() * index;
activity = kitLayer.animateToPositionScaleRotation( -x, 0, 1, 0, 500 );
}
}
示例14: initialize
import edu.umd.cs.piccolo.activities.PActivity; //导入依赖的package包/类
public void initialize() {
final PLayer layer = getCanvas().getLayer();
final PRoot root = getCanvas().getRoot();
final Random r = new Random();
for (int i = 0; i < 1000; i++) {
final PNode n = PPath.createRectangle(0, 0, 100, 80);
n.translate(10000 * r.nextFloat(), 10000 * r.nextFloat());
n.setPaint(new Color(r.nextFloat(), r.nextFloat(), r.nextFloat()));
layer.addChild(n);
}
getCanvas().getCamera().animateViewToCenterBounds(layer.getGlobalFullBounds(), true, 0);
final PActivity a = new PActivity(-1, 20) {
public void activityStep(final long currentTime) {
super.activityStep(currentTime);
rotateNodes();
}
};
root.addActivity(a);
final PPath p = new PPath();
p.moveTo(0, 0);
p.lineTo(0, 1000);
final PFixedWidthStroke stroke = new PFixedWidthStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10,
new float[] { 5, 2 }, 0);
p.setStroke(stroke);
layer.addChild(p);
}
示例15: OffscreenCanvasExample
import edu.umd.cs.piccolo.activities.PActivity; //导入依赖的package包/类
/**
* Create a new offscreen canvas example with the specified graphics device.
*
* @param device graphics device
*/
public OffscreenCanvasExample(final GraphicsDevice device) {
final GraphicsConfiguration configuration = device.getDefaultConfiguration();
frame = new Frame(configuration);
frame.setUndecorated(true);
frame.setIgnoreRepaint(true);
frame.setBounds(100, 100, 400, 400);
frame.setVisible(true);
frame.createBufferStrategy(2);
canvas = new POffscreenCanvas(400, 400);
final PText text = new PText("Offscreen Canvas Example");
text.setFont(text.getFont().deriveFont(32.0f));
text.setTextPaint(new Color(200, 200, 200));
text.offset(200.0f - text.getWidth() / 2.0f, 200.0f - text.getHeight() / 2.0f);
final PPath rect = PPath.createRectangle(0.0f, 0.0f, 360.0f, 360.0f);
rect.setPaint(new Color(20, 20, 20, 80));
rect.setStroke(new BasicStroke(2.0f));
rect.setStrokePaint(new Color(20, 20, 20));
rect.offset(20.0f, 20.0f);
canvas.getCamera().getLayer(0).addChild(text);
canvas.getCamera().getLayer(0).addChild(rect);
final Rectangle2D right = new Rectangle2D.Double(200.0f, 200.0f, 800.0f, 800.0f);
final Rectangle2D left = new Rectangle2D.Double(-200.0f, 200.0f, 225.0f, 225.0f);
final Rectangle2D start = new Rectangle2D.Double(0.0f, 0.0f, 400.0f, 400.0f);
final PActivity toRight = canvas.getCamera().animateViewToCenterBounds(right, true, 5000);
final PActivity toLeft = canvas.getCamera().animateViewToCenterBounds(left, true, 5000);
final PActivity toStart = canvas.getCamera().animateViewToCenterBounds(start, true, 5000);
toLeft.startAfter(toRight);
toStart.startAfter(toLeft);
}