Advertisement
Guest User

43rer

a guest
Feb 12th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. //
  2. // Square.m
  3. // Assignment2Template
  4. //
  5. // Created by tthang on 2/11/16.
  6. // Copyright © 2016 CMPE161. All rights reserved.
  7. //
  8.  
  9. #import <Foundation/Foundation.h>
  10. #import "Square.h"
  11. #import "Shape2D.h"
  12.  
  13. @implementation Square
  14.  
  15.  
  16. -(id)init{
  17. self = [super init];
  18.  
  19. if(self){
  20. _firstPoint.x = 0.0f;
  21. _firstPoint.y = 0.0f;
  22. _secondPoint.x = 0.0f;
  23. _secondPoint.y = 0.0f;
  24. _thirdPoint.x = 0.0f;
  25. _thirdPoint.y = 0.0f;
  26. _fourthPoint.x = 0.0f;
  27. _fourthPoint.y = 0.0f;
  28.  
  29. _squareSize = 50.0f;
  30.  
  31. }
  32. return self;
  33. }
  34.  
  35. - (id)initWithSquareCGPoint : (CGPoint)Point1 {
  36. self = [super init];
  37.  
  38. if(self){
  39. _firstPoint.x = Point1.x;
  40. _firstPoint.y = Point1.y;
  41. _secondPoint.x = Point1.x;
  42. _secondPoint.y = Point1.y + 50.0f;
  43. _thirdPoint.x = Point1.x +50.0f;
  44. _thirdPoint.y = Point1.y;
  45. _fourthPoint.x = Point1.x + 50.0f;
  46. _fourthPoint.y = Point1.y +50.0f;
  47.  
  48. _squareSize = 50.0f;
  49.  
  50.  
  51.  
  52. }
  53.  
  54. return self;
  55. }
  56.  
  57.  
  58. - (void)drawSquare : (CGContextRef)context : (CGPoint)mappingConstant{
  59.  
  60. CGPoint sPoint;
  61. sPoint.x = _firstPoint.x*mappingConstant.x;
  62. sPoint.y = _firstPoint.y*mappingConstant.y;
  63.  
  64. CGPoint sPoint2;
  65. sPoint2.x = _secondPoint.x*mappingConstant.x;
  66. sPoint2.y = _secondPoint.y*mappingConstant.y;
  67.  
  68. CGPoint sPoint3;
  69. sPoint3.x = _thirdPoint.x*mappingConstant.x;
  70. sPoint3.y = _thirdPoint.x*mappingConstant.y;
  71.  
  72. CGPoint sPoint4;
  73. sPoint4.x = _fourthPoint.x*mappingConstant.x;
  74. sPoint4.y = _fourthPoint.y*mappingConstant.y;
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. CGContextBeginPath(context);
  82. CGContextMoveToPoint(context, sPoint.y , sPoint.x);
  83. CGContextAddLineToPoint(context, sPoint2.y, sPoint2.x);
  84. CGContextAddLineToPoint(context, sPoint3.y, sPoint3.x);
  85. CGContextAddLineToPoint(context, sPoint4.y, sPoint4.x);
  86. CGContextStrokePath(context);
  87.  
  88. // CGRect square = CGRectMake(sPoint.y, sPoint.x, _squareSize, _squareSize);
  89. // CGContextSetRGBStrokeColor(context, self.red, self.green, self.blue, self.alpha);
  90. // CGContextSetRGBFillColor(context, self.red, self.green, self.blue, self.alpha);
  91. // CGContextSetLineWidth(context, 0.5);
  92. // CGContextFillRect(context, square);
  93. //
  94.  
  95. }
  96.  
  97.  
  98. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement