本文整理汇总了Java中edu.umd.cs.piccolo.PNode.translate方法的典型用法代码示例。如果您正苦于以下问题:Java PNode.translate方法的具体用法?Java PNode.translate怎么用?Java PNode.translate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.umd.cs.piccolo.PNode
的用法示例。
在下文中一共展示了PNode.translate方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCoilGraphics
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
/**
* Creates the graphics for the coils
*
* @param bounds
*/
private void createCoilGraphics( Rectangle2D bounds ) {
double baseDim = magnet.getOrientation() == GradientElectromagnet.HORIZONTAL ? bounds.getWidth() : bounds.getHeight();
double coilWidth = baseDim / numSegments;
for( int i = 0; i < coilsGraphics.length; i++ ) {
PNode coilGraphic = null;
double xLoc = i * coilWidth;
if( magnet.getOrientation() == GradientElectromagnet.HORIZONTAL ) {
coilGraphic = PImageFactory.create( MriResources.getImage( MriConfig.COIL_IMAGE ), new Dimension( (int)coilWidth, (int)bounds.getHeight() ) );
coilGraphic.setOffset( xLoc, 0 );
}
else {
coilGraphic = PImageFactory.create( MriResources.getImage( MriConfig.COIL_IMAGE ), new Dimension( (int)coilWidth, (int)bounds.getWidth() ) );
coilGraphic.rotate( Math.PI / 2 );
coilGraphic.translate( xLoc, -bounds.getWidth() );
}
addChild( coilGraphic );
coilsGraphics[i] = coilGraphic;
}
}
示例2: drag
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public void drag(final PInputEvent e) {
final PNode node = e.getPickedNode();
node.translate(e.getDelta().width, e.getDelta().height);
final ArrayList edges = (ArrayList) e.getPickedNode().getAttribute("edges");
int i;
for (i = 0; i < edges.size(); i++) {
final PPath edge = (PPath) edges.get(i);
final ArrayList nodes = (ArrayList) edge.getAttribute("nodes");
final PNode node1 = (PNode) nodes.get(0);
final PNode node2 = (PNode) nodes.get(1);
edge.reset();
// Note that the node's "FullBounds" must be used (instead of
// just the "Bound") because the nodes have non-identity
// transforms which must be included when determining their
// position.
final Point2D.Double bound1 = (Point2D.Double) node1.getFullBounds().getCenter2D();
final Point2D.Double bound2 = (Point2D.Double) node2.getFullBounds().getCenter2D();
edge.moveTo((float) bound1.getX(), (float) bound1.getY());
edge.lineTo((float) bound2.getX(), (float) bound2.getY());
}
}
示例3: updateTransform
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
private void updateTransform( PNode node, double d, double theta ) {
node.setTransform( new AffineTransform() );
node.translate( pivotPt.getX() - ( node.getFullBounds().getWidth() / 2 * scale ), pivotPt.getY() );
node.rotateAboutPoint( theta, node.getFullBounds().getWidth() / 2 * scale, 0 );
node.setScale( scale );
node.translate( 0, d );
}
示例4: SurfaceObjectNode
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
private SurfaceObjectNode( BufferedImage image, double sy, double x ) {
PNode imageNode = new PImage( image );
double scale = sy / image.getHeight();
imageNode.transformBy( AffineTransform.getScaleInstance( scale, -scale ) );
double dy = -imageNode.getFullBounds().getHeight() / scale;
imageNode.translate( x / scale, dy );//10 meters east
addChild( imageNode );
}
示例5: TestDraggingInDifferentFrames
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public TestDraggingInDifferentFrames() {
final PhetPCanvas contentPane = new PhetPCanvas();
contentPane.setZoomEventHandler( new PZoomEventHandler() );
frame.setContentPane( contentPane );
frame.setSize( 1024, 768 );
BoxNode boxNode = new BoxNode();
contentPane.addScreenChild( boxNode );
PNode rotateFrame = new PNode();
rotateFrame.rotate( Math.PI / 2 );
rotateFrame.translate( 0, -300 );
rotateFrame.addChild( new BoxNode() );
contentPane.addScreenChild( rotateFrame );
PNode offsetFrame = new PNode();
offsetFrame.setOffset( 200, 200 );
offsetFrame.addChild( new BoxNode() );
PNode offsetScaleNode = new PNode();
offsetScaleNode.setOffset( 0, 200 );
offsetScaleNode.scale( 2.0 );
offsetScaleNode.addChild( new BoxNode() );
contentPane.addScreenChild( offsetScaleNode );
PNode parentNode = new PNode();
parentNode.translate( 400, 400 );
parentNode.scale( 1.2 );
parentNode.rotate( Math.PI / 12 );
parentNode.addChild( new BoxNode() );
contentPane.addScreenChild( parentNode );
PNode childNode = new PNode();
childNode.scale( 1.2 );
childNode.rotate( Math.PI / 6 );
childNode.translate( 50, 50 );
childNode.addChild( boxNode );
parentNode.addChild( childNode );
}
示例6: composeOtherNodes
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public void composeOtherNodes() {
final PNode myCompositeFace = PPath.createRectangle(0, 0, 100, 80);
// create parts for the face.
final PNode eye1 = PPath.createEllipse(0, 0, 20, 20);
eye1.setPaint(Color.YELLOW);
final PNode eye2 = (PNode) eye1.clone();
final PNode mouth = PPath.createRectangle(0, 0, 40, 20);
mouth.setPaint(Color.BLACK);
// add the face parts
myCompositeFace.addChild(eye1);
myCompositeFace.addChild(eye2);
myCompositeFace.addChild(mouth);
// don't want anyone grabbing out our eye's.
myCompositeFace.setChildrenPickable(false);
// position the face parts.
eye2.translate(25, 0);
mouth.translate(0, 30);
// set the face bounds so that it neatly contains the face parts.
final PBounds b = myCompositeFace.getUnionOfChildrenBounds(null);
myCompositeFace.setBounds(b.inset(-5, -5));
// opps it to small, so scale it up.
myCompositeFace.scale(1.5);
getCanvas().getLayer().addChild(myCompositeFace);
}
示例7: initialize
import edu.umd.cs.piccolo.PNode; //导入方法依赖的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);
}
示例8: main
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public static void main( String[] args ) {
{
PNode node = new PNode();
System.out.println( node.getTransform() );
node.scale( 2 );
System.out.println( node.getTransform() );
node.translate( 1, 3 );
System.out.println( node.getTransform() );
node.rotate( Math.PI / 2 );
System.out.println( node.getTransform() );
node.translate( -31, 21 );
System.out.println( node.getTransform() );
System.out.println( node.getOffset().getX() );
System.out.println( node.getOffset().getY() );
System.out.println( node.getRotation() );
node.setOffset( -5, 7 );
System.out.println( node.getTransform() );
node.setRotation( 1.2 );
System.out.println( node.getTransform() );
node.setRotation( -0.7 );
System.out.println( node.getTransform() );
}
}
示例9: dragConstrainPoint
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
private void dragConstrainPoint( PInputEvent event ) {
Point2D mousePosition = event.getPosition();
PNode node = event.getPickedNode();
Rectangle2D nodeBounds = getNodeBounds( node );
/*
* Adjust the mouse location to account for where we clicked
* relative to the node's center point. We want the center
* of the node to remain in the bounds.
*/
double x = mousePosition.getX() - _pressedOffset.getX() + _nodeCenter.getX();
double y = mousePosition.getY() - _pressedOffset.getY() + _nodeCenter.getY();
_adjustedMousePosition.setLocation( x, y );
// Calculate dx
double dx = 0;
if ( _horizontalLockEnabled ) {
dx = 0;
}
else if ( _adjustedMousePosition.getX() < _dragBounds.getX() ) {
// move to far left
dx = _dragBounds.getX() - nodeBounds.getX() - _nodeCenter.getX();
}
else if ( _adjustedMousePosition.getX() > _dragBounds.getX() + _dragBounds.getWidth() ) {
// move to far right
dx = ( _dragBounds.getX() + _dragBounds.getWidth() ) - nodeBounds.getX() - _nodeCenter.getX();
}
else {
// follow mouse
dx = mousePosition.getX() - nodeBounds.getX() - _pressedOffset.getX();
}
// Calculate dy
double dy = 0;
if ( _verticalLockEnabled ) {
dy = 0;
}
else if ( _adjustedMousePosition.getY() < _dragBounds.getY() ) {
// move to top
dy = _dragBounds.getY() - nodeBounds.getY() - _nodeCenter.getY();
}
else if ( _adjustedMousePosition.getY() > _dragBounds.getY() + _dragBounds.getHeight() ) {
// move to bottom
dy = ( _dragBounds.getY() + _dragBounds.getHeight() ) - nodeBounds.getY() - _nodeCenter.getY();
}
else {
// follow mouse
dy = mousePosition.getY() - nodeBounds.getY() - _pressedOffset.getY();
}
// Perform the drag
if ( dx != 0 || dy != 0 ) {
node.translate( dx, dy );
}
}
示例10: dragConstrainBounds
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
private void dragConstrainBounds( PInputEvent event ) {
Point2D mousePosition = event.getPosition();
PNode node = event.getPickedNode();
Rectangle2D nodeBounds = getNodeBounds( node );
/*
* Adjust the mouse location to account for where we clicked
* relative to the node's upper left corner.
*/
double x = mousePosition.getX() - _pressedOffset.getX();
double y = mousePosition.getY() - _pressedOffset.getY();
_adjustedMousePosition.setLocation( x, y );
// Calculate dx
double dx = 0;
if ( _horizontalLockEnabled ) {
dx = 0;
}
else if ( _adjustedMousePosition.getX() < _dragBounds.getX() ) {
// move to far left
dx = _dragBounds.getX() - nodeBounds.getX();
}
else if ( _adjustedMousePosition.getX() + nodeBounds.getWidth() > _dragBounds.getX() + _dragBounds.getWidth() ) {
// move to far right
dx = ( _dragBounds.getX() + _dragBounds.getWidth() - nodeBounds.getWidth() ) - nodeBounds.getX();
}
else {
// follow mouse
dx = mousePosition.getX() - nodeBounds.getX() - _pressedOffset.getX();
}
// Calculate dy
double dy = 0;
if ( _verticalLockEnabled ) {
dy = 0;
}
else if ( _adjustedMousePosition.getY() < _dragBounds.getY() ) {
// move to top
dy = _dragBounds.getY() - nodeBounds.getY();
}
else if ( _adjustedMousePosition.getY() + nodeBounds.getHeight() > _dragBounds.getY() + _dragBounds.getHeight() ) {
// move to bottom
dy = ( _dragBounds.getY() + _dragBounds.getHeight() - nodeBounds.getHeight() ) - nodeBounds.getY();
}
else {
// follow mouse
dy = mousePosition.getY() - nodeBounds.getY() - _pressedOffset.getY();
}
// Perform the drag
if ( dx != 0 || dy != 0 ) {
node.translate( dx, dy );
}
}
示例11: nodeDemo
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public void nodeDemo() {
final PLayer layer = getCanvas().getLayer();
final PNode aNode = PPath.createRectangle(0, 0, 100, 80);
// A node needs to be a descendent of the root to be displayed on the
// screen.
layer.addChild(aNode);
// The default color for a node is blue, but you can change that with
// the setPaint method.
aNode.setPaint(Color.red);
// A node can have children nodes added to it.
aNode.addChild(PPath.createRectangle(0, 0, 100, 80));
// The base bounds of a node is easy to change. Note that changing the
// base
// bounds of a node will not change it's children.
aNode.setBounds(-10, -10, 200, 110);
// Each node has a transform that can be used to transform the node, and
// all its children on the screen.
aNode.translate(100, 100);
aNode.scale(1.5);
aNode.rotate(45);
// The transparency of any node can be set, this transparency will be
// applied to any of the nodes children as well.
aNode.setTransparency(0.75f);
// Its easy to copy nodes.
final PNode aCopy = (PNode) aNode.clone();
// Make is so that the copies children are not pickable. For this
// example
// that means you will not be able to grab the child and remove it from
// its parent.
aNode.setChildrenPickable(false);
// Change the look of the copy
aNode.setPaint(Color.GREEN);
aNode.setTransparency(1.0f);
// Let's add the copy to the root, and translate it so that it does not
// cover the original node.
layer.addChild(aCopy);
aCopy.setOffset(0, 0);
aCopy.rotate(-45);
}
示例12: nodeDemo
import edu.umd.cs.piccolo.PNode; //导入方法依赖的package包/类
public void nodeDemo() {
final PLayer layer = getCanvas().getLayer();
final PNode aNode = PPath.createRectangle(0, 0, 100, 80);
// A node needs to be a descendent of the root to be displayed on the
// screen.
layer.addChild(aNode);
// The default color for a node is blue, but you can change that with
// the setPaint method.
aNode.setPaint(Color.red);
// A node can have children nodes added to it.
aNode.addChild(PPath.createRectangle(0, 0, 100, 80));
// The base bounds of a node is easy to change. Note that changing the
// base bounds of a node will not change it's children.
aNode.setBounds(-10, -10, 200, 110);
// Each node has a transform that can be used to transform the node, and
// all its children on the screen.
aNode.translate(100, 100);
aNode.scale(1.5);
aNode.rotate(45);
// The transparency of any node can be set, this transparency will be
// applied to any of the nodes children as well.
aNode.setTransparency(0.75f);
// Its easy to copy nodes.
final PNode aCopy = (PNode) aNode.clone();
// Make is so that the copies children are not pickable. For this
// example that means you will not be able to grab the child and remove
// it from its parent.
aNode.setChildrenPickable(false);
// Change the look of the copy
aNode.setPaint(Color.GREEN);
aNode.setTransparency(1.0f);
// Let's add the copy to the root, and translate it so that it does not
// cover the original node.
layer.addChild(aCopy);
aCopy.setOffset(0, 0);
aCopy.rotate(-45);
}