Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: p2 on June 22, 2011, 09:11:22 am

Title: Where's the mistake?
Post by: p2 on June 22, 2011, 09:11:22 am
Hi everyone :) This is the brother of p2... Im called p1  ;)
This morning, my brother came to me and asked me for helping him at programming a BASIC program where a line of length 10 turns around till it points on a position on the screen marked with a single pixel. I then had the idea to not letting the "snake" turn around but walking a curve. My brother didnt want to program it, so I sat down and did it. This is the result... but it doest do what i want it to do: I want it to directly walk to the dot, but not like going on a linear path: it has to walk on a curve (like a car has to), till facing the aim, and then walking towards it. As soon as it gets in a defined near to the dot, this is teleported to another position on the screen. The snake turns a round till the point is in its direction and then walks to it again.
Title: Re: Where's the mistake?
Post by: Ashbad on June 22, 2011, 09:15:14 am
Welcome, P2's brother :) you should make your own forum account!  ;D

I can't look at the program like this (can't open .8xp programs on my iPad), but Im sure others will be glad to help.
Title: Re: Where's the mistake?
Post by: Compynerd255 on June 22, 2011, 10:40:04 am
Welcome, P2's brother :) you should make your own forum account!  ;D

I can't look at the program like this (can't open .8xp programs on my iPad), but Im sure others will be glad to help.
I second the welcome. :)

A good way for people to easily see the code is to go onto an online code editor such as Sourcecoder to convert the program to plain text, then copy this text inside [code][/code] tags.
Title: Re: Where's the mistake?
Post by: Michael_Lee on June 22, 2011, 11:06:50 am
I used sourcecoder, and added indents, tidied the code up slightly (mostly adding newlines):

Code: [Select]
0→Xmin:1→ΔX
0→Ymin:1→ΔY
ClrDraw
FnOff :AxesOff:GridOff:Func:CoordOff:LabelOff:ExprOff:Full:Degree:a+bi
22→dim(∟SCHL1
2→B
1→∟SCHL1(1):1→∟SCHL1(2)
randInt(4,90)→∟SCHL1(21)
randInt(4,60)→∟SCHL1(22)

While ∟SCHL1(B-1)≠∟SCHL1(21) or ∟SCHL1(B)≠∟SCHL1(22)
    Pt-Change(∟SCHL1(21),∟SCHL1(22)
    For(A,2,20,2)
        Pt-On(round(∟SCHL1(A-1)),round(∟SCHL1(A)
    End

    tan-1((∟SCHL1(B-1)-∟SCHL1(B+1-20(B=20)))/(∟SCHL1(B)-∟SCHL1(B+2-20(B=20))))→C
    tan-1((∟SCHL1(21)-∟SCHL1(B-1))/(∟SCHL1(22)-∟SCHL1(B)))→D

    If abs(D-C)<20
    Then
        (C+D)/2→E
    Else
        (C+40((D-C)>0)-20)→E
    End

    If (√((∟SCHL1(21)-∟SCHL1(B-1))2+(∟SCHL1(22)-∟SCHL1(B))2))<5
    Then
        randInt(4,90)→∟SCHL1(21)
        randInt(4,60)→∟SCHL1(22)
    End

    Pt-Off(∟SCHL1(B-3+20(B=2)),∟SCHL1(B-2+20(B=2)))
    ∟SCHL1(B-1)+cos(E)→∟SCHL1(B-3+20(B=2))
    ∟SCHL1(B)+sin((E)→∟SCHL1(B-2+20(B=2))
    B-2→B
    If B=0:20→B
    Text(1,85,round(C,0
    Text(7,85,round(D,0
    Text(13,85,round(E,0
End
Title: Re: Where's the mistake?
Post by: Compynerd255 on June 22, 2011, 02:13:38 pm
I can't really tell what this code is supposed to do, but I did notice a few things:
Other than that, good start!
Title: Re: Where's the mistake?
Post by: Scipi on June 22, 2011, 02:23:21 pm
Quote
Always initialize all of your variables at the beginning of your program. It seems as if you only initialize B and LSCHL1
All the variables used are initialized properly, just they are within the program body.

I tried to see what could be the problem, but I can't figure out where the code that gives the curve to move on is. I also don't see where the code that has it move in a straight line once it points to the dot is.

Other than that, this completely blew my mind! O.O I agree with Compy, a very good start. ;D
Title: Re: Where's the mistake?
Post by: p2 on June 23, 2011, 08:58:28 am
p2:
My brother has told me a few things:
every step of the "snake" the angel betwen the point and the "snake" will be cut in half.
The problem is that the "Snake" walks a courve, but not to the point, it walks from past.
The "snake" is a list with a dim of 10.
It always deletes the last point and adds a new point in front of the list.


This
Code: [Select]
0→Xmin:1→ΔX
0→Ymin:1→ΔY
ClrDraw
FnOff :AxesOff:GridOff:Func:CoordOff:LabelOff:ExprOff:Full:Degree:a+bi
22→dim(∟SCHL1
2→B
1→∟SCHL1(1):1→∟SCHL1(2)
randInt(4,90)→∟SCHL1(21)
randInt(4,60)→∟SCHL1(22)

While ∟SCHL1(B-1)≠∟SCHL1(21) or ∟SCHL1(B)≠∟SCHL1(22)
    Pt-Change(∟SCHL1(21),∟SCHL1(22)
    For(A,2,20,2)
        Pt-On(round(∟SCHL1(A-1)),round(∟SCHL1(A)[b],0[/b]
    End

    tan-1((∟SCHL1(B-1)-∟SCHL1(B+1-20(B=20)))/(∟SCHL1(B)-∟SCHL1(B+2-20(B=20))))→C
    tan-1((∟SCHL1(21)-∟SCHL1(B-1))/(∟SCHL1(22)-∟SCHL1(B)))→D

    If abs(D-C)<20
    Then
        (C+D)/2→E
    Else
        (C+40((D-C)>0)-20)→E
    End

    If (√((∟SCHL1(21)-∟SCHL1(B-1))[b]^2[/b]+(∟SCHL1(22)-∟SCHL1(B))2))<5        //It's [b]^2[/b] and not just [b]2[/b]
    Then
        randInt(4,90)→∟SCHL1(21)
        randInt(4,60)→∟SCHL1(22)
    End

    Pt-Off(∟SCHL1(B-3+20(B=2)),∟SCHL1(B-2+20(B=2)))
    ∟SCHL1(B-1)+cos(E)→∟SCHL1(B-3+20(B=2))
    ∟SCHL1(B)+sin((E)→∟SCHL1(B-2+20(B=2))
    B-2→B
    If B=0:20→B
    Text(1,85,round(C,0
    Text(7,85,round(D,0
    Text(13,85,round(E,0
End






This is the code of my program:
Code: [Select]
:randInt(0,94)→X
:randInt(0,62)→Y
:randInt(0,94)→V
:randInt(0,62)→W
:randInt(0,94)→A
:randInt(0,62)→B
:7→V
:31→W
:32→T
:31→U
:11→J
:2→n
:While 1
:Pt-Off(Z,K
:Pt-On(V,W
:Pt-Off(R,S
:Pt-On(X,Y
:Pt-Off(C,D
:Pt-On(A,B
:Line(Z,K,R,S,0
:Line(V,W,X,Y
:√((X-V)²+(Y-W)²)→θ
:√((A-X)²+(B-Y)²)→N
:V→Z
:W→K
:X→R
:Y→S
:A→C
:B→D
:
:
:If N≤5
:Then
:randInt(0,94)→A
:randInt(0,62)→B
:End
:
:
:If J<9
:Then
:If V>X:V+.5abs(V-X)/θ→V
:If V<X:V-.5abs(V-X)/θ→V
:If W>Y:W+.5abs(W-Y)/θ→W
:If W<Y:W-.5abs(W-Y)/θ→W
:End
:
:
:If J>10
:Then
:If V>X:V-.5abs(V-X)/θ→V
:If V<X:V+.5abs(V-X)/θ→V
:If W>Y:W-.5abs(W-Y)/θ→W
:If W<Y:W+.5abs(W-Y)/θ→W
:
:End
:
:If N>5
:Then
:
:If X>A:X-.5abs(X-A)/N→X
:If X<A:X+.5abs(X-A)/N→X
:If Y>B:Y-.5abs(Y-B)/N→Y
:If Y<B:Y+.5abs(Y-B)/N→Y
:
:End
:
:
:
:√((V-X)²+(W-Y)²)→J
:
:
:End
It always sets a point where the snake will walk to.
I just wanted a line with a lenth of ten which walks to the point.

p1 wanted the Line/snake not to spin, but to walk a courve.