[Scilab-users] Using uimenue to change rotation_angles
Jens Simon Strom
j.s.strom at hslmg.de
Thu Dec 22 11:38:03 CET 2016
Hi Samuel,
In the meantime I have realized what you meant with 'You don't need to
block the console with a loop to make changes or actions on existing
graphics.' The following script is loopless. I share it with those who
perhaps can use it in presentations demonstrating a curve under
different aspects.
//show a 3D curve under selectable aspects
x=[1 1 0 0 0]; y=[0 0 0 0.5 1]; z=[1 0 0 1 0];
xdel()
param3d(x,y,z,-90,90,"$\huge x$@$\huge y$@$\huge z$",[4 3]), ce=gce(); ce.thickness=5;
ca=gca();
//
function !cb(c,C,cax)//callback for uimenu()
if c==C(1), cax.rotation_angles=[90 -90];
elseif c==C(2), cax.rotation_angles=[90, 0];
elseif c==C(3), cax.rotation_angles=[ 0,-90];
elseif c==C(4), cax.rotation_angles=[35, 45];
elseif c==C(5), cax.rotation_angles=cax.rotation_angles+[0 -10];
elseif c==C(6), cax.rotation_angles=cax.rotation_angles+[0 +10];
elseif c==C(7)
ca0=cax.rotation_angles;
for k=[0:100 99:-1: 0]
cax.rotation_angles=ca0+[-0.25*k k];
sleep(15)
end
elseif c==C(8), xdel(), abort
end
endfunction
//
C=["xz" "yz" "xy" "Perspec" "Turn10°Left" "Turn10°right" "Rotate" "Finish"];//case name strings
for i=1:size(C,2), uimenu('label',C(i),'callback','!cb(C('+string(i)+'),C,ca)'); end
Thanks again for your consultation.
Regards
Jens
--------------------------------------------------------------------------------------------------
Am 18.12.2016 18:04, schrieb Jens Simon Strom:
> Hi Samuel,
> what I really do is this:
>
> xdel()
> figure_size=[1800 900];
> cf=figure(1,'position',[0 0 figure_size],'background',8,'immediate_drawing','off','visible','off');
> //...
> //plot3d and param3d commands
> // ...
> Rotation_Angles=[85 -64];
> ca=gca();
> ca.box='off';
> xtitle('$\Huge{\text{Isometrisch}}$','','')
> cf.immediate_drawing='on'; cf.visible='on';
>
> m1= uimenu(cf,'label','Himmelspol','callback','ra=[0,0],xtitle(''$\Huge{\text{Himmelspol}}$'','','')');
> m2= uimenu(cf,'label','Ost','callback','ra=[90,90],xtitle(''$\Huge{\text{Ost}}$'','','')');
> m3= uimenu(cf,'label','Äquator','callback','ra=[90,0],xtitle(''$\Huge{\text{Äquator}}$'','','')');
> m4= uimenu(cf,'label','West','callback','ra=[90,-90],xtitle(''$\Huge{\text{West}}$'','','')');
> m5= uimenu(cf,'label','Isometrisch','callback','ra=Rotation_Angles,xtitle(''$\Huge{\text{Isometrisch}}$'','','')');
> m6= uimenu(cf,'label','Animation','callback','Case=1,xtitle(''$\Huge{\text{Rotierend}}$'','','')');
> m7= uimenu(cf,'label', 'Aus', 'callback', "t=%f");
>
> Case=0;//Initiierung für Anfangspassage, d.h.keine Animation
> ra=Rotation_Angles;//Initiierung für Anfangspassage
> t=%t;
> while t==%t
> if Case==1//m6
> Case=0;
> rota=ca.rotation_angles;
> for k=[0:1:90 89:-1:0]
> drawlater()
> ca.rotation_angles=rota+[0 k];
> sleep(10);
> drawnow()
> end//for k=[ .... ]
> else
> sleep(200)
> ca.rotation_angles=ra;
> end//if
> end//while
>
> This works satisfactorily. I could not get the result without the
> infinite loop.
>
> Kind regards
> Jens
> -----------------------------------------------------------------------
>
>
> Am 18.12.2016 16:36, schrieb Samuel Gougeon:
>> Le 18/12/2016 16:20, Jens Simon Strom a écrit :
>>> Hi Samuel,
>>> Without the loop the script finishes and gives no chance to change
>>> anything.
>> ?
>> Have you tried? Since the figure and its menus are still here, you
>> can still use them, even if the script having generating them is
>> finished.
>>
>> A callback is an asynchronous independent script that is performed
>> just when it is called, "at any time" (actually, its instructions are
>> queued when it is called, and performed ASAP).
>>
>> You don't need to block the console with a loop to make changes or
>> actions on existing graphics.
>> But if you want to make it "modal", that is to say waiting for and
>> compelling the user to do something, yes, a loop is required.
>> BTW, the loop that you use is infinite: there is no way to escape it
>> smoothly, since
>> while 1
>> is always true.
>>
>> SG
>>
>>
>>
>> _______________________________________________
>> users mailing list
>> users at lists.scilab.org
>> http://lists.scilab.org/mailman/listinfo/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20161222/bbc8ec85/attachment.htm>
More information about the users
mailing list