"Error" trying to draw lines

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By C:\Flavius

Hello, everyone.

First of all, you have to know that this is a not so simple code/problem/issue. Idk, you may not want to read this all.

Anyways, here goes my code:

func draw_epccl(nbSeg, PosSeg, nbEp, pns):
    var m = nbEp + 1;
    var ps = PosSeg;
    var colour = Color(0.0, 1.0, 1.0);
    var b = nbSeg;
    var t = 1;
    var us = [t];
    us[0] = t;
    var used = false;
    var k = false;
    var f = true;
    var Pos1 = Vector2();
    var Pos2 = Vector2();
    var j = 0;
    var cont = 0;
    var pm_nbs = pns;

    for i in range (3*b*m):
        if (i==0):
            Pos1 = ps[1]
            Pos2 = ps[1*m]

            if (t>b):
            while (k==true):
                if (t>b):

            while (f==true):

                while (j < (us.size())):

                    if (t==us[j]):

                        used = true;


                        used = false;
            if (used==true):
                t = pm_nbs[cont];
                cont = cont +1;

            Pos1 = ps[t]
            if ((t*m)>b):
            while (k==true):
                if ((t*m)>b):
            Pos2 = ps[t*m];
        draw_line(Pos1, Pos2, colour, 3, false);


This program draws a circumference, and then separates it in segments. The coordinates of these segments are stored in the ps (PosSeg) array.
Then, it draws lines which should seem to generate a curve. Having curves appear to show up from a set of straight lines is called envelope curves.
In this case this program should draw a type of curve called epicicloid. An epicicloid is so to say a circle within a circle. Just google it and you’ll see what I mean.
The most famous epicycloid is called the cardioid because it resembles a heart. The cardioid has one epicicle. You can have more than one epicycle. This has some historical origin but I won’t give a math class, sorry. This program uses the envelope curves to draw epicycles.

So ps is an array with the positions of the segments of the circumference.

nep is the number of epicicles it should draw, it gets added one because of the way this technique or way of drawing epicycloids works.

Well, colour is the colour of the lines, b is the number of segments the circumference has been divided into, in this case 36.

t is the index this program should use in ps to get the position of each segment. The default value is one and not zero because it gets multiplied and you can’t multiply zero by a number, it would be dumb.

us is an array of values of t that have already been used to draw lines. As t gets multiplied in this case by 2 all the time, if for example t=2 has already been used, then all its multiples have already been used too.

All boolean variables, j, cont, and pm_nbs will be explained later

Pos1, Pos2, the coordinates from and to which the line will be drawn.

pm_nbs is an array of all the prime numbers between 3 and b, in this case 36.

First this program uses segment 1 and 2 to draw a line.

Then it does t = t*m (as in this case m is 2, I will use 2 since now)

Now that i is not 0, it first checks that t is not bigger than b, the number of segments. If it is, it gets subtracted 36 until t is less than 36.

Now it compares t with every value in the us array, if this value of t has already been used, used = true, else it keeps being set to false until it has checked all values in us.

Then, if this value of t has already been used, t changes to the first prime number in the list, 3. Then cont which is a counter changes to 1, so that the next time a number has already been used it uses the next prime number, 5.

If this number hasn’t been used yet, it sets the first coordinate of the line to the t’th segment.

Then it checks if t*2 is greater then b, the number of segments. If it is, it gets subtracted 36. Because math and science, the segment number 40 and 4 (40-36) are the same.

So now that t2 is in the range 0 to b( nb os sgmnts, 36), it uses t2 as the second coordinate for the line.

I have done this by hand around 8 times, with different number of epicycles, and this metodology works great so clearly I have done something wrong because when I done this by hand with the exact numbers (takes around 5 minutes per epicycle drawn by hand which means this is not hard) it was composed by around 100 lines, and you could clearly see the cardioid and other oids. But this program only draws around the first 20 lines and you cannot see anything.

I remember when I done it by hand I had to mirror the lines, aka treat the 35 as a 1, 34 as a 2 etc which is done by using this formula [n=m-r*(-1)] where n is the number you start with, m is the number you start the line on and r is the range, number or segments.

this is what the program does

And this is what my program does. I may have to mirror the lines.

I will attach pictures to ilustrate you and help you help me.

I know this is tedious and longer to read compared to other questions but I have read my code quite a few times and don’t get what is missing or what is wrong with it.

If some charitable soul is willing to help me with this, I shall forever be grateful.

Lol, I just wanted to show you I know english.

Thank you all in advance and have a nice day!

PD: No worries if you don’t want to help me with this , it is completely understandable.

just as generell try not name your varaibles single letters, because it will make it 10times harder for anybode else to read the code and the understand what is going on. So instead of ps use for example listOfPositionsOfSegmentsOfCircumference. Even tough thats long, it’s about saving bytes, but about wrtiting code you can understand.
(var==true), can be replace with (var).
two whiles can be chainned with &&

other things, it’s nice that you explain your code, but please just add comments with #
so that people that want to help you don’t have to copy your code to an other monitor and read the description to the stuff.
Basicly try cleaning up your code, that way people will acutally be able to help you and maybe you will find the bug yourself.

coffeeDragon | 2018-04-26 14:53