commit 988a7b9492c752baa4d7d0279fc5c58122c9db36 Author: En Yi Date: Sat Feb 10 22:33:57 2018 +0000 First commit diff --git a/OuO.m b/OuO.m new file mode 100755 index 0000000..ea04b3d --- /dev/null +++ b/OuO.m @@ -0,0 +1,209 @@ +function OuO() +%% Create the window +clc; +%Default Constants +default_updatetime = 0.002; +%Create the update timer, used for continuously updating the game screen +update_t = timer('ExecutionMode','fixedSpacing','Period',default_updatetime,'TimerFcn',@update_face); +blink_t = timer('ExecutionMode','singleShot','StartDelay',2,'TimerFcn',@set_blink); +mood_t = timer('ExecutionMode','fixedSpacing','Period',5,'TimerFcn',@set_mood); + +%Create the window +scrsz = get(0,'ScreenSize'); +start_dim = min(scrsz(3)/1.5,scrsz(4)/1.5);%Used for rescaling +win = figure('DeleteFcn',@delete_timers,'ToolBar',... + 'none','Name','OuO','NumberTitle','off','MenuBar','none',... + 'Resize','off','Visible','off','Color',[0 0 0]/255,... + 'Position',[[scrsz(3),scrsz(4)]/4.5 start_dim start_dim],... + 'WindowButtonMotionFcn',@blank_function); + +%% Create the UI componenets +face_axes = axes('Parent',win,'Position',[0 0 1 1]); + +set(win,'Visible','on') +%% Define face features +face_size = [4;4]; +lefteye_startpos = [1.1;2.5]; +lefteye_currentpos = lefteye_startpos; +lefteye_setpos = lefteye_startpos; +lefteye_size = 0.3; +leftbrow_currentangles = [90 90]; +leftbrow_setangles = [90 90]; +leftbottom_currentangles = [90 90]; +leftbottom_setangles = [90 90]; + +righteye_startpos = [2.9;2.5]; +righteye_currentpos = righteye_startpos; +righteye_setpos = righteye_startpos; +righteye_size = 0.3; +rightbrow_currentangles = [90 90]; +rightbrow_setangles = [90 90]; +rightbottom_currentangles = [90 90]; +rightbottom_setangles = [90 90]; + +blinking = 0; + +mouth_centre = [2;1.5]; +mouth_width = 0.5; +mouth_shift = -1; +mouth_setshift = -1; +current_mood = 'Happy'; + +set(face_axes,'Xlim',[0 face_size(1)],'Ylim',[0 face_size(2)],'Visible','off'); +start(update_t) +start(mood_t) +%% Callback functions + function update_face(~,~) + cla(face_axes) + [Xx,Yy] = get_mouse_pos(); + detect_range = 1.5; + mouse_relative_pos = ([Xx;Yy] - face_size/2).*[1;1j]; + if (abs(mouse_relative_pos)