home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 14 / IOPROG_14.ISO / soft / sdkjava / dxma.exe / DXMA05.cab / samples / da / java / showcase / Tile / Tile.java < prev   
Encoding:
Java Source  |  1997-11-13  |  4.0 KB  |  113 lines

  1. // Copyright (c) 1997 Microsoft Corporation
  2.  
  3. import com.ms.dxmedia.*;
  4. import java.net.*;
  5.  
  6. class TileModel extends Model {
  7.  
  8.   // For constructing a time-varying range.  This function
  9.   // generates a time varying number bvr provided min and max
  10.   // values, and a rate (number of cycles per second).
  11.   public static NumberBvr myRange(double min, double max, double rate) {
  12.       
  13.       // a = (1 + sin(time * rate)) * 0.5
  14.       NumberBvr a = mul(add(toBvr(1), sin(mul(toBvr(rate), localTime))),
  15.                         toBvr(0.5));
  16.  
  17.       // b = (max - min) * a + min
  18.       NumberBvr b = add(mul(toBvr(max-min), a),
  19.                         toBvr(min));
  20.  
  21.       return b;
  22.   }
  23.  
  24.   public void createModel(BvrsToRun blst) {
  25.  
  26.     URL mediaBase = getImportBase();
  27.     URL imgBase = buildURL(mediaBase,"image/");
  28.       ////// Top Image
  29.       
  30.       // Bring in a bitmap image
  31.       ImageBvr head =
  32.           importImage(buildURL(imgBase,"shingle.jpg"));
  33.  
  34.       // Construct a new image by overlaying atop an empty image that
  35.       // has an infinite bounding box.  This allows subsequent crops
  36.       // to retain the "see-through-ness" that we're trying to
  37.       // achieve. 
  38.       head = overlay(head, detectableEmptyImage);
  39.  
  40.       // Construct four time varying values representing a rectangle
  41.       // whose position is changing, and whose size is changing.  x,
  42.       // y, width, and height.
  43.       NumberBvr xPos = myRange(-0.03, 0.01, 0.8);
  44.       NumberBvr yPos = myRange(-0.03, 0.01, 0.4);
  45.       NumberBvr width = myRange(0.01, 0.07, 1.5);
  46.       NumberBvr height = myRange(0.01, 0.07, 1.5);
  47.  
  48.       // combine these numbers into points at the corners of a
  49.       // rectangle. 
  50.       Point2Bvr hMin = point2(xPos, yPos);
  51.       Point2Bvr hMax = point2(add(xPos, width), add(yPos, height));
  52.  
  53.       // Apply this rectangle as the cropping rectangle
  54.       ImageBvr  croppedHead = head.crop(hMin, hMax);
  55.  
  56.       // Infinitely tile the result.  
  57.       ImageBvr  headTiles = croppedHead.tile();
  58.  
  59.       // Build up a time-varying transform...
  60.       Transform2Bvr xf1 = translate(mul(toBvr(0.03), sin(localTime)),
  61.                                     mul(toBvr(0.03), cos(mul(localTime,
  62.                                                             toBvr(0.3)))));
  63.  
  64.       // ... and apply it to the head tiles to move the whole tiling
  65.       // around.   This completes our top image.
  66.       ImageBvr topIm = headTiles.transform(xf1);
  67.  
  68.  
  69.       ////// Bottom Image
  70.  
  71.       // build up a time-varying transform to apply to the bottom image.
  72.       Transform2Bvr xf2 = translate(mul(toBvr(0.01), sin(localTime)),
  73.                                     mul(toBvr(0.01), cos(localTime)));
  74.  
  75.       // Construct two time varying colors that cycle through the
  76.       // hues. 
  77.       ColorBvr col1 = colorHsl(mul(localTime, toBvr(0.5)),
  78.                                toBvr(0.5),
  79.                                toBvr(0.5));
  80.       
  81.       ColorBvr col2 = colorHsl(mul(localTime, toBvr(0.43)),
  82.                                toBvr(0.5),
  83.                                toBvr(0.5));
  84.  
  85.       // Use these to construct a unit-sized gradient image with black
  86.       // and white at two corners, and these time-varying colors at
  87.       // the other two corners.
  88.       ImageBvr gradImg = gradientSquare(col1, black, col2, white);
  89.  
  90.       // Now scale this way down.
  91.       gradImg = gradImg.transform(scale2(0.065));
  92.  
  93.       // Create the bottom image by transforming the gradient image
  94.       // around. 
  95.       ImageBvr botIm = gradImg.transform(xf2);
  96.  
  97.       ////// Entire model
  98.  
  99.       // Finally, overlay the top over the bottom over a solid white
  100.       // image. 
  101.       ImageBvr model = overlay(topIm,
  102.                                overlay(botIm,
  103.                                        solidColorImage(white)));
  104.  
  105.       // And set the model's image to this image.
  106.       setImage(model);
  107.   }
  108. }
  109.  
  110. public class Tile extends DXMApplet {
  111.     public Tile() { setModel(new TileModel()) ; }
  112. }
  113.