Advertisement
Guest User

Untitled

a guest
Jul 8th, 2020
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. bool Shape::init()
  2. {
  3. if (!DrawNode::init())
  4. {
  5. return false;
  6. }
  7.  
  8. Vec2 verts[364];
  9. verts[0] = Vec2(-width / 2, -height / 2 + cornerRadius);
  10. for (int i = 0; i < 90; i++)
  11. {
  12. verts[1+i] = Vec2(verts[0].x + cornerRadius + cornerRadius * cos((i + 180) * M_PI / 180), verts[0].y + cornerRadius * sin((i + 180) * M_PI / 180));
  13. }
  14. verts[91] = Vec2(width / 2 - cornerRadius, -height / 2);
  15. for (int i = 0; i < 90; i++)
  16. {
  17. verts[92+i] = Vec2(verts[91].x + cornerRadius * cos((i + 270) * M_PI / 180), verts[91].y + cornerRadius + cornerRadius * sin((i + 270) * M_PI / 180));
  18. }
  19. verts[182] = Vec2(width / 2, height / 2 - cornerRadius);
  20. for (int i = 0; i < 90; i++)
  21. {
  22. verts[183+i] = Vec2(verts[182].x - cornerRadius + cornerRadius * cos(i * M_PI / 180), verts[182].y + cornerRadius * sin(i * M_PI / 180));
  23. }
  24. verts[273] = Vec2(-width / 2 + cornerRadius, height / 2);
  25. for (int i = 0; i < 90; i++)
  26. {
  27. verts[274+i] = Vec2(verts[273].x + cornerRadius * cos((i + 90) * M_PI / 180), verts[273].y - cornerRadius + cornerRadius * sin((i + 90) * M_PI / 180));
  28. }
  29.  
  30. this->drawPolygon(verts, 364, Color4F(color), borderWidth / 2, Color4F(borderColor));
  31. this->setContentSize(Size(width, height));
  32.  
  33. return true;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement