0

Similar to a previous exercise, I am arranging cubes in a letter W. Again, if you're having trouble visualizing the end result, then think of every cube as a pixel, building a sprite of 'W'.

I created 4 sections of my code, 1 for each stroke making up the letter, but 2 of each have the same 'root point':

file -f -new;

//Specifies starting coordinates

int $xpnt1 = 5.5;
int $xpnt2 = -5.5;

//////////////////

for($i=1;$i<=25;$i++) { //BRANCH 1, POINT 1, DIR L
    polyCube;
    move -ws $xpnt1 0 0;
    //select "pCube1";
    move -r ($i*1) ($i*1) 0;
    move -r $xpnt1 0 0 pCube1.scalePivot;
    }
for($i=1;$i<=25;$i++) {//BRANCH 2, POINT 1, DIR R
    polyCube;
    move -ws $xpnt1 0 0;
    //select "pCube26";
    move -r ($i*-1) ($i*1) 0;
    move -r $xpnt1 0 0 pCube26.scalePivot;
    }
for($i=1;$i<=25;$i++) {//BRANCH 3, POINT 2, DIR L
    polyCube;
    move -ws $xpnt2 0 0;
    //select "pCube51";
    move -r ($i*1) ($i*1) 0;
    move -r $xpnt2 0 0 pCube51.scalePivot;
    }
for($i=1;$i<=25;$i++) { //BRANCH 4, POINT 2, DIR R
    polyCube;
    move -ws $xpnt2 0 0;
    //select "pCube76";
    move -r ($i*-1) ($i*1) 0;
    move -r $xpnt2 0 0 pCube76.scalePivot;
    }

So far, I've been able to get the cubes to spawn how I'd like. The main problem here is one that came up erroneously: despite having 2 of each share either 5.5 or -5.5 as starting coordinates, they end up being spaced apart by what appears to be the program: this is the current result. What ever could I be missing or ignoring that's causing this problem?

KEEP IN MIND THAT I'M AWARE 5.5/-5.5 WILL NOT PRODUCE A CORRECT W. I'M USING THESE COORDS TO TEST SPAWNING BASE CUBES TO OCCUPY THE SAME SPACE.

Sarki241
  • 21
  • 3

1 Answers1

1

Shifting the part in the for loops from for($i=1;$i<=25;$i++) to for($i=0;$i<25;$i++) will stop there being a gap.

Previously when the loops started with $i=1, it meant that, in the first iteration, the lines with move -r ($i*±1) ($i*±1) 0; would move the first block by 1 diagonal from the starting coordinate.

Since we would like the first block in each branch not to be shifted from the starting coordinate, we want the line move -r ($i*±1) ($i*±1) 0; to have no effect in the first iteration. To fix it, we can have $i equal to 0 in the first iteration so that the line becomes move -r 0 0 0; for the first block.

And at the end you still want there to be 25 blocks in each branch, so the ending condition for the For loop is changed from $i<=25 to $i<25 to account for there being a shift at the start.

Here is the code (the only thing that is changed is the conditions for each of the 4 For loops.)

file -f -new;

//Specifies starting coordinates

int $xpnt1 = 5.5;
int $xpnt2 = -5.5;

//////////////////

for($i=0;$i<25;$i++) { //BRANCH 1, POINT 1, DIR L
    polyCube;
    move -ws $xpnt1 0 0;
    //select "pCube1";
    move -r ($i*1) ($i*1) 0;
    move -r $xpnt1 0 0 pCube1.scalePivot;
    }
for($i=0;$i<25;$i++) {//BRANCH 2, POINT 1, DIR R
    polyCube;
    move -ws $xpnt1 0 0;
    //select "pCube26";
    move -r ($i*-1) ($i*1) 0;
    move -r $xpnt1 0 0 pCube26.scalePivot;
    }
for($i=0;$i<25;$i++) {//BRANCH 3, POINT 2, DIR L
    polyCube;
    move -ws $xpnt2 0 0;
    //select "pCube51";
    move -r ($i*1) ($i*1) 0;
    move -r $xpnt2 0 0 pCube51.scalePivot;
    }
for($i=0;$i<25;$i++) { //BRANCH 4, POINT 2, DIR R
    polyCube;
    move -ws $xpnt2 0 0;
    //select "pCube76";
    move -r ($i*-1) ($i*1) 0;
    move -r $xpnt2 0 0 pCube76.scalePivot;
    }

Here is an image of what it now looks like and there are two blocks in the starting coordinates as expected.

  • I think I was a little long-winded in my explanation, please let me know if that is the case –  Dec 24 '16 at 03:32
  • I also just edited the question and added in some things that I worked out as I read over it a few times — just a few things that I didn't initially understand at first, that's all. (I would have commented on your question to mention this but not enough rep) If I've gotten anything mixed up, just let me know too. –  Dec 24 '16 at 06:20
  • Ah, I meant the edits as helpful & to save others time working things out but 'twas not approved. I suppose I was trying to explain what I understood from reading. First time too little, second time too much here. I guess I'll leave it there for now. –  Dec 26 '16 at 08:17
  • Tell me how my understanding is here: there are 4 sections of code for each stroke/branch that makes up the letter. Two of each stroke share the same 'root point' — so branch 1 and 2 will have the same starting coordinate, and branch 3 and 4 will share another starting coordinate. From the starting point, the four strokes are built from creating a series of cubes that are each then moved up diagonally by an increasing number of times — until there is a diagonal line of 25 cubes with each cube one unit to the side and one unit up from the one previous to it, which makes up a stroke. –  Dec 26 '16 at 08:21
  • And: both starting coordinates lie along the Y=0 and Z=0 line, and the x-coordinates of the two starting coordinates are specified in $xpnt1 and $xpnt2. And the strokes have been spawning in a diagonal line of 25 cubes as you wanted, but they weren't sharing their root point i.e. there is a gap at the starting coordinates instead of two cubes occupying the same space. If it helped me understand I'd like others to know but I suppose I can't know if that's what you wanted too. Oh well. (You can see I'm pretty new here.) –  Dec 26 '16 at 08:25