void paint_square(Stimulus *st, Substim *sst, int mode) { Locator *pos = &sst->pos; int i,ci,w,h,ncycles; short *p,*q,*end,vx,vy,*vpx,*vpy,*vpoy,*vpox; short x[2],z[2],*xc,*yc,c; float offcolor[3],vcolor[3],*rc,*cc; float angle, oldplaid; double val,cval; if(sst->ptr->plaid_angle < -0.1) val = (double)(st->background) * (1+ pos->contrast_amp); else val = (double)(st->background) * (1+ pos->contrast); if(st->background < 0.01 && pos->contrast > 0) val = pos->contrast; vcolor[0] = vcolor[1] = vcolor[2] = dogamma(val); if(sst->ptr->plaid_angle < -0.1) val = (double)(st->background) * (1- pos->contrast_amp); else val = (double)(st->background) * (1- pos->contrast); if(st->background < 0.01 && pos->contrast < 0) val = -pos->contrast; offcolor[0] = offcolor[1] = offcolor[2] = dogamma(val); glPushMatrix(); glTranslatef((pos->xy[0]),pos->xy[1],0); angle = (pos->angle+sst->ptr->plaid_angle/2) * 180/M_PI; glRotatef(angle,0.0,0.0,1.0); if(mode == LEFTMODE) { rc = cc = &vcolor[0]; } else if(mode == RIGHTMODE) { cc = &vcolor[1]; rc = &vcolor[2]; } val = pos->phase; while(val > (2 * M_PI)) val -= (M_PI * 2); /* * for ss, pos->f determines the width of the square, while * pos->radius[1] determines the field over which the squaren moves */ h = pos->radius[0]; w = deg2pix(1/(2*st->f)); ncycles = pos->radius[1]/w; z[1] = -w * val/M_PI - (pos->radius[1]); z[0] = (-pos->radius[0]); while(z[1] < pos->radius[1]) { mycolor(vcolor); glBegin(GL_POLYGON); x[0] = z[0]; x[1] = z[1]; if(x[1] < -pos->radius[1]) x[1] = -pos->radius[1]; else if(x[1] > pos->radius[1]) x[1] = pos->radius[1]; myvx(x); x[1] = z[1] + w; if(x[1] < -pos->radius[1]) x[1] = -pos->radius[1]; else if(x[1] > pos->radius[1]) x[1] = pos->radius[1]; myvx(x); x[0] = z[0] +2 * pos->radius[0]; myvx(x); x[1] = z[1]; if(x[1] < -pos->radius[1]) x[1] = -pos->radius[1]; else if(x[1] > pos->radius[1]) x[1] = pos->radius[1]; myvx(x); glEnd(); z[1] += w; mycolor(offcolor); glBegin(GL_POLYGON); x[0] = z[0]; x[1] = z[1]; if(x[1] < -pos->radius[1]) x[1] = -pos->radius[1]; else if(x[1] > pos->radius[1]) x[1] = pos->radius[1]; myvx(x); x[1] = z[1] + w; if(x[1] < -pos->radius[1]) x[1] = -pos->radius[1]; else if(x[1] > pos->radius[1]) x[1] = pos->radius[1]; myvx(x); x[0] = z[0] +2 * pos->radius[0]; myvx(x); x[1] = z[1]; if(x[1] < -pos->radius[1]) x[1] = -pos->radius[1]; else if(x[1] > pos->radius[1]) x[1] = pos->radius[1]; myvx(x); glEnd(); z[1] += w; } glPopMatrix(); if(sst->ptr->plaid_angle > 0.01) { glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_BLEND); glBlendColor(0.5, 0.5, 0.5, 0.5); glBlendFunc (GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_COLOR); oldplaid = sst->ptr->plaid_angle; sst->ptr->plaid_angle = -sst->ptr->plaid_angle; paint_square(st, sst, mode); glDisable(GL_BLEND); sst->ptr->plaid_angle = oldplaid; } }
int main() { scanf("%d",&x_p); scanf("%d",&y_p); clear(); initscr(); start_color(); init_pair(2,COLOR_GREEN,COLOR_BLACK); init_pair(3,COLOR_YELLOW,COLOR_BLACK); init_pair(4,COLOR_RED,COLOR_BLACK); init_pair(5,COLOR_BLUE,COLOR_BLACK); attrset(A_BOLD); paint_square(2,2); paint_square(2,3); paint_square(2,4); paint_square(2,5); paint_square(2,6); paint_square(2,7); paint_square(2,8); paint_square(2,9); paint_square(4,1); int x_m=0,x_mo,y_m=0,y_mo=0; int picture[3][3]; picture[0][0]=1; picture[0][1]=2; picture[0][2]=3; picture[1][0]=4; picture[1][1]=5; picture[1][2]=6; picture[2][0]=7; picture[2][1]=8; picture[2][2]=9; input=0; y_m=0; x_m=0; while(input!='*') { noecho(); y_mo=y_m; x_mo=x_m; input=0; input=getch(); if(input=='d') { y_m=y_mo+1; if(y_m==3) { y_m=0; } } if(input=='a') { y_m=y_mo-1; if(y_m==-1) { y_m=2; } } if(input=='w') { x_m=x_mo-1; if(x_m==-1) { x_m=2; } } if(input=='s') { x_m=x_mo+1; if(x_m==3) { x_m=0; } } paint_square(2,picture[x_mo][y_mo]); paint_square(4,picture[x_m][y_m]); } clear(); refresh; endwin(); }