The basics of this code is this: moving imaginary points around, and rendering lines between them.
By turning Motor B, I can adjust how many points there are, between 1 and 16.
By turning Motor A, I (should) be able to adjust the speed of the points. I did this by writing speed = speed * (motor reading) with the motor reading always a number above zero, or else they wouldn't move at all. (I didn't have the +1 when I first wrote the code and they wouldn't move at all, but after adding the +1 they still don't move.) I just commented that section out and instead changed it (at the bottom) so that adjusting the motor adjusts the time between each frame.
Also, due to some crazy bug I haven't worked out, when there's less than 4 lines being drawn, it moves really, really fast.
Code: Select all
task main(){
int x1 = (Random(99));
int y1 = Random(63); // Set the first point anywhere on the screen
int x1_vel = (Random(3) + 1);// and give it two random velocities.
int y1_vel = (Random(3) + 1);
int x2 = Random(99);
int y2 = Random(63); // Same, but for the second point.
int x2_vel = (Random(3) + 1);
int y2_vel = (Random(3) + 1);
int x3 = Random(99);
int y3 = Random(63); // 3rd point, etc.
int x3_vel = (Random(3) + 1);
int y3_vel = (Random(3) + 1);
int x4 = Random(99);
int y4 = Random(63);
int x4_vel = (Random(3) + 1);
int y4_vel = (Random(3) + 1);
int x5 = Random(99);
int y5 = Random(63);
int x5_vel = (Random(3) + 1);
int y5_vel = (Random(3) + 1);
int x6 = Random(99);
int y6 = Random(63);
int x6_vel = (Random(3) + 1);
int y6_vel = (Random(3) + 1);
int x7 = Random(99);
int y7 = Random(63);
int x7_vel = (Random(3) + 1);
int y7_vel = (Random(3) + 1);
int x8 = Random(99);
int y8 = Random(63);
int x8_vel = (Random(3) + 1);
int y8_vel = (Random(3) + 1);
int x9 = Random(99);
int y9 = Random(63);
int x9_vel = (Random(3) + 1);
int y9_vel = (Random(3) + 1);
int x10 = Random(99);
int y10 = Random(63);
int x10_vel = (Random(3) + 1);
int y10_vel = (Random(3) + 1);
int x11 = Random(99);
int y11 = Random(63);
int x11_vel = (Random(3) + 1);
int y11_vel = (Random(3) + 1);
int x12 = Random(99);
int y12 = Random(63);
int x12_vel = (Random(3) + 1);
int y12_vel = (Random(3) + 1);
int x13 = Random(99);
int y13 = Random(63);
int x13_vel = (Random(3) + 1);
int y13_vel = (Random(3) + 1);
int x14 = Random(99);
int y14 = Random(63);
int x14_vel = (Random(3) + 1);
int y14_vel = (Random(3) + 1);
int x15 = Random(99);
int y15 = Random(63);
int x15_vel = (Random(3) + 1);
int y15_vel = (Random(3) + 1);
int x16 = Random(99);
int y16= Random(63);
int x16_vel = (Random(3) + 1);
int y16_vel = (Random(3) + 1);
while (true){
/* int x1_vel = x1_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int y1_vel = y1_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int x2_vel = x2_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int y2_vel = y2_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int x3_vel = x3_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int y3_vel = y3_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int x4_vel = x4_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int y4_vel = y4_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int x5_vel = x5_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int y5_vel = y5_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int x6_vel = x6_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int y6_vel = y6_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int x7_vel = x7_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int y7_vel = y7_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int x8_vel = x8_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int y8_vel = y8_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int x9_vel = x9_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int y9_vel = y9_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int x10_vel = x10_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int y10_vel = y10_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int x11_vel = x11_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int y11_vel = y11_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int x12_vel = x12_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int y12_vel = y12_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int x13_vel = x13_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int y13_vel = y13_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int x14_vel = x14_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int y14_vel = y14_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int x15_vel = x15_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int y15_vel = y15_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int x16_vel = x16_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
int y16_vel = y16_vel * (abs((MotorTachoCount(OUT_A)/10)) + 1);
*/
x1 = x1 + x1_vel;
x2 = x2 + x2_vel;
x3 = x3 + x3_vel;
x4 = x4 + x4_vel;
x5 = x5 + x5_vel;
x6 = x6 + x6_vel;
x7 = x7 + x7_vel;
x8 = x8 + x8_vel;
x9 = x9 + x9_vel;
x10 = x10 + x10_vel;
x11 = x11 + x11_vel;
x12 = x12 + x12_vel;
x13 = x13 + x13_vel;
x14 = x14 + x14_vel;
x15 = x15 + x15_vel;
x16 = x16 + x16_vel;
y1 = y1 + y1_vel;
y2 = y2 + y2_vel;
y3 = y3 + y3_vel;
y4 = y4 + y4_vel;
y5 = y5 + x5_vel;
y6 = y6 + y6_vel;
y7 = y7 + y7_vel;
y8 = y8 + y8_vel;
y9 = y9 + y9_vel;
y10 = y10 + y10_vel;
y11 = y11 + y11_vel;
y12 = y12 + y12_vel;
y13 = y13 + y13_vel;
y14 = y14 + y14_vel;
y15 = y15 + y15_vel;
y16 = y16 + y16_vel;
if (x1 >99){
x1 = 99;
x1_vel = (-x1_vel);
}
if (x1 <0){
x1 = 0;
x1_vel = (-x1_vel);
}
if (y1 >63){
y1 = 63;
y1_vel = (-y1_vel);
}
if (y1 <0){
y1 = 0;
y1_vel = (-y1_vel);
}
if (x2 >99){
x2 = 99;
x2_vel = (-x2_vel);
}
if (x2 <0){
x2 = 0;
x2_vel = (-x2_vel);
}
if (y2 >63){
y2 = 63;
y2_vel = (-y2_vel);
}
if (y2 <0){
y2 = 0;
y2_vel = (-y2_vel);
}
if (x3 >99){
x3 = 99;
x3_vel = (-x3_vel);
}
if (x3 <0){
x3 = 0;
x3_vel = (-x3_vel);
}
if (y3 >63){
y3 = 63;
y3_vel = (-y3_vel);
}
if (y3 <0){
y3 = 0;
y3_vel = (-y3_vel);
}
if (x4 >99){
x4 = 99;
x4_vel = (-x4_vel);
}
if (x4 <0){
x4 = 0;
x4_vel = (-x4_vel);
}
if (y4 >63){
y4 = 63;
y4_vel = (-y4_vel);
}
if (y4 <0){
y4 = 0;
y4_vel = (-y4_vel);
}
if (x5 >99){
x5 = 99;
x5_vel = (-x5_vel);
}
if (x5 <0){
x5 = 0;
x5_vel = (-x5_vel);
}
if (y5 >63){
y5 = 63;
y5_vel = (-y5_vel);
}
if (y5 <0){
y5 = 0;
y5_vel = (-y5_vel);
}
if (x6 >99){
x6 = 99;
x6_vel = (-x6_vel);
}
if (x6 <0){
x6 = 0;
x6_vel = (-x6_vel);
}
if (y6 >63){
y6 = 63;
y6_vel = (-y6_vel);
}
if (y6 <0){
y6 = 0;
y6_vel = (-y6_vel);
}
if (x7 >99){
x7 = 99;
x7_vel = (-x7_vel);
}
if (x7 <0){
x7 = 0;
x7_vel = (-x7_vel);
}
if (y7 >63){
y7 = 63;
y7_vel = (-y7_vel);
}
if (y7 <0){
y7 = 0;
y7_vel = (-y7_vel);
}
if (x8 >99){
x8 = 99;
x8_vel = (-x8_vel);
}
if (x8 <0){
x8 = 0;
x8_vel = (-x8_vel);
}
if (y8 >63){
y8 = 63;
y8_vel = (-y8_vel);
}
if (y8 <0){
y8 = 0;
y8_vel = (-y8_vel);
}
if (x9 >99){
x9 = 99;
x9_vel = (-x9_vel);
}
if (x9 <0){
x9 = 0;
x9_vel = (-x9_vel);
}
if (y9 >63){
y9 = 63;
y9_vel = (-y9_vel);
}
if (y9 <0){
y9 = 0;
y9_vel = (-y9_vel);
}
if (x10 >99){
x10 = 99;
x10_vel = (-x10_vel);
}
if (x10 <0){
x10 = 0;
x10_vel = (-x10_vel);
}
if (y10 >63){
y10 = 63;
y10_vel = (-y10_vel);
}
if (y10 <0){
y10 = 0;
y10_vel = (-y10_vel);
}
if (x11 >99){
x11 = 99;
x11_vel = (-x11_vel);
}
if (x11 <0){
x11 = 0;
x11_vel = (-x11_vel);
}
if (y11 >63){
y11 = 63;
y11_vel = (-y11_vel);
}
if (y11 <0){
y11 = 0;
y11_vel = (-y11_vel);
}
if (x12 >99){
x12 = 99;
x12_vel = (-x12_vel);
}
if (x12 <0){
x12 = 0;
x12_vel = (-x12_vel);
}
if (y12 >63){
y12 = 63;
y12_vel = (-y12_vel);
}
if (y12 <0){
y12 = 0;
y12_vel = (-y12_vel);
}
if (x13 >99){
x13 = 99;
x13_vel = (-x13_vel);
}
if (x13 <0){
x13 = 0;
x13_vel = (-x13_vel);
}
if (y13 >63){
y13 = 63;
y13_vel = (-y13_vel);
}
if (y13 <0){
y13 = 0;
y13_vel = (-y13_vel);
}
if (x14 >99){
x14 = 99;
x14_vel = (-x14_vel);
}
if (x14 <0){
x14 = 0;
x14_vel = (-x14_vel);
}
if (y14 >63){
y14 = 63;
y14_vel = (-y14_vel);
}
if (y14 <0){
y14 = 0;
y14_vel = (-y14_vel);
}
if (x15 >99){
x15 = 99;
x15_vel = (-x15_vel);
}
if (x15 <0){
x15 = 0;
x15_vel = (-x15_vel);
}
if (y15 >63){
y15 = 63;
y15_vel = (-y15_vel);
}
if (y15 <0){
y15 = 0;
y15_vel = (-y15_vel);
}
if (x16 >99){
x16 = 99;
x16_vel = (-x16_vel);
}
if (x16 <0){
x16 = 0;
x16_vel = (-x16_vel);
}
if (y16 >63){
y16 = 63;
y16_vel = (-y16_vel);
}
if (y16 <0){
y16 = 0;
y16_vel = (-y16_vel);
}
ClearScreen();
NumOut(1, 1, (MotorTachoCount(OUT_B)/10), 0);
NumOut(1, 9, (abs((MotorTachoCount(OUT_A)/10)) + 1), 0);
if ((MotorTachoCount(OUT_B)/10) > 0){
if (MotorTachoCount(OUT_B)/10 < 2){
LineOut(x1, y1, x1, y1, 0);
}
}
if ((MotorTachoCount(OUT_B)/10) > 1){
if (MotorTachoCount(OUT_B)/10 < 3){
LineOut(x1, y1, x2, y2, 0);
LineOut(x2, y2, x1, y1, 0);
}
}
if ((MotorTachoCount(OUT_B)/10) > 2){
if (MotorTachoCount(OUT_B)/10 < 4){
LineOut(x1, y1, x2, y2, 0);
LineOut(x2, y2, x3, y3, 0);
LineOut(x3, y3, x1, y1, 0);
}
}
if ((MotorTachoCount(OUT_B)/10) > 3){
if ((MotorTachoCount(OUT_B)/10) < 5){
LineOut(x1, y1, x2, y2, 0);
LineOut(x2, y2, x3, y3, 0);
LineOut(x3, y3, x4, y4, 0);
LineOut(x4, y4, x1, y1, 0);
}
if ((MotorTachoCount(OUT_B)/10) > 4){
if ((MotorTachoCount(OUT_B)/10) < 6){
LineOut(x1, y1, x2, y2, 0);
LineOut(x2, y2, x3, y3, 0);
LineOut(x3, y3, x4, y4, 0);
LineOut(x4, y4, x5, y5, 0);
LineOut(x5, y5, x1, y1, 0);
}
}
if ((MotorTachoCount(OUT_B)/10) > 5){
if ((MotorTachoCount(OUT_B)/10) < 7){
LineOut(x1, y1, x2, y2, 0);
LineOut(x2, y2, x3, y3, 0);
LineOut(x3, y3, x4, y4, 0);
LineOut(x4, y4, x5, y5, 0);
LineOut(x5, y5, x6, y6, 0);
LineOut(x6, y6, x1, y1, 0);
}
}
if ((MotorTachoCount(OUT_B)/10) > 6){
if ((MotorTachoCount(OUT_B)/10) < 8){
LineOut(x1, y1, x2, y2, 0);
LineOut(x2, y2, x3, y3, 0);
LineOut(x3, y3, x4, y4, 0);
LineOut(x4, y4, x5, y5, 0);
LineOut(x5, y5, x6, y6, 0);
LineOut(x6, y6, x7, y7, 0);
LineOut(x7, y7, x1, y1, 0);
}
}
if ((MotorTachoCount(OUT_B)/10) > 7){
if ((MotorTachoCount(OUT_B)/10) < 9){
LineOut(x1, y1, x2, y2, 0);
LineOut(x2, y2, x3, y3, 0);
LineOut(x3, y3, x4, y4, 0);
LineOut(x4, y4, x5, y5, 0);
LineOut(x5, y5, x6, y6, 0);
LineOut(x6, y6, x7, y7, 0);
LineOut(x7, y7, x8, y8, 0);
LineOut(x8, y8, x1, y1, 0);
}
}
if ((MotorTachoCount(OUT_B)/10) > 8){
if ((MotorTachoCount(OUT_B)/10) < 10){
LineOut(x1, y1, x2, y2, 0);
LineOut(x2, y2, x3, y3, 0);
LineOut(x3, y3, x4, y4, 0);
LineOut(x4, y4, x5, y5, 0);
LineOut(x5, y5, x6, y6, 0);
LineOut(x6, y6, x7, y7, 0);
LineOut(x7, y7, x8, y8, 0);
LineOut(x8, y8, x9, y9, 0);
LineOut(x9, y9, x1, y1, 0);
}
}
if ((MotorTachoCount(OUT_B)/10) > 9){
if ((MotorTachoCount(OUT_B)/10) < 11){
LineOut(x1, y1, x2, y2, 0);
LineOut(x2, y2, x3, y3, 0);
LineOut(x3, y3, x4, y4, 0);
LineOut(x4, y4, x5, y5, 0);
LineOut(x5, y5, x6, y6, 0);
LineOut(x6, y6, x7, y7, 0);
LineOut(x7, y7, x8, y8, 0);
LineOut(x8, y8, x9, y9, 0);
LineOut(x9, y9, x10, y10, 0);
LineOut(x10, y10, x1, y1, 0);
}
}
if ((MotorTachoCount(OUT_B)/10) > 10){
if ((MotorTachoCount(OUT_B)/10) < 12){
LineOut(x1, y1, x2, y2, 0);
LineOut(x2, y2, x3, y3, 0);
LineOut(x3, y3, x4, y4, 0);
LineOut(x4, y4, x5, y5, 0);
LineOut(x5, y5, x6, y6, 0);
LineOut(x6, y6, x7, y7, 0);
LineOut(x7, y7, x8, y8, 0);
LineOut(x8, y8, x9, y9, 0);
LineOut(x9, y9, x10, y10, 0);
LineOut(x10, y10, x11, y11, 0);
LineOut(x11, y11, x1, y1, 0);
}
}
if ((MotorTachoCount(OUT_B)/10) > 11){
if ((MotorTachoCount(OUT_B)/10) < 13){
LineOut(x1, y1, x2, y2, 0);
LineOut(x2, y2, x3, y3, 0);
LineOut(x3, y3, x4, y4, 0);
LineOut(x4, y4, x5, y5, 0);
LineOut(x5, y5, x6, y6, 0);
LineOut(x6, y6, x7, y7, 0);
LineOut(x7, y7, x8, y8, 0);
LineOut(x8, y8, x9, y9, 0);
LineOut(x9, y9, x10, y10, 0);
LineOut(x10, y10, x11, y11, 0);
LineOut(x11, y11, x12, y12, 0);
LineOut(x12, y12, x1, y1, 0);
}
}
if ((MotorTachoCount(OUT_B)/10) > 12){
if ((MotorTachoCount(OUT_B)/10) < 14){
LineOut(x1, y1, x2, y2, 0);
LineOut(x2, y2, x3, y3, 0);
LineOut(x3, y3, x4, y4, 0);
LineOut(x4, y4, x5, y5, 0);
LineOut(x5, y5, x6, y6, 0);
LineOut(x6, y6, x7, y7, 0);
LineOut(x7, y7, x8, y8, 0);
LineOut(x8, y8, x9, y9, 0);
LineOut(x9, y9, x10, y10, 0);
LineOut(x10, y10, x11, y11, 0);
LineOut(x11, y11, x12, y12, 0);
LineOut(x12, y12, x13, y13, 0);
LineOut(x13, y13, x1, y1, 0);
}
}
if ((MotorTachoCount(OUT_B)/10) > 13){
if ((MotorTachoCount(OUT_B)/10) < 15){
LineOut(x1, y1, x2, y2, 0);
LineOut(x2, y2, x3, y3, 0);
LineOut(x3, y3, x4, y4, 0);
LineOut(x4, y4, x5, y5, 0);
LineOut(x5, y5, x6, y6, 0);
LineOut(x6, y6, x7, y7, 0);
LineOut(x7, y7, x8, y8, 0);
LineOut(x8, y8, x9, y9, 0);
LineOut(x9, y9, x10, y10, 0);
LineOut(x10, y10, x11, y11, 0);
LineOut(x11, y11, x12, y12, 0);
LineOut(x12, y12, x13, y13, 0);
LineOut(x13, y13, x14, y14, 0);
LineOut(x14, y14, x1, y1, 0);
}
}
if ((MotorTachoCount(OUT_B)/10) > 14){
if ((MotorTachoCount(OUT_B)/10) < 16){
LineOut(x1, y1, x2, y2, 0);
LineOut(x2, y2, x3, y3, 0);
LineOut(x3, y3, x4, y4, 0);
LineOut(x4, y4, x5, y5, 0);
LineOut(x5, y5, x6, y6, 0);
LineOut(x6, y6, x7, y7, 0);
LineOut(x7, y7, x8, y8, 0);
LineOut(x8, y8, x9, y9, 0);
LineOut(x9, y9, x10, y10, 0);
LineOut(x10, y10, x11, y11, 0);
LineOut(x11, y11, x12, y12, 0);
LineOut(x12, y12, x13, y13, 0);
LineOut(x13, y13, x14, y14, 0);
LineOut(x14, y14, x15, y15, 0);
LineOut(x15, y15, x1, y1, 0);
}
}
if ((MotorTachoCount(OUT_B)/10) > 15){
LineOut(x1, y1, x2, y2, 0);
LineOut(x2, y2, x3, y3, 0);
LineOut(x3, y3, x4, y4, 0);
LineOut(x4, y4, x5, y5, 0);
LineOut(x5, y5, x6, y6, 0);
LineOut(x6, y6, x7, y7, 0);
LineOut(x7, y7, x8, y8, 0);
LineOut(x8, y8, x9, y9, 0);
LineOut(x9, y9, x10, y10, 0);
LineOut(x10, y10, x11, y11, 0);
LineOut(x11, y11, x12, y12, 0);
LineOut(x12, y12, x13, y13, 0);
LineOut(x13, y13, x14, y14, 0);
LineOut(x14, y14, x15, y15, 0);
LineOut(x15, y15, x16, y16, 0);
LineOut(x16, y16, x1, y1, 0);
}
Wait((abs((MotorTachoCount(OUT_A)/5)) + 1));
}
}
}