public function test_getFullDescription() { $shape = new Shape(4, 5); $id = $shape->getId(); $name = str_shuffle(time()); $shape->name = $name; $this->assertEquals('Shape<#' . $id . '>: ' . $name . ' - 4 x 5', $shape->getFullDescription()); }
public function __construct($x, $y, $radius, $drawAPI) { Shape::__construct($drawAPI); $this->x = $x; $this->y = $y; $this->radius = $radius; }
public function __construct($id, $width, $height) { Shape::setID($id); $this->setHeight($height); $this->setWidth($width); $this->setArea(); }
/** * @return Shape */ public function getKey() { if (!$this->key) { $this->key = isset($this->definition['key']) ? Shape::create($this->definition['key'], $this->shapeMap) : new Shape(['type' => 'string'], $this->shapeMap); } return $this->key; }
public function CircleShape($x, $y, $radius, DrawingAPI $drawingAPI) { parent::Shape($drawingAPI); $this->x = $x; $this->y = $y; $this->radius = $radius; }
public function __construct($x, $y, $radius, IDrawer $drawer) { parent::__construct($drawer); $this->x = $x; $this->y = $y; $this->radius = $radius; }
public function __construct($dp, $x, $y, $r) { parent::__construct($dp); $this->_x = $x; $this->_y = $y; $this->_r = $r; }
public function __construct($dX, $dY, $dRadius, DrawingAPI $oDrawingAPI) { parent::__construct($oDrawingAPI); $this->dX = $dX; $this->dY = $dY; $this->dRadius = $dRadius; }
public function __construct($x, $y, $radius, DrawingAPI $api) { parent::__construct($api); $this->x = $x; $this->y = $y; $this->radius = $radius; }
public function __construct(array $definition, ShapeMap $shapeMap) { $definition['type'] = 'structure'; if (!isset($definition['members'])) { $definition['members'] = []; } parent::__construct($definition, $shapeMap); }
/** * @return Shape * * @throws \RuntimeException if no member is specified */ public function getMember() { if (!$this->member) { if (!isset($this->definition['member'])) { throw new \RuntimeException('No member attribute specified'); } $this->member = Shape::create($this->definition['member'], $this->shapeMap); } return $this->member; }
public function __construct($x, $y, $color, $radius) { parent::__construct($x, $y, $color); $this->radius = is_numeric($radius) ? $radius : 0; echo "<br>Tworzę obiekt koło <br>"; echo 'położenie x = ' . $this->getX() . '<br>'; echo 'położenie y = ' . $this->getY() . '<br>'; echo 'kolor ' . $this->getColor() . '<br>'; echo 'promień r = ' . $this->getRadius() . '<br>'; echo '<hr>'; }
public function start($attribs) { parent::start($attribs); if (isset($attribs['cx'])) { $this->cx = $attribs['cx']; } if (isset($attribs['cy'])) { $this->cy = $attribs['cy']; } if (isset($attribs['rx'])) { $this->rx = $attribs['rx']; } if (isset($attribs['ry'])) { $this->ry = $attribs['ry']; } $this->document->getSurface()->ellipse($this->cx, $this->cy, $this->rx, $this->ry, 0, 0, 360, false); }
/** * Resolve a shape reference * * @param array $shapeRef Shape reference shape * * @return Shape * @throws \InvalidArgumentException */ public function resolve(array $shapeRef) { $shape = $shapeRef['shape']; if (!isset($this->definitions[$shape])) { throw new \InvalidArgumentException('Shape not found: ' . $shape); } $isSimple = count($shapeRef) == 1; if ($isSimple && isset($this->simple[$shape])) { return $this->simple[$shape]; } $definition = $shapeRef + $this->definitions[$shape]; $definition['name'] = $definition['shape']; unset($definition['shape']); $result = Shape::create($definition, $this); if ($isSimple) { $this->simple[$shape] = $result; } return $result; }
public function cannonBallDraw(&$canvas) { $this->cannonBall->draw($canvas); }
/** * @dataProvider providerResize * @param Shape $shape * @param float $factor */ public function testResize(Shape $shape, $factor) { $expectedPerimeter = round($shape->getPerimeter() * $factor, 2); $shape->scale($factor); $this->assertEquals($expectedPerimeter, round($shape->getPerimeter(), 2)); }
public function __construct(array $definition, ShapeMap $shapeMap) { $definition['type'] = 'timestamp'; parent::__construct($definition, $shapeMap); }
<?php /** * Copyright (c) 2014 Keith Casey. * * This code is designed to accompany the lynda.com video course "Design Patterns in PHP" * by Keith Casey. If you've received this code without seeing the videos, go watch the * videos. It will make way more sense and be more useful in general. */ include_once 'shapes.php'; $shape = Shape::getShape('circle', 3); // This should output 9*Pi echo $shape->getArea(); $shape = Shape::getShape('square', 3); // This should output 9 echo $shape->getArea();
public function __construct($x = 0, $y = 0, $radius = 0, $label = null) { parent::__construct($x, $y, $label); $this->setRadius($radius); }
public function __construct($x = 0, $y = 0, $label = null, $width = 0, $heigth = 0) { parent::__construct($x, $y, $label); $this->setHeigth($heigth)->setWidth($width); }
# This file illustrates the low-level C++ interface # created by SWIG. In this case, all of our C++ classes # get converted into function calls. require "example.php"; # ----- Object creation ----- print "Creating some objects:\n"; $c = new Circle(10); print " Created circle \$c\n"; $s = new Square(10); print " Created square \$s\n"; # ----- Create the ShapeContainer ---- $container = new ShapeContainer(); $container->addShape($c); $container->addShape($s); # ----- Access a static member ----- print "\nA total of " . Shape::nshapes() . " shapes were created\n"; # ----- Delete by the old references ----- # This should not truely delete the shapes because they are now owned # by the ShapeContainer. print "Delete the old references."; # Note: this invokes the virtual destructor $c = NULL; $s = NULL; print "\nA total of " . Shape::nshapes() . " shapes remain\n"; # ----- Delete by the container ----- # This should truely delete the shapes print "Delete the container."; $container = NULL; print "\nA total of " . Shape::nshapes() . " shapes remain\n"; print "Goodbye\n";
$c = new Circle(10); print " Created circle \$c\n"; $s = new Square(10); print " Created square \$s\n"; # ----- Access a static member ----- print "\nA total of " . Shape::nshapes() . " shapes were created\n"; # ----- Member data access ----- # Set the location of the object. # Note: methods in the base class Shape are used since # x and y are defined there. $c->x = 20; $c->y = 30; $s->x = -10; $s->y = 5; print "\nHere is their current position:\n"; print " Circle = (" . $c->x . "," . $c->y . ")\n"; print " Square = (" . $s->x . "," . $s->y . ")\n"; # ----- Call some methods ----- print "\nCall some overloaded methods:\n"; foreach (array(1, 2.1, "quick brown fox", $c, $s) as $o) { print " overloaded = " . overloaded($o) . "\n"; } # Need to unset($o) or else we hang on to a reference to the Square object. unset($o); # ----- Delete everything ----- print "\nGuess I'll clean up now\n"; # Note: this invokes the virtual destructor unset($c); $s = 42; print Shape::nshapes() . " shapes remain\n"; print "Goodbye\n";
// $Id$ include "../jpgraph.php"; include "../jpgraph_canvas.php"; include "../jpgraph_canvtools.php"; // Define work space $xmax = 40; $ymax = 40; // Setup a basic canvas we can work $g = new CanvasGraph(400, 200, 'auto'); $g->SetMargin(5, 11, 6, 11); $g->SetShadow(); $g->SetMarginColor("teal"); // We need to stroke the plotarea and margin before we add the // text since we otherwise would overwrite the text. $g->InitFrame(); // Create a new scale $scale = new CanvasScale($g); $scale->Set(0, $xmax, 0, $ymax); // The shape class is wrapper around the Imgae class which translates // the coordinates for us $shape = new Shape($g, $scale); $shape->SetColor('black'); $shape->IndentedRectangle(1, 2, 15, 15, 8, 8, CORNER_TOPLEFT, 'khaki'); $shape->IndentedRectangle(1, 20, 15, 15, 8, 8, CORNER_BOTTOMLEFT, 'khaki'); $shape->IndentedRectangle(20, 2, 15, 15, 8, 8, CORNER_TOPRIGHT, 'khaki'); $shape->IndentedRectangle(20, 20, 15, 15, 8, 8, CORNER_BOTTOMRIGHT, 'khaki'); // Stroke the graph $g->Stroke(); ?>
# Set the location of the object. # Note: methods in the base class Shape are used since # x and y are defined there. $c->x = 20; $c->y = 30; $s->x = -10; $s->y = 5; print "\nHere is their current position:\n"; print " Circle = (" . $c->x . "," . $c->y . ")\n"; print " Square = (" . $s->x . "," . $s->y . ")\n"; # ----- Call some methods ----- print "\nHere are some properties of the shapes:\n"; foreach (array($c, $s) as $o) { print " " . get_class($o) . " \$o\n"; print " x = " . $o->x . "\n"; print " y = " . $o->y . "\n"; print " area = " . $o->area() . "\n"; print " perimeter = " . $o->perimeter() . "\n"; } # Need to unset($o) or else we hang on to a reference to the Square object. unset($o); # ----- Delete everything ----- print "\nGuess I'll clean up now\n"; # Note: this invokes the virtual destructor unset($c); $s = 42; print Shape::nshapes() . " shapes remain\n"; print "Manually setting nshapes\n"; Shape::nshapes(42); print Shape::get_nshapes() . " == 42\n"; print "Goodbye\n";
public function __construct($a, $r) { $this->name = "Куля"; parent::__construct($a, $r, 0); }
<?php // $Id: canvasbezierex1.php,v 1.1.1.1 2005/11/30 23:01:53 gth2 Exp $ include "../jpgraph.php"; include "../jpgraph_canvas.php"; include "../jpgraph_canvtools.php"; // Setup canvas graph $g = new CanvasGraph(400, 300); $scale = new CanvasScale($g); $shape = new Shape($g, $scale); $g->title->Set('Bezier line with control points'); // Setup control point for bezier $p = array(3, 6, 6, 9, 5, 3, 7, 4); // Visualize control points $shape->SetColor('blue'); $shape->Line($p[0], $p[1], $p[2], $p[3]); $shape->FilledCircle($p[2], $p[3], -6); $shape->SetColor('red'); $shape->Line($p[4], $p[5], $p[6], $p[7]); $shape->FilledCircle($p[4], $p[5], -6); // Draw bezier $shape->SetColor('black'); $shape->Bezier($p); // Frame it with a square $shape->SetColor('navy'); $shape->Rectangle(0.5, 2, 9.5, 9.5); // ... and stroke it $g->Stroke(); ?>
public function __construct($x, $y, $width, $height) { parent::__construct($x, $y); $this->width = $width; $this->height = $height; }
include "../jpgraph.php"; include "../jpgraph_canvas.php"; include "../jpgraph_canvtools.php"; // Scale we are using $ymax = 24; $xmax = 20; // Setup the basic canvas $g = new CanvasGraph(700, 650, 'auto'); $g->SetMargin(2, 3, 2, 3); $g->SetMarginColor("teal"); $g->InitFrame(); // ... and a scale $scale = new CanvasScale($g); $scale->Set(0, $xmax, 0, $ymax); // ... we need shape since we want the indented rectangle $shape = new Shape($g, $scale); $shape->SetColor('black'); // ... basic parameters for the overall image $l = 2; // Left margin $r = 18; // Row number to start the lowest line on $width = 16; // Total width // Setup the two basic rectangle text object we will use $tt = new CanvasRectangleText(); $tt->SetFont(FF_ARIAL, FS_NORMAL, 14); $tt->SetFillColor(''); $tt->SetColor(''); $tt->SetFontColor('navy'); $t = new CanvasRectangleText();
$xmax = 20; $ymax = 20; // Setup a basic canvas we can work $g = new CanvasGraph(400, 200, 'auto'); $g->SetMargin(5, 11, 6, 11); $g->SetShadow(); $g->SetMarginColor("teal"); // We need to stroke the plotarea and margin before we add the // text since we otherwise would overwrite the text. $g->InitFrame(); // Create a new scale $scale = new CanvasScale($g); $scale->Set(0, $xmax, 0, $ymax); // The shape class is wrapper around the Imgae class which translates // the coordinates for us $shape = new Shape($g, $scale); $shape->SetColor('black'); // Add a black line $shape->SetColor('black'); $shape->Line(0, 0, 20, 20); // .. and a circle (x,y,diameter) $shape->Circle(5, 14, 2); // .. and a filled circle (x,y,diameter) $shape->SetColor('red'); $shape->FilledCircle(11, 8, 3); // .. add a rectangle $shape->SetColor('green'); $shape->FilledRectangle(15, 8, 19, 14); // .. add a filled rounded rectangle $shape->SetColor('green'); $shape->FilledRoundedRectangle(2, 3, 8, 6);
public function test_getTypeDescription() { $this->assertEquals('Type: 1', Shape::getTypeDescription()); }