Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Square.m
- // Assignment2Template
- //
- // Created by tthang on 2/11/16.
- // Copyright © 2016 CMPE161. All rights reserved.
- //
- #import <Foundation/Foundation.h>
- #import "Square.h"
- #import "Shape2D.h"
- @implementation Square
- -(id)init{
- self = [super init];
- if(self){
- _firstPoint.x = 0.0f;
- _firstPoint.y = 0.0f;
- _secondPoint.x = 0.0f;
- _secondPoint.y = 0.0f;
- _thirdPoint.x = 0.0f;
- _thirdPoint.y = 0.0f;
- _fourthPoint.x = 0.0f;
- _fourthPoint.y = 0.0f;
- _squareSize = 50.0f;
- }
- return self;
- }
- - (id)initWithSquareCGPoint : (CGPoint)Point1 {
- self = [super init];
- if(self){
- _firstPoint.x = Point1.x;
- _firstPoint.y = Point1.y;
- _secondPoint.x = Point1.x;
- _secondPoint.y = Point1.y + 50.0f;
- _thirdPoint.x = Point1.x +50.0f;
- _thirdPoint.y = Point1.y;
- _fourthPoint.x = Point1.x + 50.0f;
- _fourthPoint.y = Point1.y +50.0f;
- _squareSize = 50.0f;
- }
- return self;
- }
- - (void)drawSquare : (CGContextRef)context : (CGPoint)mappingConstant{
- CGPoint sPoint;
- sPoint.x = _firstPoint.x*mappingConstant.x;
- sPoint.y = _firstPoint.y*mappingConstant.y;
- CGPoint sPoint2;
- sPoint2.x = _secondPoint.x*mappingConstant.x;
- sPoint2.y = _secondPoint.y*mappingConstant.y;
- CGPoint sPoint3;
- sPoint3.x = _thirdPoint.x*mappingConstant.x;
- sPoint3.y = _thirdPoint.x*mappingConstant.y;
- CGPoint sPoint4;
- sPoint4.x = _fourthPoint.x*mappingConstant.x;
- sPoint4.y = _fourthPoint.y*mappingConstant.y;
- CGContextBeginPath(context);
- CGContextMoveToPoint(context, sPoint.y , sPoint.x);
- CGContextAddLineToPoint(context, sPoint2.y, sPoint2.x);
- CGContextAddLineToPoint(context, sPoint3.y, sPoint3.x);
- CGContextAddLineToPoint(context, sPoint4.y, sPoint4.x);
- CGContextStrokePath(context);
- // CGRect square = CGRectMake(sPoint.y, sPoint.x, _squareSize, _squareSize);
- // CGContextSetRGBStrokeColor(context, self.red, self.green, self.blue, self.alpha);
- // CGContextSetRGBFillColor(context, self.red, self.green, self.blue, self.alpha);
- // CGContextSetLineWidth(context, 0.5);
- // CGContextFillRect(context, square);
- //
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement