-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


[ ] GraphicsJS JavaScript

, 20 2017 . 11:52 +


. SitePoint "Introducing GraphicsJS, a Powerful Lightweight Graphics Library".

HTML5 . , , , SVG Canvas. Flash , Silverlight , , ActiveX Java-.

SVG Canvas , SVG. , XML, , , SVG DOM.

GraphicsJS. JavaScript- , SVG (VML IE). GraphicsJS, , . . , 50 - .

GraphicsJS


, SVG, : Rapha"el, Snap.svg BonsaiJS. , . GraphicsJS, , .

-, GraphicsJS JavaScript API. , DOM HTML DOM .

-, . AnyChart, , GraphicsJS ( AnyChart 7.0), . (: R&D AnyChart GraphicsJS.)

-, AnyChart JavaScript- GraphicsJS , . GitHub Apache.

-, GraphicsJS - , Internet Explorer 6.0+, Safari 3.0+, Firefox 3.0+, Opera 9.5+. IE VML, SVG.

, GraphicsJS . : , , , , , . API GraphicsJS.

GraphicsJS


GraphicsJS HTML- :


  
    
        
  
  
    

- , , - :

//   
var stage = acgraph.create('stage-container');
//  
var stage.rect(25, 50, 350, 300);

CodePen, .


,


, . () , .

GraphicsJS , , , . , . . GraphicsJS , (!) , .

, . (, ) . ( ). :

//   
var stage = acgraph.create('stage-container');

//  
var frame = stage.rect(25, 50, 350, 300);

//  
var walls = stage.rect(50, 250, 200, 100);
var roof  = stage.path()
  .moveTo(50, 250)
  .lineTo(150, 180)
  .lineTo(250, 250)
  .close();

//  
var head = stage.circle(330, 280, 10);
var neck = stage.path().moveTo(330, 290).lineTo(330, 300);
var kilt = stage.triangleUp(330, 320, 20);
var rightLeg = stage.path().moveTo(320, 330).lineTo(320, 340);
var leftLeg = stage.path().moveTo(340, 330).lineTo(340, 340);

CodePen.

, : , - , , .

, GraphicsJS (, stage.path().moveTo(320, 330).lineTo(320, 340);), . , .

- :

//  
//  
frame.stroke(["red", "green", "blue"], 2, "2 2 2");
//  
walls.fill(acgraph.hatchFill('horizontalbrick'));
//  
roof.fill("#e4d96f");
//  
kilt.fill(acgraph.hatchFill('plaid'));

.

. . , . , , :

// 169 -    
var  text = acgraph.text().text(String.fromCharCode(169)).opacity(0.2);
var  pattern_font = stage.pattern(text.getBounds());
pattern_font.addChild(text);
//    
frame.fill(pattern_font);

, : , , , .


- () 50


, GraphicsJS - Cookie Clicker 50 .

. , . GraphicsJS.

CodePen ( ).

, zIndex, DOM


( ). :

//   
var stage = acgraph.create("stage-container");

//    
var palette_fill = ['#5f8c3f', '#cb9226', '#515523', '#f2ad33', '#8b0f01']; 
var palette_stroke = ['#43622c', '#8e661b', '#393b19', '#a97924', '#610b01'];

// 
var leavesCounter = 0;

, GraphicsJS. , , . ( ): .

, , . , stage.layer zIndex, .

//     
var counterLabel = stage.text(10,10, "Swiped: 0", {fontSize: 20});

//   
var gameLayer = stage.layer().zIndex(counterLabel.zIndex()-1);

, , .


, API , , , , . , GraphicsJS, DOM .

function drawLeaf(x, y) {
  //     
  var index = Math.floor(Math.random() * 5);
  var fill = palette_fill[index];
  var stroke = palette_stroke[index];

  //       
  var scale = Math.round(Math.random() * 30) / 10 + 1;
  var angle = Math.round(Math.random() * 360 * 100) / 100;

  //    ()
  var path = acgraph.path();

  //     
  path.fill(fill).stroke(stroke, 1, 'none', 'round', 'round');
  var size = 18;
  path.moveTo(x, y)
    .curveTo(x + size / 2, y - size / 2, x + 3 * size / 4, y + size / 4, x + size, y)
    .curveTo(x + 3 * size / 4, y + size / 3, x + size / 3, y + size / 3, x, y);

  //   
  path.scale(scale, scale, x, y).rotate(angle, x, y);

  return path; 
};

, , . .


, GraphicsJS . EventType API. .

, (), . , drawLeaf, return:

path.listen("mouseover", function(){
  path.remove();
  counterLabel.text("Swiped: " + leavesCounter++);
  if (gameLayer.numChildren() < 200) shakeTree(300); 
});

, .

if (gameLayer.numChildren() < 200) shakeTree(300); 

, . , , , ( , ).

GraphicsJS DOM, HTML DOM, SVG/VML . , , , .


DOM, GraphicsJS . , , "" .

, , , , :

function shakeTree(n){
  stage.suspend(); //  
  for (var i = 0; i < n; i++) {
    var x = Math.random() * stage.width()/2 + 50;
    var y = Math.random() * stage.height()/2 + 50;
    gameLayer.addChild(drawLeaf(x, y)); //  
  }

  stage.resume(); //  
}

.

//     
shakeTree(500);

, , shakeTree().




HTML5 . - , , . , , GraphicsJS. open-source , , . GraphicsJS , , , .

GraphicsJS . ? ? , , . , JavaScript- , , , .

C





SitePoint: (Roman Lubushkin).
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/331272/


: [1] []
 

:
: 

: ( )

:

  URL