1# Drawing a spring chart 2 3[Reference](http://wiki.pchart.net/doc.spring.drawspring.html) 4 5```php 6require '/path/to/your/vendor/autoload.php'; 7 8use CpChart\Chart\Spring; 9use CpChart\Image; 10 11/* Create the Image object */ 12$image = new Image(300, 300); 13 14/* Background customization */ 15$image->drawGradientArea(0, 0, 300, 300, DIRECTION_HORIZONTAL, [ 16 "StartR" => 217, 17 "StartG" => 250, 18 "StartB" => 116, 19 "EndR" => 181, 20 "EndG" => 209, 21 "EndB" => 27, 22 "Alpha" => 100 23]); 24$image->drawGradientArea(0, 0, 300, 20, DIRECTION_VERTICAL, [ 25 "StartR" => 0, 26 "StartG" => 0, 27 "StartB" => 0, 28 "EndR" => 50, 29 "EndG" => 50, 30 "EndB" => 50, 31 "Alpha" => 100 32]); 33$image->drawRectangle(0, 0, 299, 299, ["R" => 0, "G" => 0, "B" => 0]); 34$image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]); 35$image->drawText(10, 13, "pSpring - Draw spring charts", ["R" => 255, "G" => 255, "B" => 255]); 36 37/* Prepare the graph area */ 38$image->setGraphArea(20, 20, 280, 280); 39$image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 9, "R" => 80, "G" => 80, "B" => 80]); 40$image->setShadow(true, ["X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]); 41 42/* Create the pSpring object */ 43$springChart = new Spring(); 44 45/* Set the nodes default settings */ 46$springChart->setNodeDefaults(["FreeZone" => 50]); 47 48/* Build random nodes & connections */ 49for ($i = 0; $i <= 10; $i++) { 50 $connections = []; 51 for ($j = 0; $j <= rand(0, 1); $j++) { 52 $connections[] = rand(0, 10); 53 } 54 $springChart->addNode($i, ["Name" => "Node " . $i, "Connections" => $connections]); 55} 56 57/* Compute and draw the Spring Graph */ 58$springChart->drawSpring($image, ["DrawQuietZone" => true]); 59 60/* Render the picture */ 61$image->render("drawSpring3.png"); 62``` 63