Page 1 of 1

Optimisation de code

Unread postPosted: 30 Jan 2013, 18:04
by quentin974
Bonsoir

Après avoir trimé sur cet utilitaire, GEOGEBRA sur Z80 est enfin né. Mais son code n'est certainement pas optimisé, et comme je vois pas en quoi, je préfère m'en référer à des professionnels...

Mon code, le voici :
Code: Select all
:Degree
:GridOff
:PlotsOff
:FnOff
:Full
:ClrDraw
:AxesOff
:0→Xmin
:94→Xmax
:0→Ymax
:‾62→Ymin
:CoordOff
:Lbl D
:ClrHome
:Text(57,4,"A+
:Line(18,‾58,32,‾61
:Text(57,40,"FIG^ 
:Text(57,60,"OPT^
:Text(57,79,"MES^
:Goto 1
:ClrHome
:Lbl 1
:While 1
:getKey→K
:If K=11
:Then
:Input
:Pt-On(X,Y,3
:End
:If K=12
:Then
:Input
:Pt-On(X,Y,2
:X→A
:Y→B
:Input
:Line(A,B,X,Y
:Pt-On(X,Y,2
:End
:If K=13
:Then
:Menu("FIGURES","CERCLE",2,"TRIANGLE",3,"PARALLELE",7,"DROITE",8,"MILIEU",9,"PARALLELOGRAMME",50,"RETOUR",30
:Lbl 50
:Input
:X→A
:Y→B
:Pt-On(A,B
:Input
:X→C
:Y→D
:Line(A,B,C,D
:Input
:Line(C,D,X,Y
:Line(X,Y,X-(C-A),Y-(D-B)
:Line(A,B,X-(C-A),Y-(D-B)
:Goto D
:Lbl 9
:Input
:X→A
:Y→B
:Input
:(X+A)/2→X
:(Y+B)/2→Y
:Pt-On(X,Y,3)
:Goto D
:Lbl 8
:Input
:X→A
:Y→B
:Input
:(Y-B)/(X-A)→C
:Y-CX→B
:DrawF C(X)+B
:Goto D
:Lbl 7
:Input
:X→A
:Y→B
:Input
:X→C
:Y→D
:Input
:Pt-On(X,Y,2
:Pt-On(X+(C-A),Y+(D-B),2
:Line(X,Y,X+(C-A),Y+(D-B)
:Goto D
:Lbl 3
:Input
:Pt-On(X,Y,2
:X→A
:Y→B
:Input
:Pt-On(X,Y,2
:Line(A,B,X,Y
:X→C
:Y→D
:Input
:Pt-On(X,Y,2
:Line(A,B,X,Y
:Line(C,D,X,Y
:Goto D
:Lbl 2
:Input
:Pt-On(X,Y,3
:X→A
:Y→B
:Input
:Circle(A,B,√((X-A)²+(Y-B)²)
:Goto D
:End
:If K=15
:Then
:Menu("MESURES","LONGUEUR",20,"ANGLE",21,"RETOUR",30
:Lbl 21
:Input
:X→A
:Y→B
:Input
:√((X-A)²+(Y-B)²)→L
:X→C
:Y→D
:Input
:√((X-A)²+(Y-B)²)→H
:√((X-C)²+(Y-D)²)→M
:Disp "ANGLE°",cos<sup>-1</sup>((H²-M²-L²)/(‾2ML)
:Pause
:DispGraph
:Goto D
:Lbl 20
:Input
:X→A
:Y→B
:Input
:ClrHome
:Disp "LONGUEUR",√((X-A)²+(Y-B)²)
:Pause
:DispGraph
:Goto D
:End
:If K=14
:Then
:Menu("OPTIONS","OUVRIR",4,"SAUVER",5,"EFFACER",6,"QUITTER",10,"TEXTE",40,"RETOUR",30
:Lbl 40
:Input
:Input "TEXTE : ",Str1
:Text(‾Y,X,Str1
:Goto D
:Lbl 30
:Goto D
:Lbl 10
:Menu("SAUVER ?","OUI",55,"NON",56
:Lbl 55
:StorePic 9
:Goto 56
:Lbl 56
:ClrDraw
:ZStandard
:CoordOn
:AxesOn
:Disp
:Stop
:Lbl 4
:RecallPic 9
:Goto D
:Lbl 5
:StorePic 9
:Goto D
:Lbl 6
:prgmGEOGEBRA
:End
:End
:Goto 1


Une idée ?

Re: Optimisation de code

Unread postPosted: 30 Apr 2013, 15:27
by ticot
Enlever les Goto et les Label :D

Re: Optimisation de code

Unread postPosted: 30 Apr 2013, 15:49
by Bisam
Bien tenté, ticot...
Mais à cause des "Menu", c'est impossible !
Par ailleurs, cela améliorerait peut-être la lisibilité mais pas les performances.

Il y a une toute petite amélioration possible : supprimer le Label 30 et modifier les menus pour qu'ils renvoient directement sur le label D et non sur le label 30.