views:

95

answers:

1

I am trying to write a code that will show an accelerating wheel. As long as the user presses 'a' the wheel should accelerate counterclockwise. The thing is that it turns in the right direction but it doesn't accelerate. This is the code I am using (in PTB-3 and Windows XP):

img=imread('c:\images.jpg');  
[yimg,ximg,z]=size(img);  
rot_spd = 1;  
larrow = KbName('a'); % modify this for Windows  
rarrow = KbName('b');  
[w,rect]=Screen('OpenWindow',0,[0 0 0]);  
sx = 400; % desired x-size of image (pixels)  
sy = yimg*sx/ximg; % desired y-size--keep proportional  
t = Screen('MakeTexture',w,img);  
bdown=0;  
th = 0; % initial rotation angle (degrees)  
HideCursor  
while(~any(bdown)) % exit loop if mouse button is pressed  
    [x,y,bdown]=GetMouse;  
    [keyisdown,secs,keycode] = KbCheck;    
    if(keycode(larrow))  
        th = th - rot_spd-1; % accelerate counterclockwise  
        th  
    end  
    if(keycode(rarrow))  
        th = th + rot_spd+1; % accelerate clockwise  
        th  
    end  
    destrect=[x-sx/2,y-sy/2,x+sx/2,y+sy/2];  
    Screen('DrawTexture',w,t,[],destrect,th);  
    Screen('Flip',w);   
end  
Screen('Close',w)   
ShowCursor   

If anyone has an idea why it doesn't accelerate, I'd appreciate it very much.

A: 

this is the code:
%th1=-120 Holds still

img=imread('c:/images.jpg'); [yimg,ximg,z]=size(img); rot_spd = .25; % rotation speed (degrees per frame) larrow = KbName('a'); % modify this for Windows? rarrow = KbName('b'); [w,rect]=Screen('OpenWindow',0,[0 0 0]); sx = 400; % desired x-size of image (pixels) sy = yimg*sx/ximg; % desired y-size--keep proportional t = Screen('MakeTexture',w,img); bdown=0; th = 0; % initial rotation angle (degrees) HideCursor th1=0; while(~any(bdown)) % exit loop if mouse button is pressed

[x,y,bdown]=GetMouse; [keyisdown,secs,keycode] = KbCheck; if(keycode(larrow)) th1 = (th1 - rot_spd) th1 end

if(keycode(rarrow)) th1 = (th1+ rot_spd) th1 end th=th+th1;

destrect=[x-sx/2,y-sy/2,x+sx/2,y+sy/2]; Screen('DrawTexture',w,t,[],destrect,th); Screen('Flip',w); end Screen('Close',w) ShowCursor;

ariel

related questions