text: #include "HelloWorldScene.h"
  
  #include <iostream>
  
  USING_NS_CC;
  
  class VisibleRect
  {
  public:
      static cocos2d::Rect getVisibleRect();
  
      static cocos2d::Vec2 left();
      static cocos2d::Vec2 right();
      static cocos2d::Vec2 top();
      static cocos2d::Vec2 bottom();
      static cocos2d::Vec2 center();
      static cocos2d::Vec2 leftTop();
      static cocos2d::Vec2 rightTop();
      static cocos2d::Vec2 leftBottom();
      static cocos2d::Vec2 rightBottom();
  private:
      static void lazyInit();
      static cocos2d::Rect s_visibleRect;
  };
  
  
  
  
  
  
  
  
  
  
  
  Rect VisibleRect::s_visibleRect;
  
  void VisibleRect::lazyInit()
  {
      // no lazy init
      // Useful if we change the resolution in runtime
      s_visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect();
  }
  
  Rect VisibleRect::getVisibleRect()
  {
      lazyInit();
      return s_visibleRect;
  }
  
  Vec2 VisibleRect::left()
  {
      lazyInit();
      return Vec2(s_visibleRect.origin.x, s_visibleRect.origin.y + s_visibleRect.size.height / 2);
  }
  
  Vec2 VisibleRect::right()
  {
      lazyInit();
      return Vec2(s_visibleRect.origin.x + s_visibleRect.size.width, s_visibleRect.origin.y + s_visibleRect.size.height / 2);
  }
  
  Vec2 VisibleRect::top()
  {
      lazyInit();
      return Vec2(s_visibleRect.origin.x + s_visibleRect.size.width / 2, s_visibleRect.origin.y + s_visibleRect.size.height);
  }
  
  Vec2 VisibleRect::bottom()
  {
      lazyInit();
      return Vec2(s_visibleRect.origin.x + s_visibleRect.size.width / 2, s_visibleRect.origin.y);
  }
  
  Vec2 VisibleRect::center()
  {
      lazyInit();
      return Vec2(s_visibleRect.origin.x + s_visibleRect.size.width / 2, s_visibleRect.origin.y + s_visibleRect.size.height / 2);
  }
  
  Vec2 VisibleRect::leftTop()
  {
      lazyInit();
      return Vec2(s_visibleRect.origin.x, s_visibleRect.origin.y + s_visibleRect.size.height);
  }
  
  Vec2 VisibleRect::rightTop()
  {
      lazyInit();
      return Vec2(s_visibleRect.origin.x + s_visibleRect.size.width, s_visibleRect.origin.y + s_visibleRect.size.height);
  }
  
  Vec2 VisibleRect::leftBottom()
  {
      lazyInit();
      return s_visibleRect.origin;
  }
  
  Vec2 VisibleRect::rightBottom()
  {
      lazyInit();
      return Vec2(s_visibleRect.origin.x + s_visibleRect.size.width, s_visibleRect.origin.y);
  }
  
  Scene* HelloWorld::createScene()
  {
      std::cout << __FUNCTION__ << std::endl;
      // 'scene' is an autorelease object
      auto scene = Scene::create();
  
      // 'layer' is an autorelease object
      auto layer = HelloWorld::create();
  
      // add layer as a child to scene
      scene->addChild(layer);
  
      // return the scene
      return scene;
  }
  
  // on "init" you need to initialize your instance
  
  bool HelloWorld::init()
  {
      std::cout << __FUNCTION__ << std::endl;
      //////////////////////////////
      // 1. super init first
      if (!Layer::init())
      {
          return false;
      }
  
      Size visibleSize = Director::getInstance()->getVisibleSize();
      Vec2 origin = Director::getInstance()->getVisibleOrigin();
  
      std::cout << "origin: " << origin.x << " , " << origin.y << std::endl;
      std::cout << "visibleSize: " << visibleSize.width << " , " << visibleSize.height << std::endl;
  
      /////////////////////////////
      // 2. add a menu item with "X" image, which is clicked to quit the program
      //    you may modify it.
  
      // add a "close" icon to exit the progress. it's an autorelease object
      auto closeItem = MenuItemImage::create(
              "CloseNormal.png",
              "CloseSelected.png",
              CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
  
      closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width / 2,
              origin.y + closeItem->getContentSize().height / 2));
  
      // create menu, it's an autorelease object
      auto menu = Menu::create(closeItem, NULL);
      menu->setPosition(Vec2::ZERO);
      this->addChild(menu, 1);
  
      /////////////////////////////
      // 3. add your codes below...
  
      // add a label shows "Hello World"
      // create and initialize a label
  
      //     auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24);
      // 	if(nullptr != label)
      // 	{
      //     
      //     // position the label on the center of the screen
      //     //label->setPosition(Vec2(origin.x + visibleSize.width/2,  origin.y + visibleSize.height - label->getContentSize().height));
      // 
      //     // add the label as a child to this layer
      //     this->addChild(label, 1);
      // 	}else
      // 	{
      // 		std::cout << "LABLE NULO!" << std::endl;
      // 	}
  
      // add "HelloWorld" splash screen"
      auto sprite = Sprite::create("HelloWorld.png");
      if (nullptr == sprite)
      {
          std::cout << "SPRITE NULO!" << std::endl;
      } else
      {
          // position the sprite on the center of the screen
          sprite->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));
  
  
  
  
          for (auto i = 0; i < 60; i = i + 6)
          {
              circles[i] = Sprite::create("c1.png");
              circles[i + 1] = Sprite::create("c2.png");
              circles[i + 2] = Sprite::create("c3.png");
              circles[i + 3] = Sprite::create("c4.png");
              circles[i + 4] = Sprite::create("c5.png");
              circles[i + 5] = Sprite::create("c6.png");
          }
  
  
  
  
  
          for (auto i = 0; i < steps; i++)
          {
  
              float scale = (-1.76f * i + 56.4f) / steps;
              mScales[i] = scale;
              circles[i]->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));
              circles[i]->setScale(scale);
              this->addChild(circles[i]);
          }
  
  
  
  
  
  
  
          // add the sprite as a child to this layer
          //this->addChild(sprite, 0);
          mTime = 0;
          mCurrentStep = 0;
  
      }
      scheduleUpdate();
  
      auto s = Director::getInstance()->getWinSize();
  
      auto draw = DrawNode::create();
      addChild(draw, 10);
  
      draw->drawPoint(Vec2(s.width / 2 - 120, s.height / 2 - 120), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
  
      draw->drawPoint(Vec2(s.width / 2 + 120, s.height / 2 + 120), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
  
      // draw 4 small points
      Vec2 position[] = {Vec2(60, 60), Vec2(70, 70), Vec2(60, 70), Vec2(70, 60)};
      draw->drawPoints(position, 4, 5, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
  
      // draw a line
      draw->drawLine(Vec2(0, 0), Vec2(s.width, s.height), Color4F(1.0, 0.0, 0.0, 0.5));
  
      // draw a rectangle
      draw->drawRect(Vec2(23, 23), Vec2(7, 7), Color4F(1, 1, 0, 1));
  
      draw->drawRect(Vec2(15, 30), Vec2(30, 15), Vec2(15, 0), Vec2(0, 15), Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
  
      // draw a circle
      draw->drawCircle(VisibleRect::center() + Vec2(140, 0), 100, CC_DEGREES_TO_RADIANS(90), 50, true, 1.0f, 2.0f, Color4F(1.0, 0.0, 0.0, 0.5));
  
      draw->drawCircle(VisibleRect::center() - Vec2(140, 0), 50, CC_DEGREES_TO_RADIANS(90), 30, false, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
  
      // Draw some beziers
      draw->drawQuadBezier(Vec2(s.width - 150, s.height - 150), Vec2(s.width - 70, s.height - 10), Vec2(s.width - 10, s.height - 10), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
  
      draw->drawQuadBezier(Vec2(0, s.height), Vec2(s.width / 2, s.height / 2), Vec2(s.width, s.height), 50, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
  
      draw->drawCubicBezier(VisibleRect::center(), Vec2(VisibleRect::center().x + 30, VisibleRect::center().y + 50), Vec2(VisibleRect::center().x + 60, VisibleRect::center().y - 50), VisibleRect::right(), 100, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
  
      draw->drawCubicBezier(Vec2(s.width - 250, 40), Vec2(s.width - 70, 100), Vec2(s.width - 30, 250), Vec2(s.width - 10, s.height - 50), 10, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
  
      auto array = PointArray::create(20);
      array->addControlPoint(Vec2(0, 0));
      array->addControlPoint(Vec2(80, 80));
      array->addControlPoint(Vec2(s.width - 80, 80));
      array->addControlPoint(Vec2(s.width - 80, s.height - 80));
      array->addControlPoint(Vec2(80, s.height - 80));
      array->addControlPoint(Vec2(80, 80));
      array->addControlPoint(Vec2(s.width / 2, s.height / 2));
      draw->drawCardinalSpline(array, 0.5, 50, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
  
      auto array2 = PointArray::create(20);
      array2->addControlPoint(Vec2(s.width / 2, 30));
      array2->addControlPoint(Vec2(s.width - 80, 30));
      array2->addControlPoint(Vec2(s.width - 80, s.height - 80));
      array2->addControlPoint(Vec2(s.width / 2, s.height - 80));
      array2->addControlPoint(Vec2(s.width / 2, 30));
      draw->drawCatmullRom(array2, 50, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
  
      // open random color poly
      Vec2 vertices[] = {Vec2(0, 0), Vec2(50, 50), Vec2(100, 50), Vec2(100, 100), Vec2(50, 100)};
      draw->drawPoly(vertices, 5, false, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
  
      // closed random color poly
      Vec2 vertices2[] = {Vec2(30, 130), Vec2(30, 230), Vec2(50, 200)};
      draw->drawPoly(vertices2, 3, true, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
  
      // Draw 10 circles
      for (int i = 0; i < 10; i++)
      {
          draw->drawDot(Vec2(s.width / 2, s.height / 2), 10 * (10 - i), Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
      }
  
      // Draw polygons
      Vec2 points[] = {Vec2(s.height / 4, 0), Vec2(s.width, s.height / 5), Vec2(s.width / 3 * 2, s.height)};
      draw->drawPolygon(points, sizeof (points) / sizeof (points[0]), Color4F(1, 0, 0, 0.5), 4, Color4F(0, 0, 1, 0.5));
  
      // star poly (triggers buggs)
      {
          const float o = 80;
          const float w = 20;
          const float h = 50;
          Vec2 star[] = {
              Vec2(o + w, o - h), Vec2(o + w * 2, o), // lower spike
              Vec2(o + w * 2 + h, o + w), Vec2(o + w * 2, o + w * 2), // right spike
              //              {o +w, o+w*2+h}, {o,o+w*2},                 // top spike
              //              {o -h, o+w}, {o,o},                         // left spike
          };
  
          draw->drawPolygon(star, sizeof (star) / sizeof (star[0]), Color4F(1, 0, 0, 0.5), 1, Color4F(0, 0, 1, 1));
      }
  
      // star poly (doesn't trigger bug... order is important un tesselation is supported.
      {
          const float o = 180;
          const float w = 20;
          const float h = 50;
          Vec2 star[] = {
              Vec2(o, o), Vec2(o + w, o - h), Vec2(o + w * 2, o), // lower spike
              Vec2(o + w * 2 + h, o + w), Vec2(o + w * 2, o + w * 2), // right spike
              Vec2(o + w, o + w * 2 + h), Vec2(o, o + w * 2), // top spike
              Vec2(o - h, o + w), // left spike
          };
  
          draw->drawPolygon(star, sizeof (star) / sizeof (star[0]), Color4F(1, 0, 0, 0.5), 1, Color4F(0, 0, 1, 1));
      }
  
      //draw a solid polygon
      Vec2 vertices3[] = {Vec2(60, 160), Vec2(70, 190), Vec2(100, 190), Vec2(90, 160)};
      draw->drawSolidPoly(vertices3, 4, Color4F(1, 1, 0, 1));
  
      //draw a solid rectangle
      draw->drawSolidRect(Vec2(10, 10), Vec2(20, 20), Color4F(1, 1, 0, 1));
  
      //draw a solid circle
      draw->drawSolidCircle(VisibleRect::center() + Vec2(140, 0), 40, CC_DEGREES_TO_RADIANS(90), 50, 2.0f, 2.0f, Color4F(0.0, 1.0, 0.0, 1.0));
  
      // Draw segment
      draw->drawSegment(Vec2(20, s.height), Vec2(20, s.height / 2), 10, Color4F(0, 1, 0, 1));
  
      draw->drawSegment(Vec2(10, s.height / 2), Vec2(s.width / 2, s.height / 2), 40, Color4F(1, 0, 1, 0.5));
  
      // Draw triangle
      draw->drawTriangle(Vec2(10, 10), Vec2(70, 30), Vec2(100, 140), Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 0.5));
  
      for (int i = 0; i < 100; i++)
      {
          draw->drawPoint(Vec2(i * 7, 5), (float) i / 5 + 1, Color4F(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), 1));
      }
  
      auto draw1 = DrawNode::create();
      this->addChild(draw1, 10);
      draw1->setLineWidth(4);
      draw1->drawLine(Vec2(0, s.height), Vec2(s.width, s.height - 20), Color4F::YELLOW);
      draw1->drawLine(Vec2(0, 0), Vec2(s.width, s.height - 20), Color4F::YELLOW);
  
      return true;
  }
  
  void HelloWorld::update(float delta)
  {
  
      mTime += delta;
  
  
      if (mTime >= 0)
      {
  
          printf("Running %f\n", mTime);
  
          mCurrentStep++;
          if (mCurrentStep > steps)
          {
              mCurrentStep = 0;
          }
  
  
  
          for (auto i = steps - 1; i != 0; i--)
          {
              float scale = (-1.76f * (i + mCurrentStep) + 56.4f) / steps;
              if (circles[i] != nullptr) circles[i]->setScale(scale);
  
          }
  
  
  
  
  
  
          mTime = 0;
      }
  
  
  
  }
  
  void HelloWorld::menuCloseCallback(Ref* pSender)
  {
      Director::getInstance()->end();
  
  #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
      exit(0);
  #endif
  }
  