Reflect images: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
<jsxgraph width="600" height="500">
<jsxgraph width="600" height="500">
(function(){
(function(){
  var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox:[-5,5,13,-2.5], grid:true});
        var board = JXG.JSXGraph.initBoard('jxgbox', {
  var p0, p1, p2, p3, p5,
            boundingbox: [-5, 5, 13, -2.5],
      l1, l2,
            grid: true
      im1, im2, im3,  
        });
      t1, t2,
        var p0, p1, p2, p3, p4, p5,
      imurl = "/distrib/images/uccellino.jpg",
            l1, l2,
      X, Y, W, H;          // Functions defining the position, width and height of the original image.
            im1, im2, im3,
            t1, t2,
            imurl = "/distrib/images/uccellino.jpg",
            X, Y, W, H;          // Functions defining the position, width and height of the original image.


  // Define two line through four points
        // Define two line through four points
  p0 = brd.createElement('point', [2,-2]);  
        p0 = board.create('point', [2, -2]);
  p1 = brd.createElement('point', [2,1]);  
        p1 = board.create('point', [2, 1]);
  p2 = brd.createElement('point', [10,-1]);  
        p2 = board.create('point', [10, -1]);


  l1 = brd.createElement('line', [p0, p1]);  
        l1 = board.create('line', [p0, p1]);
  l2 = brd.createElement('line', [p1, p2]);  
        l2 = board.create('line', [p1, p2]);


  p4 = brd.createElement('point', [-2,-2]);  
        p4 = board.create('point', [-2, -2]);
  p5 = brd.createElement('point', [1,0]);  
        p5 = board.create('point', [1, 0]);


  X = function(){ return Math.min(p4.X(), p5.X()); };
        X = function () { return Math.min(p4.X(), p5.X()); };
  Y = function(){ return Math.min(p4.Y(), p5.Y()); };
        Y = function () { return Math.min(p4.Y(), p5.Y()); };
  W = function(){ return Math.abs(p5.X() -p4.X()); };
        W = function () { return Math.abs(p5.X() - p4.X()); };
  H = function(){ return Math.abs(p5.Y() -p4.Y()); };
        H = function () { return Math.abs(p5.Y() - p4.Y()); };


  im1 = brd.create('image',[imurl, [X, Y], [W, H]], {opacity:0.7});  
        im1 = board.create('image', [imurl, [X, Y], [W, H]], { opacity: 0.7 });
  im2 = brd.create('image',[imurl, [X, Y], [W, H]], {opacity:0.7});  
        im2 = board.create('image', [imurl, [X, Y], [W, H]], { opacity: 0.7 });
  im3 = brd.create('image',[imurl, [X, Y], [W, H]], {opacity:0.7});  
        im3 = board.create('image', [imurl, [X, Y], [W, H]], { opacity: 0.7 });


  t1 = brd.createElement('transform', [l1], {type:'reflect'});
        t1 = board.create('transform', [l1], { type: 'reflect' });
  t2 = brd.createElement('transform', [l2], {type:'reflect'});
        t2 = board.create('transform', [l2], { type: 'reflect' });


  // Reflect im2 on l1
        // Reflect im2 on l1
  t1.bindTo(im2);
        t1.bindTo(im2);


  // Reflect im2 on l1 and on l2
        // Reflect im3 on l1 and on l2
  t1.bindTo(im3);
        t1.bindTo(im3);
  t2.bindTo(im3);
        t2.bindTo(im3);
 
  brd.update();


        board.update();
})();
})();
</jsxgraph>
</jsxgraph>
Line 47: Line 49:
Here is the complete code to accomplish this behaviour.
Here is the complete code to accomplish this behaviour.
<source lang="javascript">
<source lang="javascript">
        var board = JXG.JSXGraph.initBoard('jxgbox', {
            boundingbox: [-5, 5, 13, -2.5],
            grid: true
        });
        var p0, p1, p2, p3, p4, p5,
            l1, l2,
            im1, im2, im3,
            t1, t2,
            imurl = "/distrib/images/uccellino.jpg",
            X, Y, W, H;          // Functions defining the position, width and height of the original image.
        // Define two line through four points
        p0 = board.create('point', [2, -2]);
        p1 = board.create('point', [2, 1]);
        p2 = board.create('point', [10, -1]);
        l1 = board.create('line', [p0, p1]);
        l2 = board.create('line', [p1, p2]);
        p4 = board.create('point', [-2, -2]);
        p5 = board.create('point', [1, 0]);
        X = function () { return Math.min(p4.X(), p5.X()); };
        Y = function () { return Math.min(p4.Y(), p5.Y()); };
        W = function () { return Math.abs(p5.X() - p4.X()); };
        H = function () { return Math.abs(p5.Y() - p4.Y()); };
        im1 = board.create('image', [imurl, [X, Y], [W, H]], { opacity: 0.7 });
        im2 = board.create('image', [imurl, [X, Y], [W, H]], { opacity: 0.7 });
        im3 = board.create('image', [imurl, [X, Y], [W, H]], { opacity: 0.7 });
        t1 = board.create('transform', [l1], { type: 'reflect' });
        t2 = board.create('transform', [l2], { type: 'reflect' });
        // Reflect im2 on l1
        t1.bindTo(im2);
        // Reflect im3 on l1 and on l2
        t1.bindTo(im3);
        t2.bindTo(im3);
        board.update();
</source>
</source>


[[Category:Examples]]
[[Category:Examples]]
[[Category:Geometry]]
[[Category:Geometry]]

Latest revision as of 06:04, 16 September 2024

The JavaScript code

Here is the complete code to accomplish this behaviour.

        var board = JXG.JSXGraph.initBoard('jxgbox', {
            boundingbox: [-5, 5, 13, -2.5],
            grid: true
        });
        var p0, p1, p2, p3, p4, p5,
            l1, l2,
            im1, im2, im3,
            t1, t2,
            imurl = "/distrib/images/uccellino.jpg",
            X, Y, W, H;          // Functions defining the position, width and height of the original image.

        // Define two line through four points
        p0 = board.create('point', [2, -2]);
        p1 = board.create('point', [2, 1]);
        p2 = board.create('point', [10, -1]);

        l1 = board.create('line', [p0, p1]);
        l2 = board.create('line', [p1, p2]);

        p4 = board.create('point', [-2, -2]);
        p5 = board.create('point', [1, 0]);

        X = function () { return Math.min(p4.X(), p5.X()); };
        Y = function () { return Math.min(p4.Y(), p5.Y()); };
        W = function () { return Math.abs(p5.X() - p4.X()); };
        H = function () { return Math.abs(p5.Y() - p4.Y()); };

        im1 = board.create('image', [imurl, [X, Y], [W, H]], { opacity: 0.7 });
        im2 = board.create('image', [imurl, [X, Y], [W, H]], { opacity: 0.7 });
        im3 = board.create('image', [imurl, [X, Y], [W, H]], { opacity: 0.7 });

        t1 = board.create('transform', [l1], { type: 'reflect' });
        t2 = board.create('transform', [l2], { type: 'reflect' });

        // Reflect im2 on l1
        t1.bindTo(im2);

        // Reflect im3 on l1 and on l2
        t1.bindTo(im3);
        t2.bindTo(im3);

        board.update();