I started adding on to a program I use that will convert a bunch of stills images in to an mp4 video file.
i have one large NSImage that is 5120 x 720. At each frame I adjust the NSRect x.origin to slide the image a little. The image needs to move 1280 pixels over 30 frames. By just dividing these values I get an x.origin value 42.666.... I am trying to accelerate and decelerate the image over 30 frames? Dividing them gives me a constant speed, I am looking to ramp up and then down the velocity over time.
I did a google search on acceleration and get lots of mathematical equations but I am at a loss for converting this to code? I have Time and Distance but can't seem to get figure out the multiplier?
Here is the code so far, not that it really makes a difference to the question.
i have one large NSImage that is 5120 x 720. At each frame I adjust the NSRect x.origin to slide the image a little. The image needs to move 1280 pixels over 30 frames. By just dividing these values I get an x.origin value 42.666.... I am trying to accelerate and decelerate the image over 30 frames? Dividing them gives me a constant speed, I am looking to ramp up and then down the velocity over time.
I did a google search on acceleration and get lots of mathematical equations but I am at a loss for converting this to code? I have Time and Distance but can't seem to get figure out the multiplier?
Here is the code so far, not that it really makes a difference to the question.
Code:
#import "FramesGenerator.h"
@implementation FramesGenerator
@synthesize importImage, frameNumber;
-(void)startProcess{
frameSlideSpeed = 42.666;
if (!framesArray) {
framesArray = [[NSMutableArray alloc]init];
}
for (int i = 0; i < totalFrames; i++) {
[self createFrame];
}
}
-(void)createFrame{
NSImage *toSaveImage = [[NSImage alloc] initWithSize:CGSizeMake(1280, 720)]; // image to save after created.
[toSaveImage lockFocus]; //prep for writing to layer
[importImage drawInRect:NSMakeRect((frameSlideSpeed * frameNumber) * -1, 0, 1280 * 4, 720) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
[toSaveImage unlockFocus];
frameNumber++; // starts with 1
[framesArray addObject:toSaveImage];
}
@end