Ejemplo n.º 1
0
 public function test_getFullDescription()
 {
     $circle = new Circle(13);
     $id = $circle->getId();
     $name = str_shuffle(time());
     $circle->name = $name;
     $this->assertEquals('Circle<#' . $id . '>: ' . $name . ' - 13', $circle->getFullDescription());
 }
Ejemplo n.º 2
0
function testCircle(Circle $circle)
{
    $circle->setWidth(2);
    assert('$circle->getWidth() == 2');
    $circle->setHeight(4);
    assert('$circle->getHeight() == 4');
    assert('$circle->getWidth() == $circle->getHeight()');
    // kruznica garantuje, ze sirka a vyska su rovnake
}
Ejemplo n.º 3
0
 public function testCircleSquare()
 {
     $circle = new Circle();
     if ($circle instanceof ISquarable) {
         $circle->square();
     } else {
         $this->assertTrue(false, 'Circle must have square');
     }
 }
Ejemplo n.º 4
0
 public function loadCache()
 {
     $rect = new Rectangle();
     $rect->setId("1");
     $this->shapeMap["1"] = $rect;
     $square = new Square();
     $square->setId("2");
     $this->shapeMap["2"] = $square;
     $circle = new Circle();
     $circle->setId("3");
     $this->shapeMap["3"] = $circle;
 }
 public function __construct(array $classes)
 {
     foreach ($classes as $class) {
         require_once "trials/{$class}.php";
         $circle = new Circle($class);
         $rfl_class = new ReflectionClass($class);
         foreach ($rfl_class->getMethods() as $method) {
             if ($method->isPublic()) {
                 $circle->add_trial($this->build_trial($rfl_class, $method));
             }
         }
         $this->circles[] = $circle;
     }
 }
Ejemplo n.º 6
0
 public function register($aid, $name, $gender, $age, $type, $u_name, $u_gender, $u_city, $inviter)
 {
     $user = new User();
     $user->name = $u_name;
     $user->gender = $u_gender;
     $user->city = $u_city;
     $user->code = $this->createInviteCode();
     $user->inviter = $inviter;
     $user->gold = 500;
     $reward_items = array(1101 => 3, 1102 => 3, 1103 => 3, 1104 => 3, 1105 => 3, 1106 => 3, 1107 => 3, 1201 => 2, 1202 => 2, 1203 => 2, 1204 => 2, 1205 => 2, 1206 => 2, 1207 => 2, 1301 => 1, 1302 => 1, 1303 => 1, 1304 => 1, 1305 => 1, 2101 => 3, 2102 => 3, 2103 => 3, 2104 => 3);
     $user->items = serialize($reward_items);
     $user->save();
     if (!isset($aid)) {
         $animal = new Animal();
         $animal->name = $name;
         $animal->gender = $gender;
         $animal->age = $age;
         $animal->type = $type;
         $animal->from = substr($type, 0, 1);
         $animal->master_id = $user->usr_id;
         $animal->save();
         $aid = $animal->aid;
         $circle = new Circle();
         $circle->aid = $aid;
         $circle->usr_id = $user->usr_id;
         $circle->rank = 0;
         $circle->save();
     } else {
         $circle = new Circle();
         $circle->aid = $aid;
         $circle->usr_id = $user->usr_id;
         $circle->save();
     }
     $f = new Follow();
     $f->usr_id = $user->usr_id;
     $f->aid = $aid;
     $f->create_time = time();
     $f->save();
     $user->aid = $aid;
     $user->saveAttributes(array('aid'));
     $user->initialize();
     $user->rewardInviter();
     //$this->onRegister = array($user, 'initialize');
     //$this->onRegister = array($user, 'rewardInviter');
     $this->owner->usr_id = $user->usr_id;
     $this->owner->saveAttributes(array('usr_id'));
     $this->onRegister(new CEvent());
     return $user;
 }
Ejemplo n.º 7
0
 public function getIntersectionPoint()
 {
     if (!$this->circleA || !$this->circleB || !$this->circleC) {
         return false;
     }
     $vectorP1 = $this->getECRVector($this->circleA);
     $vectorP2 = $this->getECRVector($this->circleB);
     $vectorP3 = $this->getECRVector($this->circleC);
     #from wikipedia: http://en.wikipedia.org/wiki/Trilateration
     #transform to get circle 1 at origin
     #transform to get circle 2 on x axis
     // CALC EX
     $l = $vectorP2->subtract($vectorP1);
     $norm = new Vector(array_fill(0, 3, $l->length()));
     $d = $norm;
     $ex = $l->divide($norm);
     // CALC i
     $P3minusP1 = $vectorP3->subtract($vectorP1);
     $i = $ex->dotProduct($P3minusP1);
     // CALC EY
     $iex = $ex->multiplyByScalar($i);
     $P3P1iex = $P3minusP1->subtract($iex);
     $l = $P3P1iex;
     $norm = new Vector(array_fill(0, 3, $l->length()));
     $ey = $P3P1iex->divide($norm);
     // CALC EZ
     $ez = $ex->crossProduct($ey);
     // CALC D
     $d = $d->getElement(0);
     // CALC J
     $j = $ey->dotProduct($P3minusP1);
     #from wikipedia
     #plug and chug using above values
     $x = (pow($this->circleA->getRadius(), 2) - pow($this->circleB->getRadius(), 2) + pow($d, 2)) / (2 * $d);
     $y = (pow($this->circleA->getRadius(), 2) - pow($this->circleC->getRadius(), 2) + pow($i, 2) + pow($j, 2)) / (2 * $j) - $i / $j * $x;
     # only one case shown here
     $z = sqrt(pow($this->circleA->getRadius(), 2) - pow($x, 2) - pow($y, 2));
     #triPt is an array with ECEF x,y,z of trilateration point
     $xex = $ex->multiplyByScalar($x);
     $yey = $ey->multiplyByScalar($y);
     $zez = $ez->multiplyByScalar($z);
     // CALC $triPt = $P1vector + $xex + $yey + $zez;
     $triPt = $vectorP1->add($xex)->add($yey)->add($zez);
     $triPtX = $triPt->getElement(0);
     $triPtY = $triPt->getElement(1);
     $triPtZ = $triPt->getElement(2);
     #convert back to lat/long from ECEF
     #convert to degrees
     $lat = rad2deg(asin($triPtZ / $this->earthRadius));
     $lng = rad2deg(atan2($triPtY, $triPtX));
     return compact('lat', 'lng');
 }
Ejemplo n.º 8
0
 public function start()
 {
     $r = Yii::app()->db->createCommand('SELECT aid, name, type, tx, d_rq  FROM dc_animal ORDER BY d_rq DESC')->queryAll();
     $prev_rank = Yii::app()->cache->get('d_rq_rank_report');
     if (isset($prev_rank)) {
         foreach ($r as $k => $v) {
             $rank[$v['aid']] = $k;
             if (isset($prev_rank[$v['aid']]) && $prev_rank[$v['aid']] > $k) {
                 $r[$k]['change'] = 1;
             } else {
                 if (isset($prev_rank[$v['aid']]) && $prev_rank[$v['aid']] < $k) {
                     $r[$k]['change'] = -1;
                 } else {
                     $r[$k]['change'] = 0;
                 }
             }
         }
     } else {
         foreach ($r as $k => $v) {
             $rank[$v['aid']] = $k;
             $r[$k]['change'] = 0;
         }
     }
     //奖励计算
     $total_member = Yii::app()->db->createCommand('SELECT COUNT(*) FROM dc_user')->queryScalar();
     $total_a = Yii::app()->db->createCommand('SELECT COUNT(aid), SUM(d_rq) FROM dc_animal')->queryRow();
     $all_gold = $total_member * RANK_REWARD_E;
     $total_popularity = $total_a['SUM(d_rq)'];
     $reward_count = round($total_a['COUNT(aid)'] * 30 / 100);
     for ($i = 0; $i < $reward_count; $i++) {
         $aid = $r[$i]['aid'];
         $single_popularity = $r[$i]['d_rq'];
         $total_gold = $all_gold * $single_popularity / $total_popularity;
         if ($total_gold != 0) {
             $circles = Circle::model()->findAllByAttributes(array('aid' => $aid));
             foreach ($circles as $circle) {
                 $result_money = round($total_gold * $circle->d_contri / $single_popularity);
                 $user = User::model()->findByPk($circle->usr_id);
                 $user->gold += $result_money;
                 $user->saveAttributes(array('gold'));
                 $self_rank = $i + 1;
                 $msg = "您的王国/家族在人气日排行榜中获得第" . $self_rank . "名,您获得" . $result_money . "金币奖励";
                 Talk::model()->sendMsg(NPC_SYSTEM_USRID, $user->usr_id, $msg);
             }
         }
     }
     Yii::app()->cache->set('d_rq_rank_report', $rank, 3600 * 24);
     Yii::app()->cache->set('d_rq_rank', $r, 3600 * 24);
 }
Ejemplo n.º 9
0
<?php

define('CONT_NAME', 'value');
const OTHER_CONSTANT = 'value';
const CONSTANT_ARRAY = ['a' => 1, 'b' => 2];
class Circle
{
    const PI = 3.14;
    const DEFAULT_RADIUS = 3;
    public static function getArea($r = self::DEFAULT_RADIUS)
    {
        return self::PI * pow($r, 2);
    }
}
var_dump(Circle::getArea(5));
Ejemplo n.º 10
0
{
    protected $decoratedShape;
    function __construct(Shape $decoratedShape)
    {
        $this->decoratedShape = $decoratedShape;
    }
    function draw()
    {
        $this->decoratedShape->draw();
    }
}
class RedShapeDecorator extends ShapeDecorator
{
    function __construct(Shape $decoratedShape)
    {
        parent::__construct($decoratedShape);
    }
    private function setRedBorder()
    {
        echo 'Border color: red';
    }
    function draw()
    {
        $this->decoratedShape->draw();
        $this->setRedBorder();
    }
}
$c = new Circle();
$c->draw();
$rc = new RedShapeDecorator($c);
$rc->draw();
<?php

$success = false;
$errors = array();
$data = array();
$objects = array();
require 'includes/initialize.php';
if (!$session->is_logged_in()) {
    array_push($errors, "Not logged in.");
} else {
    if (isset($_GET['user_id'])) {
        $user = User::find_by_id($_GET['user_id']);
        $circles = Circle::find_by_user_id($session->user_id);
        $og_circle_ids = array();
        foreach ($circles as $circle) {
            array_push($og_circle_ids, $circle->circle_id);
        }
        $user->remove_from_circles($og_circle_ids);
        $user->add_to_circles($_GET['circle_ids']);
        $success = true;
    }
}
display_success($success, $errors, $data, $objects);
    }
}
class ShapeInfo
{
    private $_shape;
    public function setShape($shape)
    {
        $this->_shape = $shape;
    }
    public function showInfo()
    {
        echo "<p>The shape's color is " . $this->_shape->getColor();
        echo ", and its area is " . $this->_shape->getArea() . ".</p>";
    }
}
$myCircle = new Circle();
$myCircle->setColor("red");
$myCircle->fill();
$myCircle->setRadius(4);
$mySquare = new Square();
$mySquare->setColor("green");
$mySquare->makeHollow();
$mySquare->setSideLength(3);
$info = new ShapeInfo();
$info->setShape($myCircle);
$info->showInfo();
// Displays "The shape's color is red, and its area is 50.2654824574."
$info->setShape($mySquare);
$info->showInfo();
// Displays "The shape's color is green, and its area is 9."
$myRect = new Rectangle();
Ejemplo n.º 13
0
<?php

require_once "Circle.php";
$shape = new Circle();
sleep(1);
echo "Прошло некоторое время ...";
$shape->movBy(101, 6);
sleep(1);
echo "Прошло некоторое время ...";
$shape->resizeBy(2.0);
sleep(1);
echo "Прошло некоторое время ...";
Ejemplo n.º 14
0
        return $this->color;
    }
    function getArea()
    {
        return pow($this->lenght, 2);
    }
}
class Square extends Shape
{
}
class Triangle extends Shape
{
    protected $base = 4;
    protected $height = 7;
    function getArea()
    {
        return 0.5 * $this->base * $this->height;
    }
}
class Circle extends Shape
{
    protected $radius = 5;
    public function getArea()
    {
        return M_PI * pow($this->radius, 2);
    }
}
echo (new Triangle())->getArea();
echo (new Square('green'))->getColor();
$circle = new Circle();
echo $circle->getArea();
Ejemplo n.º 15
0
$rec->__construct(4, 8, 20, 4, 2);
$rec->printShape();
//Square
$sq = new Square();
$sq->__construct(10, 40, 0, 5);
$sq->printShape();
//Triangle
$tri = new Triangle();
$tri->__construct(35, 20, 20, 50, 50, 50);
$tri->printShape();
//Oval
$oval = new Oval();
$oval->__construct(10, 9, 8);
$oval->printShape();
//Circle
$circle = new Circle();
$circle->__construct(80, 80, 10);
$circle->printShape();
//Demos the getAreas function
$shape->getAreas($shape, $rec, $circle);
class Shape
{
    /*Due to the nature of random shapes
      sideLengths does not go into the constructor.
      numSides will be calculated based on the number of sides entered.*/
    public $sideLengths;
    public $numSides;
    public $width;
    public $height;
    public $rotation;
    public $perim;
Ejemplo n.º 16
0
<?php

class Circle
{
    const pi = 3.14;
    public function Area($radius)
    {
        return self::pi * ($radius * $radius);
    }
}
$get = new Circle();
echo $get->Area(5);
Ejemplo n.º 17
0
Archivo: walec.php Proyecto: kabaj/opp
 public function getArea()
 {
     echo "Liczymy obwod <br>";
     $xxx = parent::getPerimeter();
     echo $xxx * $this->h . "<br>";
 }
Ejemplo n.º 18
0
    function perimeter()
    {
        return (2 * $this->radius * 3.14);
    }

    function translate($deltaX, $deltaY)
    {
        $this->centerx += $deltaX;
        $this->centery += $deltaY;
        return "X axis is now at " . ($this->centerx) . " and Y axis is now at " . ($this->centery);
    }

    function ptInCircle ($x, $y)
    {$dx = $this->centerx - $x;
     $dy = $this->centery - $y;

        if (pow($dx, 2) + pow($dy,2) < pow($this->radius,2)){
        return "true";
    }
        else return "false";}
}

$circle = new Circle(10,10,50);
echo $circle->area()."<br>";
echo $circle->perimeter()."<br>";
echo $circle->translate(15,15)."<br>";//will move x and y by 15
echo $circle->ptInCircle (11,11)."<br>";
echo $circle->ptInCircle(70,70)."<br>";
?>
Ejemplo n.º 19
0
    protected $drawAPI;
    protected function __construct($drawAPI)
    {
        $this->drawAPI = $drawAPI;
    }
    public abstract function draw();
}
// create concrete class implementing the Shape interface (abstract class)
class Circle extends Shape
{
    private $x;
    private $y;
    private $radius;
    public function __construct($x, $y, $radius, $drawAPI)
    {
        Shape::__construct($drawAPI);
        $this->x = $x;
        $this->y = $y;
        $this->radius = $radius;
    }
    public function draw()
    {
        $this->drawAPI->drawCircle($this->radius, $this->x, $this->y);
    }
}
// Use Shape and DrawAPI classes to draw different colored circles
// implementation of concrete circles selected at run time.
$redCircle = new Circle(100, 100, 10, new RedCircle());
$greenCircle = new Circle(100, 100, 10, new GreenCircle());
$redCircle->draw();
$greenCircle->draw();
Ejemplo n.º 20
0
<?php

// interface.php
require_once "app_autoload.php";
$circle = new Circle(7);
echo $circle->serialise();
Ejemplo n.º 21
0
function CreateTestAnnots($doc)
{
    $ew = new ElementWriter();
    $eb = new ElementBuilder();
    $first_page = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0));
    $doc->PagePushBack($first_page);
    $ew->Begin($first_page, ElementWriter::e_overlay, false);
    // begin writing to this page
    $ew->End();
    // save changes to the current page
    //
    // Test of a free text annotation.
    //
    $txtannot = FreeText::Create($doc->GetSDFDoc(), new Rect(10.0, 400.0, 160.0, 570.0));
    $txtannot->SetContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." . "\n\nAha!\n\nAnd there was much rejoicing!");
    $txtannot->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 1.0, 10.0, 20.0), true);
    $txtannot->SetQuaddingFormat(0);
    $first_page->AnnotPushBack($txtannot);
    $txtannot->RefreshAppearance();
    $txtannot = FreeText::Create($doc->GetSDFDoc(), new Rect(100.0, 100.0, 350.0, 500.0));
    $txtannot->SetContentRect(new Rect(200.0, 200.0, 350.0, 500.0));
    $txtannot->SetContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." . "\n\nAha!\n\nAnd there was much rejoicing!");
    $txtannot->SetCalloutLinePoints(new Point(200.0, 300.0), new Point(150.0, 290.0), new Point(110.0, 110.0));
    $txtannot->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 1.0, 10.0, 20.0), true);
    $txtannot->SetEndingStyle(LineAnnot::e_ClosedArrow);
    $txtannot->SetColor(new ColorPt(0.0, 1.0, 0.0));
    $txtannot->SetQuaddingFormat(1);
    $first_page->AnnotPushBack($txtannot);
    $txtannot->RefreshAppearance();
    $txtannot = FreeText::Create($doc->GetSDFDoc(), new Rect(400.0, 10.0, 550.0, 400.0));
    $txtannot->SetContents("\n\nSome swift brown fox snatched a gray hare out of the air by freezing it with an angry glare." . "\n\nAha!\n\nAnd there was much rejoicing!");
    $txtannot->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 1.0, 10.0, 20.0), true);
    $txtannot->SetColor(new ColorPt(0.0, 0.0, 1.0));
    $txtannot->SetOpacity(0.2);
    $txtannot->SetQuaddingFormat(2);
    $first_page->AnnotPushBack($txtannot);
    $txtannot->RefreshAppearance();
    $page = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0));
    $doc->PagePushBack($page);
    $ew->Begin($page, ElementWriter::e_overlay, false);
    // begin writing to this page
    $eb->Reset();
    // Reset the GState to default
    $ew->End();
    // save changes to the current page
    //Create a Line annotation...
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(250.0, 250.0, 400.0, 400.0));
    $line->SetStartPoint(new Point(350.0, 270.0));
    $line->SetEndPoint(new Point(260.0, 370.0));
    $line->SetStartStyle(LineAnnot::e_Square);
    $line->SetEndStyle(LineAnnot::e_Circle);
    $line->SetColor(new ColorPt(0.3, 0.5, 0.0), 3);
    $line->SetContents("Dashed Captioned");
    $line->SetShowCaption(true);
    $line->SetCaptionPosition(LineAnnot::e_Top);
    $line->SetBorderStyle(new BorderStyle(BorderStyle::e_dashed, 2.0, 0.0, 0.0, array(2.0, 2.0)));
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(347.0, 377.0, 600.0, 600.0));
    $line->SetStartPoint(new Point(385.0, 410.0));
    $line->SetEndPoint(new Point(540.0, 555.0));
    $line->SetStartStyle(LineAnnot::e_Circle);
    $line->SetEndStyle(LineAnnot::e_OpenArrow);
    $line->SetColor(new ColorPt(1.0, 0.0, 0.0), 3);
    $line->SetInteriorColor(new ColorPt(0.0, 1.0, 0.0), 3);
    $line->SetContents("Inline Caption");
    $line->SetShowCaption(true);
    $line->SetCaptionPosition(LineAnnot::e_Inline);
    $line->SetLeaderLineExtensionLength(-4.0);
    $line->SetLeaderLineLength(-12.0);
    $line->SetLeaderLineOffset(2.0);
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(10.0, 400.0, 200.0, 600.0));
    $line->SetStartPoint(new Point(25.0, 426.0));
    $line->SetEndPoint(new Point(180.0, 555.0));
    $line->SetStartStyle(LineAnnot::e_Circle);
    $line->SetEndStyle(LineAnnot::e_Square);
    $line->SetColor(new ColorPt(0.0, 0.0, 1.0), 3);
    $line->SetInteriorColor(new ColorPt(1.0, 0.0, 0.0), 3);
    $line->SetContents("Offset Caption");
    $line->SetShowCaption(true);
    $line->SetCaptionPosition(LineAnnot::e_Top);
    $line->SetTextHOffset(-60);
    $line->SetTextVOffset(10);
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(200.0, 10.0, 400.0, 70.0));
    $line->SetStartPoint(new Point(220.0, 25.0));
    $line->SetEndPoint(new Point(370.0, 60.0));
    $line->SetStartStyle(LineAnnot::e_Butt);
    $line->SetEndStyle(LineAnnot::e_OpenArrow);
    $line->SetColor(new ColorPt(0.0, 0.0, 1.0), 3);
    $line->SetContents("Regular Caption");
    $line->SetShowCaption(true);
    $line->SetCaptionPosition(LineAnnot::e_Top);
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(200.0, 70.0, 400.0, 130.0));
    $line->SetStartPoint(new Point(220.0, 111.0));
    $line->SetEndPoint(new Point(370.0, 78.0));
    $line->SetStartStyle(LineAnnot::e_Circle);
    $line->SetEndStyle(LineAnnot::e_Diamond);
    $line->SetContents("Circle to Diamond");
    $line->SetColor(new ColorPt(0.0, 0.0, 1.0), 3);
    $line->SetInteriorColor(new ColorPt(0.0, 1.0, 0.0), 3);
    $line->SetShowCaption(true);
    $line->SetCaptionPosition(LineAnnot::e_Top);
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(10.0, 100.0, 160.0, 200.0));
    $line->SetStartPoint(new Point(15.0, 110.0));
    $line->SetEndPoint(new Point(150.0, 190.0));
    $line->SetStartStyle(LineAnnot::e_Slash);
    $line->SetEndStyle(LineAnnot::e_ClosedArrow);
    $line->SetContents("Slash to CArrow");
    $line->SetColor(new ColorPt(1.0, 0.0, 0.0), 3);
    $line->SetInteriorColor(new ColorPt(0.0, 1.0, 1.0), 3);
    $line->SetShowCaption(true);
    $line->SetCaptionPosition(LineAnnot::e_Top);
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(270.0, 270.0, 570.0, 433.0));
    $line->SetStartPoint(new Point(300.0, 400.0));
    $line->SetEndPoint(new Point(550.0, 300.0));
    $line->SetStartStyle(LineAnnot::e_RClosedArrow);
    $line->SetEndStyle(LineAnnot::e_ROpenArrow);
    $line->SetContents("ROpen & RClosed arrows");
    $line->SetColor(new ColorPt(0.0, 0.0, 1.0), 3);
    $line->SetInteriorColor(new ColorPt(0.0, 1.0, 0.0), 3);
    $line->SetShowCaption(true);
    $line->SetCaptionPosition(LineAnnot::e_Top);
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(195.0, 395.0, 205.0, 505.0));
    $line->SetStartPoint(new Point(200.0, 400.0));
    $line->SetEndPoint(new Point(200.0, 500.0));
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(55.0, 299.0, 150.0, 301.0));
    $line->SetStartPoint(new Point(55.0, 300.0));
    $line->SetEndPoint(new Point(155.0, 300.0));
    $line->SetStartStyle(LineAnnot::e_Circle);
    $line->SetEndStyle(LineAnnot::e_Circle);
    $line->SetContents("Caption that's longer than its line.");
    $line->SetColor(new ColorPt(1.0, 0.0, 1.0), 3);
    $line->SetInteriorColor(new ColorPt(0.0, 1.0, 0.0), 3);
    $line->SetShowCaption(true);
    $line->SetCaptionPosition(LineAnnot::e_Top);
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $line = LineAnnot::Create($doc->GetSDFDoc(), new Rect(300.0, 200.0, 390.0, 234.0));
    $line->SetStartPoint(new Point(310.0, 210.0));
    $line->SetEndPoint(new Point(380.0, 220.0));
    $line->SetColor(new ColorPt(0.0, 0.0, 0.0), 3);
    $line->RefreshAppearance();
    $page->AnnotPushBack($line);
    $page3 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0));
    $ew->Begin($page3);
    // begin writing to the page
    $ew->End();
    // save changes to the current page
    $doc->PagePushBack($page3);
    $circle = Circle::Create($doc->GetSDFDoc(), new Rect(300.0, 300.0, 390.0, 350.0));
    $circle->SetColor(new ColorPt(0.0, 0.0, 0.0), 3);
    $circle->RefreshAppearance();
    $page3->AnnotPushBack($circle);
    $circle = Circle::Create($doc->GetSDFDoc(), new Rect(100.0, 100.0, 200.0, 200.0));
    $circle->SetColor(new ColorPt(0.0, 1.0, 0.0), 3);
    $circle->SetInteriorColor(new ColorPt(0.0, 0.0, 1.0), 3);
    $circle->SetBorderStyle(new BorderStyle(BorderStyle::e_dashed, 3.0, 0.0, 0.0, array(2.0, 4.0)));
    $circle->SetPadding(2.0);
    $circle->RefreshAppearance();
    $page3->AnnotPushBack($circle);
    $sq = Square::Create($doc->GetSDFDoc(), new Rect(10.0, 200.0, 80.0, 300.0));
    $sq->SetColor(new ColorPt(0.0, 0.0, 0.0), 3);
    $sq->RefreshAppearance();
    $page3->AnnotPushBack($sq);
    $sq = Square::Create($doc->GetSDFDoc(), new Rect(500.0, 200.0, 580.0, 300.0));
    $sq->SetColor(new ColorPt(1.0, 0.0, 0.0), 3);
    $sq->SetInteriorColor(new ColorPt(0.0, 1.0, 1.0), 3);
    $sq->SetBorderStyle(new BorderStyle(BorderStyle::e_dashed, 6.0, 0.0, 0.0, array(4.0, 2.0)));
    $sq->SetPadding(4.0);
    $sq->RefreshAppearance();
    $page3->AnnotPushBack($sq);
    $poly = Polygon::Create($doc->GetSDFDoc(), new Rect(5.0, 500.0, 125.0, 590.0));
    $poly->SetColor(new ColorPt(1.0, 0.0, 0.0), 3);
    $poly->SetInteriorColor(new ColorPt(1.0, 1.0, 0.0), 3);
    $poly->SetVertex(0, new Point(12.0, 510.0));
    $poly->SetVertex(1, new Point(100.0, 510.0));
    $poly->SetVertex(2, new Point(100.0, 555.0));
    $poly->SetVertex(3, new Point(35.0, 544.0));
    $poly->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 4.0, 0.0, 0.0));
    $poly->SetPadding(4.0);
    $poly->RefreshAppearance();
    $page3->AnnotPushBack($poly);
    $poly = PolyLine::Create($doc->GetSDFDoc(), new Rect(400.0, 10.0, 500.0, 90.0));
    $poly->SetColor(new ColorPt(1.0, 0.0, 0.0), 3);
    $poly->SetInteriorColor(new ColorPt(0.0, 1.0, 0.0), 3);
    $poly->SetVertex(0, new Point(405.0, 20.0));
    $poly->SetVertex(1, new Point(440.0, 40.0));
    $poly->SetVertex(2, new Point(410.0, 60.0));
    $poly->SetVertex(3, new Point(470.0, 80.0));
    $poly->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 2.0, 0.0, 0.0));
    $poly->SetPadding(4.0);
    $poly->SetStartStyle(LineAnnot::e_RClosedArrow);
    $poly->SetEndStyle(LineAnnot::e_ClosedArrow);
    $poly->RefreshAppearance();
    $page3->AnnotPushBack($poly);
    $lk = Link::Create($doc->GetSDFDoc(), new Rect(5.0, 5.0, 55.0, 24.0));
    //$lk->SetColor( new ColorPt(0.0,1.0,0.0), 3.0 );
    $lk->RefreshAppearance();
    $page3->AnnotPushBack($lk);
    $page4 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0));
    $ew->Begin($page4);
    // begin writing to the page
    $ew->End();
    // save changes to the current page
    $doc->PagePushBack($page4);
    $ew->Begin($page4);
    $font = Font::Create($doc->GetSDFDoc(), Font::e_helvetica);
    $element = $eb->CreateTextBegin($font, 16.0);
    $element->SetPathFill(true);
    $ew->WriteElement($element);
    $element = $eb->CreateTextRun("Some random text on the page", $font, 16.0);
    $element->SetTextMatrix(1.0, 0.0, 0.0, 1.0, 100.0, 500.0);
    $ew->WriteElement($element);
    $ew->WriteElement($eb->CreateTextEnd());
    $ew->End();
    $hl = HighlightAnnot::Create($doc->GetSDFDoc(), new Rect(100.0, 490.0, 150.0, 515.0));
    $hl->SetColor(new ColorPt(0.0, 1.0, 0.0), 3);
    $hl->RefreshAppearance();
    $page4->AnnotPushBack($hl);
    $sq = Squiggly::Create($doc->GetSDFDoc(), new Rect(100.0, 450.0, 250.0, 600.0));
    //$sq->SetColor( new ColorPt(1.0,0.0,0.0), 3 );
    $sq->SetQuadPoint(0, new QuadPoint(new Point(122.0, 455.0), new Point(240.0, 545.0), new Point(230.0, 595.0), new Point(101.0, 500.0)));
    $sq->RefreshAppearance();
    $page4->AnnotPushBack($sq);
    $cr = Caret::Create($doc->GetSDFDoc(), new Rect(100.0, 40.0, 129.0, 69.0));
    $cr->SetColor(new ColorPt(0.0, 0.0, 1.0), 3);
    $cr->SetSymbol("P");
    $cr->RefreshAppearance();
    $page4->AnnotPushBack($cr);
    $page5 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0));
    $ew->Begin($page5);
    // begin writing to the page
    $ew->End();
    // save changes to the current page
    $doc->PagePushBack($page5);
    global $input_path;
    $fs = FileSpec::Create($doc->GetSDFDoc(), $input_path . "butterfly.png", false);
    $page6 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0));
    $ew->Begin($page6);
    // begin writing to the page
    $ew->End();
    // save changes to the current page
    $doc->PagePushBack($page6);
    for ($ipage = 0; $ipage < 2; ++$ipage) {
        for ($iann = 0; $iann < 100; $iann++) {
            if (!($iann > FileAttachment::e_Tag)) {
                $fa = FileAttachment::Create($doc->GetSDFDoc(), new Rect(50.0 + 50.0 * (double) $iann, 100.0, 70.0 + 50.0 * (double) $iann, 120.0), $fs, $iann);
                if ($ipage) {
                    $fa->SetColor(new ColorPt(1.0, 1.0, 0.0));
                }
                $fa->RefreshAppearance();
                if ($ipage == 0) {
                    $page5->AnnotPushBack($fa);
                } else {
                    $page6->AnnotPushBack($fa);
                }
            }
            if ($iann > Text::e_Note) {
                break;
            }
            $txt = Text::Create($doc->GetSDFDoc(), new Rect(10.0 + (double) $iann * 50.0, 200.0, 30.0 + (double) $iann * 50.0, 220.0));
            $txt->SetIcon($iann);
            $txt->SetContents($txt->GetIconName());
            if ($ipage) {
                $txt->SetColor(new ColorPt(1.0, 1.0, 0.0));
            }
            $txt->RefreshAppearance();
            if ($ipage == 0) {
                $page5->AnnotPushBack($txt);
            } else {
                $page6->AnnotPushBack($txt);
            }
        }
    }
    $txt = Text::Create($doc->GetSDFDoc(), new Rect(10.0, 20.0, 30.0, 40.0));
    $txt->SetIcon("UserIcon");
    $txt->SetContents("User defined icon, unrecognized by appearance generator");
    $txt->SetColor(new ColorPt(0.0, 1.0, 0.0));
    $txt->RefreshAppearance();
    $page6->AnnotPushBack($txt);
    $ink = Ink::Create($doc->GetSDFDoc(), new Rect(100.0, 400.0, 200.0, 550.0));
    $ink->SetColor(new ColorPt(0.0, 0.0, 1.0));
    $ink->SetPoint(1, 3, new Point(220.0, 505.0));
    $ink->SetPoint(1, 0, new Point(100.0, 490.0));
    $ink->SetPoint(0, 1, new Point(120.0, 410.0));
    $ink->SetPoint(0, 0, new Point(100.0, 400.0));
    $ink->SetPoint(1, 2, new Point(180.0, 490.0));
    $ink->SetPoint(1, 1, new Point(140.0, 440.0));
    $ink->SetBorderStyle(new BorderStyle(BorderStyle::e_solid, 3.0, 0.0, 0.0));
    $ink->RefreshAppearance();
    $page6->AnnotPushBack($ink);
    $page7 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0));
    $ew->Begin($page7);
    // begin writing to the page
    $ew->End();
    // save changes to the current page
    $doc->PagePushBack($page7);
    $snd = Sound::Create($doc->GetSDFDoc(), new Rect(100.0, 500.0, 120.0, 520.0));
    $snd->SetColor(new ColorPt(1.0, 1.0, 0.0));
    $snd->SetIcon(Sound::e_Speaker);
    $snd->RefreshAppearance();
    $page7->AnnotPushBack($snd);
    $snd = Sound::Create($doc->GetSDFDoc(), new Rect(200.0, 500.0, 220.0, 520.0));
    $snd->SetColor(new ColorPt(1.0, 1.0, 0.0));
    $snd->SetIcon(Sound::e_Mic);
    $snd->RefreshAppearance();
    $page7->AnnotPushBack($snd);
    $page8 = $doc->PageCreate(new Rect(0.0, 0.0, 600.0, 600.0));
    $ew->Begin($page8);
    // begin writing to the page
    $ew->End();
    // save changes to the current page
    $doc->PagePushBack($page8);
    for ($ipage = 0; $ipage < 2; ++$ipage) {
        $px = 5;
        $py = 520;
        for ($istamp = RubberStamp::e_Approved; $istamp <= RubberStamp::e_Draft; $istamp = $istamp + 1) {
            $st = RubberStamp::Create($doc->GetSDFDoc(), new Rect(1.0, 1.0, 100.0, 100.0));
            $st->SetIcon($istamp);
            $st->SetContents($st->GetIconName());
            $st->SetRect(new Rect((double) $px, (double) $py, (double) $px + 100.0, (double) $py + 25.0));
            $py -= 100;
            if ($py < 0) {
                $py = 520;
                $px += 200;
            }
            if ($ipage == 0) {
                //$page7->AnnotPushBack( $st );
            } else {
                $page8->AnnotPushBack($st);
                $st->RefreshAppearance();
            }
        }
    }
    $st = RubberStamp::Create($doc->GetSDFDoc(), new Rect(400.0, 5.0, 550.0, 45.0));
    $st->SetIcon("UserStamp");
    $st->SetContents("User defined stamp");
    $page8->AnnotPushBack($st);
    $st->RefreshAppearance();
}
Ejemplo n.º 22
0
<?php

// circle.php
require_once "app_autoload.php";
$circle = new Circle(7);
echo "Dimensions: " . $circle->getDimensions() . "<br>";
echo "Perimeter (circumference): " . $circle->getPerimeter() . " (" . $circle->getCircumference() . ")<br>";
echo "Area: " . $circle->getArea() . "<br>";
{
    private $_sideLength = 0;
    public function getSideLength()
    {
        return $this->_sideLength;
    }
    public function setSideLength($length)
    {
        $this->_sideLength = $length;
    }
    public function getArea()
    {
        return pow($this->_sideLength, 2);
    }
}
$myCircle = new Circle();
$myCircle->setColor("red");
$myCircle->fill();
$myCircle->setRadius(4);
echo "<h2>My Circle</h2>";
echo "<p>My circle has a radius of " . $myCircle->getRadius() . ".</p>";
echo "<p>It is " . $myCircle->getColor() . " and it is " . ($myCircle->isFilled() ? "filled" : "hollow") . ".</p>";
echo "<p>The area of my circle is: " . $myCircle->getArea() . ".</p>";
$mySquare = new Square();
$mySquare->setColor("green");
$mySquare->makeHollow();
$mySquare->setSideLength(3);
echo "<h2>My Square</h2>";
echo "<p>My square has a side length of " . $mySquare->getSideLength() . ".</p>";
echo "<p>It is " . $mySquare->getColor() . " and it is " . ($mySquare->isFilled() ? "filled" : "hollow") . ".</p>";
echo "<p>The area of my square is: " . $mySquare->getArea() . ".</p>";
Ejemplo n.º 24
0
}
class Rectangle extends Shape
{
    private $width;
    private $height;
    public function __construct($width, $height)
    {
        $this->width = $width;
        $this->height = $height;
    }
    public function calcArea()
    {
        return $this->width * $this->height;
    }
}
$circ = new Circle(3);
$rect = new Rectangle(3, 4);
// <?= is the shortcut for <?php echo
?>



	<?php 
echo $circ->calcArea();
?>
<br/>
	<?php 
echo $rect->calcArea();
?>
 
{
    private $radius;
    public function __construct($x, $y, $radius)
    {
        parent::__construct($x, $y);
        $this->radius = $radius;
    }
    protected function drawShape()
    {
        return "Рисуем окружность с радиусом {$this->radius}";
    }
}
class Rectangle extends Shape
{
    private $width;
    private $height;
    public function __construct($x, $y, $width, $height)
    {
        parent::__construct($x, $y);
        $this->width = $width;
        $this->height = $height;
    }
    protected function drawShape()
    {
        return "Рисуем прямоугольник с шириной {$this->width} и высотой {$this->height}";
    }
}
$circle = new Circle(0, 0, 50);
$rectangle = new Rectangle(0, 0, 100, 50);
$circle->draw();
$rectangle->draw();
<?php

$success = false;
$errors = array();
require 'includes/initialize.php';
if (!$session->is_logged_in()) {
    array_push($errors, "Not logged in.");
} else {
    if (!isset($_POST['circle_name'])) {
        array_push($errors, "Error 0x01 creating circle.");
    } else {
        $circle = Circle::make($_POST['circle_name'], $session->user_id);
        if ($circle->create()) {
            $success = true;
        }
    }
}
display_success($success, $errors);
Ejemplo n.º 27
0
 public function actionSendGiftApi($item_id, $aid, $img_id = NULL, $is_shake = FALSE)
 {
     $itemList = Util::loadConfig('items');
     $item = $itemList[$item_id];
     if (isset($item)) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $user = User::model()->findByPk($this->usr_id);
             $ex_gold = $user->gold;
             $ex_exp = $user->exp;
             $ex_lv = $user->lv;
             if (!$is_shake) {
                 $items = unserialize($user->items);
                 if (isset($items[$item_id]) && $items[$item_id] > 0) {
                     $items[$item_id]--;
                     $user->items = serialize($items);
                     $user->saveAttributes(array('items'));
                 } else {
                     throw new PException('礼物数量不足');
                 }
             }
             $user->sendGift($is_shake);
             $circle = Circle::model()->findByPk(array('aid' => $aid, 'usr_id' => $this->usr_id));
             if (isset($circle)) {
                 $ex_rank = $circle->rank;
                 $circle->t_contri += $item['rq'];
                 $circle->m_contri += $item['rq'];
                 $circle->w_contri += $item['rq'];
                 $circle->d_contri += $item['rq'];
                 $user->contributionChange($circle);
                 $circle->saveAttributes(array('t_contri', 'm_contri', 'w_contri', 'd_contri'));
             }
             $animal = Animal::model()->findByPk($aid);
             $animal->d_rq += $item['rq'];
             $animal->m_rq += $item['rq'];
             $animal->w_rq += $item['rq'];
             $animal->t_rq += $item['rq'];
             if ($animal->d_rq < 0) {
                 $animal->d_rq = 0;
             }
             if ($animal->m_rq < 0) {
                 $animal->m_rq = 0;
             }
             if ($animal->w_rq < 0) {
                 $animal->w_rq = 0;
             }
             if ($animal->t_rq < 0) {
                 $animal->t_rq = 0;
             }
             $a_items = unserialize($animal->items);
             if (isset($a_items[$item_id])) {
                 $a_items[$item_id]++;
             } else {
                 $a_items[$item_id] = 1;
             }
             $animal->items = serialize($a_items);
             $animal->saveAttributes(array('d_rq', 'm_rq', 'w_rq', 't_rq', 'items'));
             if (isset($img_id)) {
                 $image = Image::model()->findByPk($img_id);
                 $image->gifts++;
                 if (isset($image->senders) && $image->senders != '') {
                     $image->senders = $this->usr_id . ',' . $image->senders;
                 } else {
                     $image->senders = $this->usr_id;
                 }
                 $image->saveAttributes(array('gifts', 'senders'));
             }
             if ($is_shake) {
                 $session = Yii::app()->session;
                 if (isset($session[$aid . '_shake_count'])) {
                     $session[$aid . '_shake_count'] -= 1;
                 } else {
                     $session[$aid . '_shake_count'] = 3;
                 }
             }
             $news = new News();
             $news->aid = $aid;
             $news->type = $item['rq'] >= 0 ? 4 : 7;
             $news->create_time = time();
             $news->content = serialize(array('usr_id' => $user->usr_id, 'u_name' => $user->name, 'rank' => isset($circle) ? $circle->rank : -1, 'item_id' => $item_id, 'rq' => $item['rq']));
             $news->save();
             $transaction->commit();
             $this->echoJsonData(array('exp' => $user->exp - $ex_exp, 'gold' => $user->gold - $ex_gold, 'lv' => $user->lv - $ex_lv, 'rank' => isset($circle) ? $circle->rank - $ex_rank : -1));
         } catch (Exception $e) {
             $transaction->rollback();
             throw $e;
         }
     } else {
         throw new PException('礼物不存在');
     }
 }
Ejemplo n.º 28
0
	<form action="" method="post">
	请输入|圆形|的半径:<br/>
	半径:<input type="text" name="radius" > <br/>
	<input type="submit" name="btn" value="计算">
	</form>
</body>
</html>

<?php 
include 'file_7_extraTraining.php';
class Circle extends Shape
{
    private $radius;
    function __construct($radius)
    {
        $this->radius = $radius;
    }
    function getArea()
    {
        return $this->radius * $this->radius * 3.14;
    }
    function getPerimeter()
    {
        return $this->radius * 2 * 3.14;
    }
}
if (isset($_POST["btn"])) {
    $circle1 = new Circle($_POST["radius"]);
    echo "圆形的周长:" . $circle1->getPerimeter() . "<br/>";
    echo "圆形的面积:" . $circle1->getArea() . "<br/>";
}
<?php

$success = false;
$errors = array();
require 'includes/initialize.php';
if (!$session->is_logged_in()) {
    array_push($errors, "Not logged in.");
} else {
    if (!isset($_POST['circle_id'])) {
        array_push($errors, "Error 0x01 deleting circle.");
    } else {
        $circle = Circle::find_by_id($_POST['circle_id']);
        if ($session->user_id == $circle->user_id) {
            if ($circle->delete()) {
                $success = true;
            }
        }
    }
}
display_success($success, $errors);
<?php

/*АБСТРАКТНЫЕ КЛАССЫ И МЕТОДЫ*/
//Абстрактный метод - это  метод реализация которого отсутствует. После написания функция сразу ставим точку с запятой (abstract function draw();)
//Абстрактный класс- это класс, который содержит хотя бы один абстрактный метод. Имеет два свойства: 1 - создать объект абстрактного класса невозможно; 2 - невозможно воспользоваться абстрактными методами, если они не переопределены в производных классах(классах наследниках)
//Ключевое слово abstract - объявляет класс абстрактным
require_once getenv("DOCUMENT_ROOT") . "/lib/config.php";
require_once "Circle.php";
$shape = new Circle(50, 20, 10);
$shape->moveTo(30, 40);
$shape->draw();