Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
WarpImage.java
Package: Java2D.rar [view]
Upload User: cdlibang
Upload Date: 2016-07-17
Package Size: 774k
Code Size: 5k
Category:
2D Graphic
Development Platform:
Java
- /*
- * @(#)WarpImage.java 1.16 99/04/23
- *
- * Copyright (c) 1998, 1999 by Sun Microsystems, Inc. All Rights Reserved.
- *
- * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
- * modify and redistribute this software in source and binary code form,
- * provided that i) this copyright notice and license appear on all copies of
- * the software; and ii) Licensee does not utilize the software in a manner
- * which is disparaging to Sun.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
- * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
- * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
- * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
- * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
- * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
- * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
- * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
- * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * This software is not designed or intended for use in on-line control of
- * aircraft, air traffic, aircraft navigation or aircraft communications; or in
- * the design, construction, operation or maintenance of any nuclear
- * facility. Licensee represents and warrants that it will not use or
- * redistribute the Software for such purposes.
- */
- package demos.Images;
- import java.awt.*;
- import java.awt.event.*;
- import java.awt.geom.CubicCurve2D;
- import java.awt.geom.Point2D;
- import java.awt.geom.FlatteningPathIterator;
- import java.awt.geom.PathIterator;
- import AnimatingContext;
- import DemoSurface;
- import DemoPanel;
- /**
- * Warps a image on a CubicCurve2D flattened path.
- */
- public class WarpImage extends DemoSurface implements AnimatingContext {
- private static int iw, ih, iw2, ih2;
- private static Image img;
- private static final int FORWARD = 0;
- private static final int BACK = 1;
- private Point2D pts[];
- private int direction = FORWARD;
- private int pNum;
- private int x, y;
- public WarpImage() {
- setBackground(Color.white);
- img = getImage("surfing.gif");
- iw = img.getWidth(this);
- ih = img.getHeight(this);
- iw2 = iw/2;
- ih2 = ih/2;
- }
- public void reset(int w, int h) {
- pNum = 0;
- direction = FORWARD;
- CubicCurve2D cc = new CubicCurve2D.Float(
- w*.2f, h*.5f, w*.4f,0, w*.6f,h,w*.8f,h*.5f);
- PathIterator pi = cc.getPathIterator(null, 0.1);
- Point2D tmp[] = new Point2D[200];
- int i = 0;
- while ( !pi.isDone() ) {
- float[] coords = new float[6];
- switch ( pi.currentSegment(coords) ) {
- case pi.SEG_MOVETO:
- case pi.SEG_LINETO:
- tmp[i] = new Point2D.Float(coords[0], coords[1]);
- }
- i++;
- pi.next();
- }
- pts = new Point2D[i];
- System.arraycopy(tmp,0,pts,0,i);
- }
- public void step(int w, int h) {
- if (pts == null) {
- return;
- }
- x = (int) pts[pNum].getX();
- y = (int) pts[pNum].getY();
- if (direction == FORWARD)
- if (++pNum == pts.length)
- direction = BACK;
- if (direction == BACK)
- if (--pNum == 0)
- direction = FORWARD;
- }
- public void drawDemo(int w, int h, Graphics2D g2) {
- g2.drawImage(img,
- 0, 0, x, y,
- 0, 0, iw2, ih2,
- this);
- g2.drawImage(img,
- x, 0, w, y,
- iw2, 0, iw, ih2,
- this);
- g2.drawImage(img,
- 0, y, x, h,
- 0, ih2, iw2, ih,
- this);
- g2.drawImage(img,
- x, y, w, h,
- iw2, ih2, iw, ih,
- this);
- }
- public static void main(String argv[]) {
- final DemoPanel dp = new DemoPanel(new WarpImage());
- Frame f = new Frame("Java2D Demo - WarpImage");
- f.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {System.exit(0);}
- public void windowDeiconified(WindowEvent e) {
- dp.surface.start();
- }
- public void windowIconified(WindowEvent e) {
- dp.surface.stop();
- }
- });
- f.add("Center", dp);
- f.pack();
- f.setSize(new Dimension(400,300));
- f.show();
- dp.surface.start();
- }
- }