Home News Browse Search Reviews Interviews Webwatch Top 40
Poll Tips Glossary Codebase Links Lists Help Log in

 Code sample
Plotting Math functions
Submitted by guilippo on 11:44:29 20022 3rd February 2002 (4846 hits)
OPL32 : Algorithms
Level: Intermediate
This is an example how I plot math functions.
Questo è un\'esempio per plottare funzioni matematiche.
For suggestions or questions guilippo@tiscali.it
PROC plotdata:
  xa&=-20
  xb&=20
  ya&=-10
  yb&=10
  xpix=636
  ypix=236
  scale%=-1 : REM =si
  hres%=0
  beep%=0
  xrange&=xb&-xa&
  yrange&=yb&-ya&
  fsx=xpix/xrange&
  fsy=ypix/yrange&
  stepx%=xrange&/12+1
  stepy%=yrange&/6+1
ENDP

PROC setrange:
  dINIT \"Set Range\",2
  dTEXT \"x-axis\",\"\",512
  dLONG xb&,\"max.:\",-9999,9999
  dLONG xa&,\"min.:\",-9999,9999
  dTEXT \"y-axis\",\"\",512
  dLONG yb&,\"max.:\",-9999,9999
  dLONG ya&,\"min.:\",-9999,9999
  DIALOG
	REM	verify range
  xrange&=xb&-xa&
  yrange&=yb&-ya&
  IF xrange&<=0 OR yrange&<=0
    dINIT \"ERROR\"
    dTEXT \"\",\"Illegal Range\",512
    DIALOG
    setrange:
  ENDIF
  fsx=xpix/xrange&
  fsy=ypix/yrange&
  stepx%=xrange&/12+1
  stepy%=yrange&/6+1
ENDP

PROC settings:
  dINIT \"Other settings\",2
  dCHECKBOX hres%,\"high resolution\"
  dCHECKBOX scale%,\"display scale\"
  dCHECKBOX beep%,\"beep on\"
  DIALOG
ENDP

PROC plot:
	LOCAL y,xs,ys,xs1,ys1,test
	IF it%=0
		dINIT \"Warning - \"+Program$+\" - plot\",$300
		dTEXT \"\",\"NON E\' STATA SCELTA LA FUNZIONE\"
		DIALOG
		RETURN
	ENDIF
  CLS
  REM calcola le pos.degli assi sullo schermo
  REM attenzione asse ys (schermo) invertito rispetto a y
  y0pos%=yb&*fsy
  x0pos%=-xa&*fsx
	gAT 4,y0pos% : gLINETO xpix,y0pos%
	gAT x0pos%,4 : gLINETO x0pos%,ypix
  IF scale%=-1
    drawscale:
  ENDIF
  BUSY \"Plotting\"
  x=xa&
  test=0
  WHILE x<xb&
		y=fnz:
		ys=y0pos%-y*fsy
		IF ys>-30000 AND ys<30000
			xs=x0pos%+x*fsx
			IF test=0
				gAT xs,ys
				test=1
			ELSE
				gLINETO xs,ys
			ENDIF
		ENDIF
		REM incremento
		IF hres%=-1
			x=x+1/fsx
		ELSE
			x=x+10/fsx
		ENDIF
	ENDWH
	IF beep%<>0
		BEEP 5,300
	ENDIF
	BUSY OFF
	dINIT \"y= \"+it$,$300
	dPOSITION 1,1
	DIALOG
ENDP

PROC drawscale:
	LOCAL xstep%,ystep%,valx,valy,xs0%,ys0%
	gFONT 6 : gSTYLE 0
	xstep%=0
	ystep%=0
	valx=xa&
	valy=yb&
REM segna le scale degli assi x e y anche se
REM sono fuori dallo schermo
	IF y0pos%<0
		ys0%=0
	ELSEIF y0pos%>ypix
		ys0%=ypix
	ELSE
		ys0%=y0pos%
	ENDIF
	IF x0pos%<0
		xs0%=0
	ELSEIF x0pos%>xpix
		xs0%=xpix
	ELSE
		xs0%=x0pos%
	ENDIF
	WHILE xstep%<xpix
		gAT xstep%,ys0%-4 : gLINETO xstep%,ys0%+5
		IF ya&>-2 OR yb&>1
			gAT xstep%-4,ys0%-6
			REM testi sopra
		ELSE
			gAT xstep%-4,ys0%+16
			REM testi sotto
		ENDIF
		gPRINT valx
		rem ---------incrementi X----
		valx=valx+stepx%
		xstep%=xstep%+fsx*stepx%
	ENDWH
	WHILE ystep%<ypix
		gAT xs0%-4,ystep% : gLINETO xs0%+5,ystep%
		IF xa&>-2
			gAT xs0%+6,ystep%+5
			REM testi a destra
		ELSE
			gAT xs0%-20,ystep%+5
		ENDIF
		gPRINT valy
		rem ---------incrementi Y----
		valy=valy-stepy%
		ystep%=ystep%+fsy*stepy%
	ENDWH
ENDP
[ show as plain text ]   [ codebase index ]
Comments: 0 [ expand all ] [ post a new comment ]

Disclaimer: The following comments are the responsibility of the poster. epoczone.com is not responsible in any way for what they may say.
If you have not already done so, please read the terms and conditions before you post a comment.

Digital SLR News - DSLR camera information

 Log in
Username:
Password:

 Poll
With very few new releases of software, no new PDAs, and very little site maintenance happening, should the EPOC Zone be shut down?
Yes, it's pretty much useless...
No, it's one of the last Psion outposts!
[ results ]

 Top 5
MyNotes
Biklog5
VoiceMan5
MBMView
PsiDat

 Tips
DjVu Viewer
Sdictionary
Sviewer - .TXT.GZ file viewer
Maximum memory for revo
CF-data is not secured




 Glossary
Revo
DI 27/DI 28
GPRS
Parse
Kill (an EPOC application)

 Codebase
Handing stacks
Finding out the number of images in an MBM file.
Plotting Math functions
word-wrapping editor ver. 3.26
word-wrapping editor ver. 3.26

 Mailing list
Enter your email address and hit 'Subscribe' to join the software mailing list

Search:
Keywords:
In Association with Amazon.co.uk


(C)opyright 1999-2007 epoczone.com
Not logged in.
Please read the legal stuff.
A shrunken.net site