Ooops
October 28, 2021, 11:23:09

Author Topic: [bb] Cosineinterpolytion by Vertex [ 1+ years ago ]  (Read 675 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Cosineinterpolytion by Vertex [ 1+ years ago ]
« on: June 29, 2017, 00:28:42 »
Title : Cosineinterpolytion
Author : Vertex
Posted : 1+ years ago

Description : Hi!
THX to Markus!
<a href="http://astronomy.swin.edu.au/~pbourke/analysis/interpolation/" target="_blank">http://astronomy.swin.edu.au/~pbourke/analysis/interpolation/[/url] for more methods
cu olli


Code :
Code: BlitzBasic
  1. ; Set the screensize
  2. Graphics 640,480,32,2
  3. SetBuffer BackBuffer()
  4.  
  5. ; Dimension the pointarray and set startvalues
  6. Dim DataPoint(4,1)
  7. DataPoint(0,0) = 100 : DataPoint(0,1) = 090
  8. DataPoint(1,0) = 200 : DataPoint(1,1) = 160
  9. DataPoint(2,0) = 300 : DataPoint(2,1) = 300
  10. DataPoint(3,0) = 400 : DataPoint(3,1) = 210
  11. DataPoint(4,0) = 500 : DataPoint(4,1) = 100
  12.  
  13. ; Set the clearcolor to red, and select point 0
  14. ClsColor 255,255,255 : Global Selected = 0
  15.  
  16. ; Mainloop
  17. While Not KeyDown(1)
  18.    Cls ; Clear screen
  19.  
  20.    ; Userinput (Use [Q] and [W] to select a point,
  21.    ; and Arrowkeys to position the selected point)
  22.    If KeyHit(16) And Selected > 0 Then Selected = Selected - 1
  23.    If KeyHit(17) And Selected < 4 Then Selected = Selected + 1
  24.    If KeyDown(203) Then DataPoint(Selected,0) = DataPoint(Selected,0) - 1
  25.    If KeyDown(205) Then DataPoint(Selected,0) = DataPoint(Selected,0) + 1
  26.    If KeyDown(200) Then DataPoint(Selected,1) = DataPoint(Selected,1) - 1
  27.    If KeyDown(208) Then DataPoint(Selected,1) = DataPoint(Selected,1) + 1
  28.  
  29.    DrawLine() ; Draw the interpolated line between point 0 and 4
  30.  
  31.    Flip ; Flip backbuffer to frontbuffer
  32. Wend
  33.  
  34. End ; End of programm
  35.  
  36. Function DrawLine()
  37.    ; Startpoint for the first Line
  38.    X = DataPoint(0,0) : Y = DataPoint(0,1) : Color 0,0,0
  39.  
  40.    ; Draw the interpolyted Line between point 0 and 1
  41.    MX = (DataPoint(0,0) - DataPoint(1,0)) * (-1)
  42.    For MU# = 0 To 1.0 Step 0.08
  43.       OX = X : OY = Y
  44.       Y = CosineInterpolate(DataPoint(0,1),DataPoint(1,1),MU#)
  45.       X = MX * MU# + DataPoint(0,0)
  46.       Line OX,OY,X,Y
  47.    Next
  48.    
  49.    ; Draw the interpolated line between point 1 and 4
  50.    For I = 2 To 4
  51.       MX = (DataPoint(I - 1,0) - DataPoint(I,0)) * (-1)
  52.       For MU# = 0 To 1.0 Step 0.08
  53.          OX = X : OY = Y
  54.          Y = CosineInterpolate(DataPoint(I - 1,1),DataPoint(I,1),MU#)  
  55.          X = MX * MU# + DataPoint(I - 1,0)
  56.          Line OX,OY,X,Y
  57.       Next
  58.    Next
  59.  
  60.    ; Dra the anchor points
  61.    Color 255,0,0
  62.    For I = 0 To 4
  63.       If Selected = I Then
  64.          Color 0,0,255
  65.       Else
  66.          Color 255,0,0
  67.       EndIf
  68.       Oval DataPoint(I,0) - 2,DataPoint(I,1) - 2,5,5,1
  69.    Next
  70. End Function
  71.  
  72. ; Function for cosineinterpolated line
  73. Function CosineInterpolate(Y1#,Y2#,MU#)
  74.    Local MU2#
  75.    MU2# = (1.0 - Cos(MU# * 180.0))/2.0
  76.    Return (Y1# * (1.0 - MU2#) + Y2# * MU2#)
  77. End Function
  78.  
  79. ; Function for normal line
  80. Function LinearInterpolate(Y1#,Y2#,MU#)
  81.    Return Y1# * (1 - MU#) + Y2# * MU#
  82. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal