Skip to content

Instantly share code, notes, and snippets.

@jtubert
Last active December 24, 2015 04:39
Show Gist options
  • Save jtubert/6745160 to your computer and use it in GitHub Desktop.
Save jtubert/6745160 to your computer and use it in GitHub Desktop.
Sketchio presentation - Mirroring lines
-(void) mirroringX1:(float)x1 y1:(float)y1 x2:(float)x2 y2:(float)y2{
float mirrorNumber = totalLines;
float deltaAngle = 360 / mirrorNumber;
float deltaAngleRadian = [self degreesToRadian:deltaAngle];
float centerX = self.frame.size.width / 2;
float centerY = self.frame.size.height / 2;
float distance1 = [self distX1:x1 y1:y1 x2:centerX y2:centerY];
float distance2 = [self distX1:x2 y1:y2 x2:centerX y2:centerY];
float deltaY1 = y1-centerY;
float deltaX1 = x1-centerX;
float deltaY2 = y2-centerY;
float deltaX2 = x2-centerX;
float angle1 = atan2(deltaY1, deltaX1);
float angle2 = atan2(deltaY2, deltaX2);
for(int i = 0; i < mirrorNumber;i++){
float newX1 = centerX + distance1 * sin(angle1 + (i * deltaAngleRadian));
float newY1 = centerY - distance1 * cos(angle1 + (i * deltaAngleRadian));
float newX2 = centerX + distance2 * sin(angle2 + (i * deltaAngleRadian));
float newY2 = centerY - distance2 * cos(angle2 + (i * deltaAngleRadian));
[self lineX1:newX1 y1:newY1 x2:newX2 y2:newY2];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment