• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Transform not quite right
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Transform not quite right


  • Subject: Transform not quite right
  • From: David Arnold <email@hidden>
  • Date: Sat, 30 Jun 2007 00:49:57 -0700

All,

I am very new to cocoa and I am trying to map my user space to an NSView object. I am almost success, but for some reason, I am not getting the translation upward that I need so the the entire sine curve will fit in the window. I feel I am missing something fundamental. Can anyone help?


// // DavidView.m // David // // Created by David Arnold on 6/29/07. // Copyright 2007 David Arnold. All rights reserved. //

#import "DavidView.h"


@implementation DavidView

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
		//code here
    }
    return self;
}

- (void)drawRect:(NSRect)rect {

	float xmin = 0.0;
	float xmax = 2*pi;
	float ymin = -2.0;
	float ymax = 2.0;
	float numPoints = 200;

	float x = xmin;
	float dx = (xmax-xmin)/numPoints;
	float y;

	[[NSColor grayColor] set];
	NSRectFill(rect);

NSAffineTransform *xForm = [NSAffineTransform transform];
[xForm translateXBy:-xmin yBy:-ymin];
[xForm scaleXBy:(rect.size.width/(xmax-xmin)) yBy:(rect.size.height/ (ymax-ymin))];
// [xForm translateXBy:rect.origin.x yBy:rect.origin.y];


	NSBezierPath *path = [NSBezierPath bezierPath];
	[path moveToPoint:NSMakePoint(x,[self f:x])];
	while (x<=xmax) {
		y=[self f:x];
		[path lineToPoint:NSMakePoint(x,y)];
		x+=dx;
	}
	x=xmax;
	y=[self f:x];
	[path lineToPoint:NSMakePoint(x,y)];

	[[NSColor whiteColor] set];
	[path setLineWidth:1];
	[path transformUsingAffineTransform:xForm];
	[path stroke];

}

- (float)f:(float)x
{
	return sin(x);
}

@end

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Transform not quite right
      • From: "R. Matthew Emerson" <email@hidden>
  • Prev by Date: NSTableView update triggered from a thread
  • Next by Date: ScreenSaver Shell?
  • Previous by thread: NSTableView update triggered from a thread
  • Next by thread: Re: Transform not quite right
  • Index(es):
    • Date
    • Thread