
KiXforms The Forum for the KiXforms Community


View previous topic :: View next topic 
Author 
Message 
frak KiXforms Dabbler
Joined: 14 Mar 2003 Posts: 6 Location: Manchester UK

Posted: Tue May 06, 2003 12:32 pm Post subject: Sine wave cheat 


Hi well i've given up tryign to code my own trigonometry functions for kix for the time being. My maths is a little too rusty and to be honest i've struggled with it. The aim was to do some 3d rotating objects but you need sine and cosine functions to do this effectively. However, i did come up with a cheating way to do a sine wave, it is thoguh only an interpretation of one. I can't see how anyone will find it useful but hey i might as well post it. Most of it was pinched form a BYTE magazine article for Qbasic but i adapted it for KiXforms. You can change the appearance of the wave by setting velocity, sine and the stepping of the FOR loop to different values. enjoy. lol.
Regards
frak
Code: 
break on
$x =400
$y = 137
$sine = 128
$velocity = 0
$y1 = $y
$Form = CreateObject("Kixtart.Form")
$Form.Width = 410
$Form.Height = 300
$Form.Backcolor= 0,0,0
$Form.Forecolor = 0,255,0
$Form.show
$line1 = $form.line(0,$y,$x,$y)
$line2 = $form.line(0,$y$sine,$x,$y$sine)
$line3 = $form.line(0,$y+$sine,$x,$y+$sine)
draw_sine()
while $form.Visible
$=execute($form.DoEvents)
loop
exit 1
FUNCTION draw_sine
FOR $i=0 to $x
IF $sine >= 0
$velocity = $velocity  1
ELSE
$velocity = $velocity + 1
ENDIF
$sine = $sine + $velocity
$line4 =$form.line($i,$y1,$i+1,$y+$sine)
$y1 = $y+$sine
sleep 0.1
NEXT
ENDFUNCTION

Last edited by frak on Tue May 06, 2003 1:54 pm; edited 1 time in total 

Back to top 


Jochen KiXforms Devotee
Joined: 05 Mar 2003 Posts: 1204 Location: Stuttgart, Germany

Posted: Tue May 06, 2003 1:23 pm Post subject: 


Neat ...
To enhance 'functionality' (if there is other than reinventing oscilloscope apps ) one should trigger a timer object for the drawing, otherwise there will be no other functionality possible than close the thing
Oh yeah , Black background and Green would look better
Oh hey ! Welcome to the games'n'stuff forum ! _________________ Jochen
Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand. 

Back to top 


Sealeopard KiXforms Aficionado
Joined: 05 Mar 2003 Posts: 436 Location: Boston, MA

Posted: Tue May 06, 2003 1:37 pm Post subject: 


Depending ont he resolution required for the SIN/COs functions, one can always create a lookup table for the function, e.g. an array of [0359] for the appropriate sine/cosine values for each degree, for one degree precision. However, one has to then convert from/to radians. Alternatively, there are approximation methods for sine/cosine that are well documented. _________________ Jens
'There are two kinds of vessels, submarines and targets.' 

Back to top 


frak KiXforms Dabbler
Joined: 14 Mar 2003 Posts: 6 Location: Manchester UK

Posted: Tue May 06, 2003 1:55 pm Post subject: 


I had toyed with the idea of using lookup tables, i will look further into those or the approximations you mentioned i guess i am just being lazy but it depends when i get a free few minutes to look at this stuff and maths as you know takes more than a few mins lol. Anyway i resized the form and did it with the colours you suggested. However i couldn't get the timer to behave quite how i wanted. Again when i have more time i will update it.
Thanks for the feedback,
Dan 

Back to top 


Chris S. KiXforms Enthusiast
Joined: 05 Mar 2003 Posts: 241

Posted: Tue May 06, 2003 5:06 pm Post subject: 


Here's a timer sample...
Code:  Break On CLS
;
; Main Form
;
$frmMain = CreateObject("Kixtart.Form")
$frmMain.Size = 280,90
$frmMain.Text = "Using KiXforms build "+$frmMain.Build
$prgCPU = $frmMain.ProgressBar
$prgCPU.ScaleHeight = 50
$prgCPU.ScaleWidth = 50
$prgCPU.Top = 5
$prgCPU.Left = 5
$prgCPU.ForeColor = Lawngreen
$prgCPU.BackColor = Black
$prgCPU.BorderStyle = 1
$prgCPU.Orientation = 1
$prgCPU.Style = 1
$prgCPU.Max = 100
$picCPU = $frmMain.PictureBox
$picCPU.ScaleHeight = 50
$picCPU.ScaleWidth = 200
$picCPU.ForeColor = Green
$picCPU.BackColor = Black
$picCPU.Top = $prgCPU.Top
$picCPU.Left = $prgCPU.Right + 5
$Timer = $frmMain.Timer(500)
$Timer.OnTimer = "Draw()"
$frmMain.Center
$frmMain.Show
While $frmMain.Visible
$nul=Execute($frmMain.DoEvents)
Loop
Exit 1
Function Draw()
$picCPU.Clear
$picCPU.ForeColor = Green
For $y=10 to 50 step 10
$picCPU.Line(0,$y,200,$y)
Next
For $x=10 to 200 step 10
$picCPU.Line($x,0,$x,50)
Next
$picCPU.ForeColor = Lawngreen
$y1=50
for $x = 5 to 199 step 5
$y=rnd(100)
$y2=50$y/2
$prgCPU.Value = $y
$picCPU.Line($x,$y1,$x+5,$y2)
$y1=$y2
sleep 0.1
next
EndFunction



Back to top 


Lonkero KiXforms Devotee
Joined: 13 Mar 2003 Posts: 1022 Location: Espoo, Finland

Posted: Wed May 07, 2003 5:55 am Post subject: 


there is at least one linedrawer UDF coded at KORG...
it was to draw lines on map and draw a clock etc...
was not too fast but worked. _________________ Hammer 

Back to top 


Lonkero KiXforms Devotee
Joined: 13 Mar 2003 Posts: 1022 Location: Espoo, Finland

Posted: Wed May 07, 2003 6:27 am Post subject: 


ok, dunno how easy it's to adapt anything like this into this specific sinmonitor...
anyway, here it goes:
Code: 
function coord($x,$y,$dist,$deg)
dim $
select case $deg=0 $coord=$x,$y+$dist
case $deg=90 $coord=$x+$dist,$y
case $deg=180 $coord=$x,$y$dist
case $deg=270 $coord=$x$dist,$y
case $deg<90 $=sides($dist,$deg) $coord=$x+$[1],$y+$[0]
case $deg<180 $=sides($dist,$deg90) $coord=$x+$[0],$y$[1]
case $deg<270 $=sides($dist,$deg180) $coord=$x$[1],$y$[0]
case 1 $=sides($dist,$deg270) $coord=$x$[0],$y+$[1]
endselect
endfunction
function sides($1,$2)
dim $,$3
$1=0.0+$1*$1
$3=90.0$2
do $=0.01+$ until $1<($*$2)*($*$2)+($*$3)*($*$3)
$sides=$*$3,$*$2
endfunction

syntax:
RESULTINGx,RESULTINGy=Coord(CURRENTx,CURRENTy,DISTANCE,DEGREE)
this is more like basework for KiXforms vectorgraphics than just controlling pixels. _________________ Hammer 

Back to top 


Lonkero KiXforms Devotee
Joined: 13 Mar 2003 Posts: 1022 Location: Espoo, Finland

Posted: Wed May 07, 2003 6:28 am Post subject: 


once again, the board loosed single spaces inside the codetags!
that an bug if anything. _________________ Hammer 

Back to top 




You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum

Powered by phpBB © 2001, 2005 phpBB Group
