home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 14 / IOPROG_14.ISO / soft / sdkjava / dxma.exe / DXMA05.cab / samples / da / java / exercises / Apple / Apple.java next >
Encoding:
Java Source  |  1997-11-13  |  1.5 KB  |  45 lines

  1. // This applet illustrates importing and displaying an image
  2. //
  3. // Copyright (c) 1997 Microsoft Corporation
  4.  
  5. import com.ms.dxmedia.*;
  6. import java.net.*;
  7.  
  8. class AppleModel extends Model {
  9.  
  10.   // Create the image in the createModel method.
  11.   public void createModel(BvrsToRun blist) {
  12.     // Build up a URL to import relative to.
  13.     URL mediaBase = getImportBase();
  14.     URL imgBase = buildURL(mediaBase, "Image/");    
  15.  
  16.     // Import a few bitmaps bitmap.
  17.     ImageBvr pictImg = importImage(buildURL(imgBase, "foliageUtah.jpg"));
  18.     ImageBvr bgImg = importImage(buildURL(imgBase, "sandbg1.jpg"));
  19.     ImageBvr appleImg = importImage(buildURL(imgBase, "apple.gif"));
  20.  
  21.     // construct an apple sprite with a time varying opacity
  22.     appleImg = appleImg.opacity(abs(sin(localTime)));
  23.  
  24.     // a transform for sinosoidal oscillation
  25.     Transform2Bvr apple1Tf = rotate(mul(sin(localTime), toBvr(Math.PI/6)));     
  26.     // another for sinosoidal translation
  27.     Transform2Bvr apple2Tf = translate(mul(sin(localTime), toBvr(1.5 * cm)), toBvr(0));
  28.  
  29.     // construct an apple that oscillates both raidally and linearly
  30.     appleImg = appleImg.transform(apple1Tf);
  31.     appleImg = appleImg.transform(apple2Tf);
  32.  
  33.     // tile the background sprite, overlay it with a picture and the 
  34.     // animate apple
  35.     setImage(overlay(overlay(appleImg, pictImg), bgImg.tile()));
  36.   }
  37. }
  38.  
  39. public class Apple extends DXMApplet {
  40.   public void init() {
  41.     super.init() ;
  42.     setModel(new AppleModel());
  43.   }
  44. }
  45.