Question

Bonus Laboratory-Raphael JS 1. Using Raphael, create the following shapes: 2. Add some events and effects.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The description of code is given in inline comments.

Code:

<div id="container"></div>

<button id="show">Show</button>

<script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"> </script>

<script>

var paper = Raphael(10, 50, 960, 860);

// we need 6 rectangle to draw television

//  the below 3 rectangles are used for drawing Telivision

var rect1 = paper.rect(300, 100, 200, 100).attr({

    fill: 'gray',

    stroke: 'red',

        'stroke-width': 1,

    cursor: 'pointer'

});

var rect2 = paper.rect(390, 200, 12, 25).attr({

    fill: 'gray',

    stroke: 'red',

        'stroke-width': 1,

    cursor: 'pointer'

});

var rect3 = paper.rect(300, 225, 200, 10).attr({

    fill: 'gray',

    stroke: 'red',

        'stroke-width': 1,

    cursor: 'pointer'

});

//////////////////////////////////////////////

//  the below 3 rectangles are used for Telivision holder

var rect4 = paper.rect(250, 235, 300, 15).attr({

    fill: 'blue',

    stroke: 'red',

        'stroke-width': 0,

    cursor: 'pointer'

});

var rect5 = paper.rect(280, 250, 13,150).attr({

    fill: 'blue',

    stroke: 'red',

        'stroke-width': 0,

    cursor: 'pointer'

});

var rect6 = paper.rect(500, 250, 13,150).attr({

    fill: 'blue',

    stroke: 'red',

        'stroke-width': 0,

    cursor: 'pointer'

});

///////////////////////////////////////////////////////////////

var dot = paper.circle(650, 300, 60).attr({

    fill: 'gray',

    stroke: 'blue',

        'stroke-width': 1,

    cursor: 'pointer'

});

var e = paper.ellipse(650, 100, 40, 80).attr({fill: 'orange', stroke:"red"});

var tetronimo = paper.path("M 600 380 l 100 0 l 17 22 l -20 0 l 0 -10 l -90 0 l 0 10 l -20 0z").attr({

    fill: 'gray',

    stroke: 'blue',

        'stroke-width': 1,

    cursor: 'pointer'

});

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function DrawTriangleOnPaper(x,y,ax,ay,bx,by){

    // typical structure of the triangle

     var trianglePath = [["M",x,y],["L",ax,ay],["L",bx,by],["Z"]];

     var discattr = {fill: "yellow",stroke: "1"};

     

     var triangle = paper.path(trianglePath).attr({

                                        fill: 'blue',

                                        stroke: 'red',

                                        'stroke-width': 1,

                                        }); // Draw the triangle

     

     // The below code creates yellow circles formoving the triangle

     // using below circles we have created the effects

     cont = paper.set(

        paper.circle(x, y, 5).attr(discattr),

        paper.circle(ax, ay, 5).attr(discattr),

        paper.circle(bx, by, 5).attr(discattr));

      

      //We create the update to ove the circle position

      cont[0].update = function(mouseX,mouseY) {

        var newX = this.attr("cx") + mouseX;

        var newY = this.attr("cy") + mouseY;

        this.attr({cx:newX,cy:newY}

        );

        

        trianglePath[0][1] = newX;

        trianglePath[0][2] = newY;

        

        triangle.attr({path: trianglePath});

      }

      cont[1].update = function(mouseX,mouseY) {

        var newX = this.attr("cx") + mouseX;

        var newY = this.attr("cy") + mouseY;

        this.attr({cx:newX,cy:newY});

         trianglePath[1][1]  = newX;

         trianglePath[1][2]  = newY;

         

         triangle.attr({path:trianglePath});

      }

      

      cont[2].update = function(mouseX,mouseY) {

        var newX = this.attr("cx") + mouseX;

        var newY = this.attr("cy") + mouseY;

        this.attr({cx:newX,cy:newY});

         trianglePath[2][1] = newX;

         trianglePath[2][2] = newY;

         

         triangle.attr({path:trianglePath})

      }

      

      // setting the functions on drag

      cont.drag(moveMouse,upMouse);

  }

  

  function moveMouse(mouseX,mouseY){

    this.update(mouseX - (this.mouseX ||0) ,mouseY - (this.mouseY || 0));

    this.mouseX = mouseX;

    this.mouseY = mouseY;

    console.log(mouseX)

    

    console.log('=')

    console.log(mouseY)

  }

  

  function upMouse(){

    this.mouseX = this.mouseY = 0;

  }

DrawTriangleOnPaper(150,210,200,300,100,300);

// for drawing the line

var rectangle = paper.rect(140, 300, 10, 300).attr({

    fill: 'blue',

    stroke: 'blue',

        'stroke-width': 1,

    cursor: 'pointer'

});

// for drawing the rectangle below the triangle

var rectangle = paper.rect(100, 600, 100, 30).attr({

    fill: 'blue',

    stroke: 'blue',

        'stroke-width': 1,

    cursor: 'pointer'

});


//  Creating the button events

var button = document.getElementById('show');

button.onclick = function () {

    console.log("hi")

    dot.animate({

        fill: '#005'

    }, 500);

};

</script>

Screnshot:

2 10 1 <div id=container></div> <button id=show>Show</button> 3 4 <script src=http://cdnjs.cloudflare.com/ajax/libs/raph

56 stroke-width: 1, 57 cursor: pointer 58 }); 59 60 var e = paper.ellipse(650, 100, 40, 80).attr({fill: orange, stroke:

cont[2].update = function(mouseX,mouse) { var newx = this.attr(cx) + mouseX; var newy = this.attr(cy) + mouseY; this.attr

Output :

Show [o

Add a comment
Know the answer?
Add Answer to:
Bonus Laboratory-Raphael JS 1. Using Raphael, create the following shapes: 2. Add some events and effects.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT