123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- function [Ob, Par] = JA_Initialise_Shapes(Par)
- % it produces the initial position of every object on the screen
- % every measure is taken as a ratio of the screen_dimensions, so it could be
- % easily adapted (thanks to JA_dim2prop and JA_prop2dim)
- % get window and screen dimensions
- window = Par.window;
- screen_dimensions = Par.screen_dimensions;
- %% create ball object
- % It spits pixel number corresponding to 0.08 of the current x axis and 0 of the Y axis (rounded);
- [dimB] = JA_prop2dim(screen_dimensions, 0.08 , 0);
- [posB] = JA_prop2dim(screen_dimensions, 0.65, 0.0);
- ball = [];
- ball.name = 'ball';
- ball.type = 'circle';
- ball.window = window;
- ball.centered_square = [posB(1) posB(2)]; % initial ball position
- ball.diameter = dimB(1); % %diameter of the ball
- ball.color = [0.5 0.5 0.5]; % grey color
- % it centers the ball up and right on the screen
- baseRect = [0 0 ball.diameter ball.diameter];
- ball.dimension = CenterRectOnPoint(baseRect, ball.centered_square(1),...
- ball.centered_square(2));
-
- %% this obj will not be loaded, but it provides distances for piston_CF and table_CF
- ball_distance_in_propY = 0.4;
- [posB_final_CF] = JA_prop2dim(screen_dimensions, 0.65, ball_distance_in_propY);
- ball_final_CF = [];
- ball_final_CF.name = 'ball';
- ball_final_CF.type = 'circle';
- ball_final_CF.window = window;
- ball_final_CF.centered_square = [posB_final_CF(1), posB_final_CF(2)];
- ball_final_CF.diameter = dimB(1);
- ball_final_CF.color = [0.5 0.5 0.5];
-
- baseRect_final_CF = [0 0 ball.diameter ball.diameter];
- ball_final_CF.dimension = CenterRectOnPoint(baseRect_final_CF, ball_final_CF.centered_square(1),...
- ball_final_CF.centered_square(2));
- %% this obj will not be loaded, but it provides distances for piston_SBJ and table_SBJ
- posB_final_SBJ(1) = posB_final_CF(1) - posB_final_CF(2);%0.8*(posB_final_CF(1) - posB_final_CF(2));
- posB_final_SBJ(2) = posB_final_CF(2);
- ball_final_SBJ = [];
- ball_final_SBJ.name = 'ball';
- ball_final_SBJ.type = 'circle';
- ball_final_SBJ.window = window;
- ball_final_SBJ.centered_square = [posB_final_SBJ(1), posB_final_SBJ(2)];
- ball_final_SBJ.diameter = dimB(1);
- ball_final_SBJ.color = [0.5 0.5 0.5];
-
- baseRect_final_SBJ = [0 0 ball.diameter ball.diameter];
- ball_final_SBJ.dimension = CenterRectOnPoint(baseRect_final_SBJ, ball_final_SBJ.centered_square(1),...
- ball_final_SBJ.centered_square(2));
-
- %% creates the flat horizontal line onto the ball lands after falling in the CF turn
- % length and thickness in pixels
- [dim_table] = JA_prop2dim(screen_dimensions, 0.15, 0.005);
- % position of the center of the table on the screen in pixels
- [pos] = JA_prop2dim(screen_dimensions, 0.65, 0.5667);
- table_CF = [];
- table_CF.name = 'table_CF';
- table_CF.type = 'square';
- table_CF.window = window;
- table_CF.centered_square = [pos(1) pos(2)];
- table_CF.length = dim_table(1);
- table_CF.height = dim_table(2);
- table_CF.position = [0 0 table_CF.length table_CF.height];
- table_CF.color = [1 1 1];
- table_CF.dimension = ...
- CenterRectOnPoint(table_CF.position, table_CF.centered_square(1),...
- table_CF.centered_square(2));
- table_CF.dimension(2) = ball_final_CF.dimension(4);
- table_CF.dimension(4) = table_CF.dimension(2)+table_CF.height;
- %% create Piston for CF
- [dimP1] = JA_prop2dim(screen_dimensions, 0.25, 0.1);
- [posPCF] = JA_prop2dim(screen_dimensions, 0.84, 0.5);
- piston_CF = [];
- piston_CF.name = 'piston_CF';
- piston_CF.type = 'square';
- piston_CF.window = window;
- piston_CF.centered_square = [posPCF(1) ball_final_CF.centered_square(2)];
- piston_CF.length = dimP1(1);
- piston_CF.height = dimP1(2);
- piston_CF.position = [0 0 piston_CF.length piston_CF.height];
- piston_CF.color = [0.5 0.5 0.5];
- piston_CF.dimension = ...
- CenterRectOnPoint(piston_CF.position, piston_CF.centered_square(1),...
- piston_CF.centered_square(2));
-
- piston_CF.dimension(1) = table_CF.dimension(3);
- piston_CF.dimension(3) = piston_CF.dimension(1)+ piston_CF.length;
- %% creates the vertical line onto the ball lands after the ball has been pushed by CF
- [dim_table] = JA_prop2dim(screen_dimensions, 0.15, 0.005);
- table_SBJ = [];
- table_SBJ.name = 'table_SBJ';
- table_SBJ.type = 'square';
- table_SBJ.window = window;
- table_SBJ.centered_square = [0 ball_final_CF.centered_square(2)];
- table_SBJ.length = dim_table(2);
- table_SBJ.height = dim_table(1);
- table_SBJ.position = [0 0 table_SBJ.length table_SBJ.height];
- table_SBJ.color = [1 1 1];
- table_SBJ.dimension = ...
- CenterRectOnPoint(table_SBJ.position, table_SBJ.centered_square(1),...
- table_SBJ.centered_square(2));
-
-
- table_SBJ.dimension(3) = ball_final_SBJ.dimension(1); %%%%
- table_SBJ.dimension(1) = table_SBJ.dimension(3)-table_SBJ.length/2;
- %% create Piston for SBJ
- pos(1) = ball_final_SBJ.centered_square(1);
- pos(2) = ball_final_SBJ.centered_square(2);
- piston_SBJ = [];
- piston_SBJ.name = 'piston_SBJ';
- piston_SBJ.type = 'square';
- piston_SBJ.window = window;
- piston_SBJ.centered_square = [pos(1) pos(2)];
- piston_SBJ.length = dimP1(2);
- piston_SBJ.height = dimP1(1);
- piston_SBJ.position = [0 0 piston_SBJ.length piston_SBJ.height];
- piston_SBJ.color = [0.5 0.5 0.5];
- piston_SBJ.dimension = ...
- CenterRectOnPoint(piston_SBJ.position, piston_SBJ.centered_square(1),...
- piston_SBJ.centered_square(2));
-
- piston_SBJ.dimension(2) = table_SBJ.dimension(4);
- piston_SBJ.dimension(4) = piston_SBJ.dimension(2)+ piston_SBJ.height;
- %% create Background object
- back = [];
- back.name = 'back';
- back.type = 'square';
- back.color = [0 0 0];
- back.dimension = screen_dimensions;
- back.centered_square = [screen_dimensions(3)/2 screen_dimensions(4)/2];
- back.length = screen_dimensions(3);
- back.height = screen_dimensions(4);
- back.position = [0 0 back.length back.height];
- back.dimension = ...
- CenterRectOnPoint(back.position, back.centered_square(1),...
- back.centered_square(2));
-
- % %% create text_CF
- % [pos] = JA_prop2dim(screen_dimensions, 0.815, 0.5425);
- %
- % text_CF = [];
- % text_CF.name = 'text_CF';
- % text_CF.type = 'text';
- % text_CF.color = [1 1 1];
- % text_CF.size = 60;
- % text_CF.content = 'x';
- % text_CF.dimension = screen_dimensions;
- % text_CF.centered_square = [pos(1) pos(2)];
- %
- % %%
- %
- % [pos] = JA_prop2dim(screen_dimensions, 0.25, 0.78);
- %
- % text_SBJ = [];
- % text_SBJ.name = 'text_SBJ';
- % text_SBJ.type = 'text';
- % text_SBJ.color = [1 1 1];
- % text_SBJ.size = 60;
- % text_SBJ.content = 'x';
- % text_SBJ.dimension = screen_dimensions;
- % text_SBJ.centered_square = [pos(1) pos(2)];
- %
- %% create arduino objects standing for the three sensors
- arduino_CF = [];
- arduino_CF.name = 'arduino_CF';
- arduino_CF.val = [];
- arduino_CF.type = 'none';
- %%
- arduino_SBJ_DCG = [];
- arduino_SBJ_DCG.name = 'arduino_SBJ_DCG';
- arduino_SBJ_DCG.val = [];
- arduino_SBJ_DCG.type = 'none';
- %%
- arduino_SBJ_RISP = [];
- arduino_SBJ_RISP.name = 'arduino_SBJ_RISP';
- arduino_SBJ_RISP.val = [];
- arduino_SBJ_RISP.type = 'none';
- %% creates a structure cntaining all the objects created that can be put as inputs or outputs for functions in the main script
- Ob = [];
- Ob.back = back;
- Ob.piston_CF = piston_CF;
- Ob.piston_SBJ =piston_SBJ;
- Ob.ball = ball;
- Ob.table_CF = table_CF;
- Ob.table_SBJ = table_SBJ;
- % Ob.text_CF = text_CF;
- % Ob.text_SBJ = text_SBJ;
- Ob.arduino_CF = arduino_CF;
- Ob.arduino_SBJ_DCG = arduino_SBJ_DCG;
- Ob.arduino_SBJ_RISP = arduino_SBJ_RISP;
- Ob_fieldnames = fieldnames(Ob);
- %% the following allows sliding the whole set of objects on the screen along the X axis
- [slide] = JA_prop2dim(Par.screen_dimensions, 0.2, 0);
- for sl = 1:length(Ob_fieldnames)
-
- if ~strcmp(Ob.(Ob_fieldnames{sl}).name, 'back')
-
- % if the object has a 'dimension' field...
- if isfield(Ob.(Ob_fieldnames{sl}), 'dimension')
-
- % slide it on the X axis by subtracting the pixels in the slide variable
- Ob.(Ob_fieldnames{sl}).dimension([1 3]) = Ob.(Ob_fieldnames{sl}).dimension([1 3])-slide(1);
- Ob.(Ob_fieldnames{sl}).centered_square(1) = Ob.(Ob_fieldnames{sl}).centered_square(1)-slide(1);
-
- end
- end
-
- end
- end
|