Mac Help Forums


Reply
Thread Tools Display Modes

Fading Paths ???

 
New Member
Join Date: Jun 2007
Posts: 2
 
      4th June 2007
Hello everyone,

i would like to know how to code for this: everytime i click generate i want the previous path's colors to change into a different color.

THANKS



#import "RanWithParameters.h"


@implementation RanWithParameters

- (id)initWithFrame:(NSRect)rect
{
NSLog(@"-------------initWithFrame------------------");
if (self = [super initWithFrame:rect])
{
transform = [[NSAffineTransform alloc] init];
path = [[NSBezierPath alloc] init];
}
return self;
}



- (IBAction)generate:(id)sender
{
NSLog(@"generate");
[self drawRandomLine];
[self setNeedsDisplay:YES];

}



- (void)drawRandomLine
{
int i;
NSPoint p;

//Create a path object
[path setLineWidth:2.0];
p = [self randomPoint:0];
[path moveToPoint: p];

for (i = 0; i <= 10; i++)
{
p = [self randomPoint:i];
[path lineToPoint: p];
}
}



// randomPoint returns a random point inside the view
- (NSPoint)randomPoint:(long)index
{
NSPoint result;
result.y = (random() % 100) -50;
result.x = index + 0;

return result;
}



//Setting scales
- (void)setScale:(NSRect)bounds
{
NSAffineTransformStruct I, unitsToPix;

NSLog(@"setScale");

I.m11 = 1;
I.m12 = 0;
I.m21 = 0;
I.m22 = 1;
I.tX = 0;
I.tY = 0;

[transform setTransformStruct:I];
[transform translateXBy: bounds.origin.x yBy: bounds.origin.y + bounds.size.height/2.0];
[transform scaleXBy: bounds.size.width/10 yBy: bounds.size.height/100];

unitsToPix = [transform transformStruct];

NSLog(@"unitsToPix.m11=%f unitsToPix.m12=%f unitsToPix.m21=%f unitsToPix.m22=%f unitsToPix.tX=%f unitsToPix.tY=%f",
unitsToPix.m11, unitsToPix.m12, unitsToPix.m21, unitsToPix.m22, unitsToPix.tX, unitsToPix.tY);
}


- (void)drawRect:(NSRect)rect
{
NSRect bounds;

NSLog(@"======= drawRect ======");

bounds = [self bounds];

[self setScale:bounds];

//Fill the view with black
[[NSColor blackColor] set];
[NSBezierPath fillRect:bounds];

// Draw the path red
[[NSColor greenColor] set];

[path transformUsingAffineTransform: transform]; // transform path in units to path in pixels
[path stroke]; // draw path in pixels
[transform invert]; // invert transform to go from pixels to units
[path transformUsingAffineTransform: transform]; // transform path in pixels back to path in units
[transform invert]; // invert transform back to take us from units to pixels
}


- (void)dealloc
{
[path release];
[transform release];
[super dealloc];
}



@end
 
Reply With Quote
 
 
 
 
Senior Member
Kaveman's Avatar
Join Date: Nov 2010
Location: Westland, NZ
Posts: 1,360
 
      12th June 2011
If this problem is not solved, please IM me;-)
 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Screen bar fading? Willowrib Mac OS X 1 14th August 2011 05:38 AM
If you want to succeed you should strike out on new paths rather thantravel the worn paths of accepted success. ali khanbaba Apps 0 31st May 2009 04:36 AM
If you want to succeed you should strike out on new paths rather thantravel the worn paths of accepted success. ali khanbaba Apps 0 31st May 2009 04:35 AM
Fading in and out in iMovie '09? H.B. Elkins Apps 1 4th April 2009 07:28 PM
iLamp fading into nothingness Sara Kirk UK Macs 28 24th April 2008 03:10 PM


All times are GMT +1. The time now is 10:58 AM.
Mac-Help.com is an independent website and is not affiliated with Apple Inc.


Welcome!
Welcome to the Mac Help Forums
 


Latest Threads
New book about Steve Jobs << take part in it!
Arjan (1 Hour Ago, 09:37 AM)

Help! Stupid computer is automatically logging me out
Elizaboo (12 Hours Ago, 10:41 PM)

URGENT Help. Crazy talk Mac!
Joeker (13 Hours Ago, 09:42 PM)

PDF Document
yura (22 Hours Ago, 12:13 PM)

Difficulties with internet speed (nothing to do with connection)
sammethh (1 Day Ago, 06:36 AM)

 


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51