[SOLVED] PolygonCeption Help : Confused screaming

I literally don’t get what i should do here. there are no instructions on what variables to use or what guide point i should get. here is my code.

// You are on your own this time, I hope you have learned what you need from the previous fractal levels. Check the guide for help with what you need to do and with the math required for polygons.
hero.setFlowerColor("purple");
// You need a function to convert degrees to radians.  Multiply degrees by Math.PI / 180.
function convert(n){
    return Math.PI / 180 * n;
}

// Your polygon function should have 3 inputs: start, end, and sides.
function polygon (start,end,sides){
    var full = Vector.subtract(end , start);
    var mag = full.magnitude();
    if (mag < 2) {
        hero.toggleFlowers(false);
        hero.moveXY(start.x, start.y);
        hero.toggleFlowers(true);
        hero.moveXY(end.x, end.y);
        return;
    }
    
    var fifth = Vector.multiply(full, 1/5);
    var angle = convert(360/sides);
    var A = Vector.add(start ,fifth);
    var rotate = Vector.rotate(fifth,angle);
    var B = Vector.add(rotate,A);
    var C = Vector.add(rotate,B);
    var D = Vector.add(rotate,C);
    polygon(start,A,sides);
    polygon(A,B,sides);
    polygon(B,C,sides);
    polygon(C,D,sides);
    polygon(D,end,sides);
}
// Remember to make your polygon recursive, drawing extra polygons at every corner.
// To get the start and end position for each polygon, add startOffset and endOffset to the yak's position.
var startOffset = new Vector(-15, -15);
var endOffset = new Vector(15, -15);
var enemies = hero.findEnemies();
// You need to loop through all the yaks, drawing a polygon for each.  Yaks are enemies.
for (var i = 0; i < enemies.length;i++){
    var enemy = enemies[i];
    var sides = enemy.sides;
    var start = Vector.add(enemy.pos, startOffset);
    var end = Vector.add(enemy.pos, endOffset);
    polygon(start,end,sides);
}

Note: this code creates a weird shape on the first yak. that’s it

I heard that @Chaboi_3000 has done this level, so i might need to get some tips from him. been trying for days.

ANY help would be appreciated
Riley

Hi Riley,

Are you still working on this one? I’ve (just) scraped through the level :laughing: - it’s a bit of a mystery why it works, but I’m happy to try to help if you still want it.

J.

1 Like

uhh YES. please tell me how i can fix this.

Hey, that’s an amazing recursive shape that you manage to draw :smile:. I’ll have a go, and @dedreous, @AnSeDra or @Deadpool198 can help when I’m stuck :wink: . I think the bit that needs work is this:

   var fifth = Vector.multiply(full, 1/5);
   var angle = convert(360/sides);
   var A = Vector.add(start ,fifth);
   var rotate = Vector.rotate(fifth,angle);
   var B = Vector.add(rotate,A);
   var C = Vector.add(rotate,B);
   var D = Vector.add(rotate,C);
   polygon(start,A,sides);
   polygon(A,B,sides);
   polygon(B,C,sides);
   polygon(C,D,sides);
   polygon(D,end,sides);

You look as though you’ve based your code on assuming that there’s going to be 5 sides in the shape, so you need to make it more generic. Rather than specifying the number of sides, I used a for loop for the whole of this chunk, so the loop repeated ‘sides’ times. Inside the for loop were 5 lines of code:

  1. The hero.moveXY(end.x, end.y); term - have this here rather than before the return.
  2. Redefine ‘full’ using the Vector.rotate
  3. The var fifth, as you’ve got it.
  4. The polygon function in here, with fifth as ‘end’
  5. Redefine ‘end’

Think you’ll still have some head scratching to do, but hopefully that gets you going in the right direction. Good luck!

1 Like

I will have to go pretty soon, so can you, @dedreous or @Deadpool198, help @Valentino_Artawan with this level?

Uhhh

function polygon (start,end,sides){
    var full = Vector.subtract(end , start);
    var mag = full.magnitude();
    if (mag < 2) {
        hero.toggleFlowers(false);
        hero.moveXY(start.x, start.y);
        return;
        
    }
    for (var i = 0; i < sides; i++){
        hero.toggleFlowers(true);
        hero.moveXY(end.x, end.y);
        var angle = convert(360/sides);
        var fifth = Vector.multiply(full, 1/5);
        full = Vector.rotate(full,angle);
        polygon(full,fifth,sides);
        fifth = Vector.multiply(full, 1/5);
    }
}

wat???

no i literally don’t get this XD

You’re close!

        var fifth = Vector.multiply(full, 1/5);
        full = Vector.rotate(full,angle);

Swap these over.

        polygon(full,fifth,sides);

I missed out a step here. Rather than ‘fifth’, this should be ‘fifth’ added to ‘end’. Also, the start point of the polygon should be ‘end’.

  fifth = Vector.multiply(full, 1/5);

Not quite for this line. You need to redefine ‘end’ by adding ‘full’ to it.

Keep going :smiley:.

1 Like

something’s wrong, but where?

P.S : i… i think we made it backwards…

Let’s see a fresh (recent) copy of your code.

here you go

// You are on your own this time, I hope you have learned what you need from the previous fractal levels. Check the guide for help with what you need to do and with the math required for polygons.
hero.setFlowerColor("purple");
// You need a function to convert degrees to radians.  Multiply degrees by Math.PI / 180.
function convert(n){
    return Math.PI / 180 * n;
}

// Your polygon function should have 3 inputs: start, end, and sides.
function polygon (start,end,sides){
    var full = Vector.subtract(end , start);
    var mag = full.magnitude();
    if (mag < 2) {
        hero.toggleFlowers(false);
        hero.moveXY(start.x, start.y);
        return;
        
    }
    for (var i = 0; i < sides; i++){
        hero.toggleFlowers(true);
        hero.moveXY(end.x, end.y);
        var angle = convert(360/sides);
        full = Vector.rotate(full,angle);
        var fifth = Vector.multiply(full, 1/5);
        var end2 = Vector.add(fifth,end);
        polygon(end,end2,sides);
        end = Vector.add(end,full);
    }
}
// Remember to make your polygon recursive, drawing extra polygons at every corner.
// To get the start and end position for each polygon, add startOffset and endOffset to the yaks position.
var startOffset = new Vector(-15, -15);
var endOffset = new Vector(15, -15);
var enemies = hero.findEnemies();
// You need to loop through all the yaks, drawing a polygon for each.  Yaks are enemies.
for (var i = 0; i < enemies.length;i++){
    var enemy = enemies[i];
    var sides = enemy.sides;
    var start = Vector.add(enemy.pos, startOffset);
    var end = Vector.add(enemy.pos, endOffset);
    polygon(start,end,sides);
}

ok, so i think something needs to be changed. something minimal.

It’s working when I run your code, just the toggling the flowers on & off isn’t happening at quite the right times. I’ll leave you to play with that.

For the

if (mag < 2) {

I needed to change the 2 to a 5 (I know the instructions say 2) to make it work.

2 Likes

heh…ya beat me to it! :stuck_out_tongue_winking_eye: However, the ‘mag < 2’ worked perfectly, once I fixed the toggling.

In a nutshell, I simply added two additional lines.

2 Likes

What exactly? i’ve been tinkering and still no luck

1 Like

nevermind. found the two lines. finished the level. THX guys! :smiley:

3 Likes

Well done! :smiley:
(20 characters)

1 Like