Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

neoserver

macrumors 6502
Original poster
Apr 24, 2003
335
0
Here's the background:

I want to be able to have an array of points and then draw line segments between these points starting at (0,0).

So what I do is add points to the array, and then send a setNeedsDisplay:YES to my custom View.

In the drawRect: function, I create a NSBezierPath and loop through the NSMutableArray and by using lineToPoint, I am able to create the effect I want.

HOWEVER, after about 3 Points, I get a line connecting the last point drawn to the origin (NOT WANTED).

This is my first time working with NSBezierPaths, So I'm sure theres just something I've Overlooked.

I've also attached the project I'm using.

Any Ideas? Thanks in Advance :)
 

Attachments

  • CoreGraphicsTest.zip
    58.1 KB · Views: 121
  • Picture 4 copy.png
    Picture 4 copy.png
    48.4 KB · Views: 125

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Change the body of your loop to this:
Code:
lastpoint = [[dataPoints objectAtIndex:i] pointValue];  
if (i == 0)
    [apath moveToPoint:lastpoint];
else
    [apath lineToPoint:lastpoint];

You don't need to moveToPoint: each time. The path's current point is set to the point passed to lineToPoint:
 

neoserver

macrumors 6502
Original poster
Apr 24, 2003
335
0
Change the body of your loop to this:
Code:
lastpoint = [[dataPoints objectAtIndex:i] pointValue];  
if (i == 0)
    [apath moveToPoint:lastpoint];
else
    [apath lineToPoint:lastpoint];

You don't need to moveToPoint: each time. The path's current point is set to the point passed to lineToPoint:

THANK YOU! That was the ticket!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.