This is PolyFrogViewPart.m in view mode; [Download] [Up]
#import "PolyFrogViewPart.h"
#import <appkit/NXImage.h>
#import <appkit/Window.h>
#import <dpsclient/wraps.h>
#import <libc.h>
#import <math.h>
@implementation PolyFrogView
- commandKey
{
bigMode = !bigMode;
return self;
}
- alternateKey
{
eraseTrails = !eraseTrails;
return self;
}
- initFrame:(NXRect *)frameRect
{
register int jkl;
eraseTrails=NO;
// about the 3 -- don''t ask, it looks good.
x1=(float *)malloc(sizeof(float) * (NUMLINES +3));
yc1=(float *)malloc(sizeof(float) * (NUMLINES +3));
t1=(float *)malloc(sizeof(float) * (NUMLINES +3));
t2=(float *)malloc(sizeof(float) * (NUMLINES +3));
t3=(float *)malloc(sizeof(float) * (NUMLINES +3));
[super initFrame:frameRect];
for(jkl=0;jkl<NUMLINES;jkl++){
x1[jkl]=midx;
yc1[jkl]=midy;
}
// line per is the percentage back that erase steps
lper=NUMLINES-5;
return self;
}
- oneStep
{
float mx, my;
pp=p; p=n;
n=(n+1)%(NUMLINES-1);
erasepp=erasep; erasep=erase;
erase=(n-lper); if(erase<0) erase+=(NUMLINES-1);
PScurrentmouse(winNum, &mx, &my);
if (bigMode){
xi=((mx-midx)/urx)*150;
yi=((my-midy)/ury)*150;
} else {
xis=((mx-midx)/urx)*3;
yis=((my-midy)/ury)*3;
}
if((count++>500) && (((mx != oldx) && (my != oldy)) || (count>30000))){
count=0;
PSsetgray(0.0);
NXRectFill(&bounds);
}
oldx=mx; oldy=my;
t1[n]=t1[p]+0.2*(xi+xis); if(t1[n]>(2*M_PI)) t1[n]-=(2*M_PI);
t2[n]=t2[p]+0.2*(yi+yis); if(t2[n]>(2*M_PI)) t2[n]-=(2*M_PI);
t3[n]=t3[p]+0.01; if(t3[n]>(2*M_PI)) t3[n]-=(2*M_PI);
x1[n]=(cos(t1[n])*s1) + (cos(t2[n])*s3) + midx;
yc1[n]=(sin(t1[n])*s2) + (sin(t2[n])*s4) + midy;
if (eraseTrails){
PSsetrgbcolor(0.0,0.0,0.0);
PSnewpath();
PSmoveto(x1[erasepp], yc1[erasepp]);
PSlineto(x1[erasep], yc1[erasep]);
PSlineto(x1[erase], yc1[erase]);
PSclosepath();
PSstroke();
}
PSsetrgbcolor(1.0-(cos(t1[n])+1.0)/2.0,
1.0-(cos(t2[n])+1.0)/2.0,
1.0-(cos(t3[n]*1.5)+1.0)/2.0);
PSnewpath();
PSmoveto(x1[pp], yc1[pp]);
PSlineto(x1[p], yc1[p]);
PSlineto(x1[n], yc1[n]);
PSclosepath();
PSstroke();
return self;
}
@end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.