Author Topic: Curve-fitting  (Read 8912 times)

0 Members and 1 Guest are viewing this topic.

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Curve-fitting
« on: May 30, 2010, 01:57:08 pm »
~~~~axe is smexy~~~

anyway, i'm working on a version of tanks (scorched earth) and I'm wondering if anyone has any ideas on a routine for map-drawing. Smooth, random curves with varying amplitudes and periods: I was using the sin( function, but its epically confusing, what with the period being 255, etc

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Curve-fitting
« Reply #1 on: May 30, 2010, 07:01:16 pm »
You can get a nice parabolic smoothing by having a "height map" particle move across the screen with applied random gravity.  If the velocity gets too positive, make the gravity negative and if the velocity is too negative, make gravity positive.  Also, have the gravity flip at random intervals.  That gives a very smooth curve that resembles random wave motion in a cool way.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Curve-fitting
« Reply #2 on: May 30, 2010, 08:24:03 pm »
hmmm sounds like that could work. thanks.

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Curve-fitting
« Reply #3 on: May 31, 2010, 05:40:43 pm »
Ok...  because of my unfamiliarity with Axe's system of numbers I decided to try in BASIC first; I managed to make it work but not in axe: it produces a bunch of random vertical lines

BASIC version
Code: [Select]
:ClrDraw
:0->Xmin
:0->Ymin
:94->Xmax
:62-.Ymax
:8->V
:5->G
:0->A
:40->L2(1
:For(X,1,94
:L2(x)-2GA/V^2->L2(x+1)
:A+1->A
:If 2<abs(-2GA/V^2
:Then
:-G+randInt(-2,2->G
:-9->A
;End
:End
;For(A,1,94
:Line(A,L2(A),A+1,L2(A+1)
:End

And then I changed it to match Axe syntax:
Code: [Select]
:.AMAP
:ClrDraw
:8->V
:5->G
:0->A
:deltaList(40)->GDB1
:For(X,1,94
:-2*G*A//V//V+{X+GDB1}->{GDB1+X+1
:A+1->A
:If 2<abs(-2*G*A//V//V
:-G->G
:-9->A
;End
:End
:For(A,0,94
:Line(A,{GDB1+A},A+1,{GDB1+A+1
:End
;DispGraph
;Repeat getKey
:End

The basic idea is to just change the Y value by the derivative of the equ gx^2/v^2 + y where g= grav. constant, v=intitial velocity, and y= initial height and flip the gravity when f'x>2