from visual import *
sec = arrow(color = color.cyan, pos = vector(0,0,0), axis = vector(0,3,0))
minu = arrow(color = color.red, pos = vector(0,0,0), axis = vector(0,2,0))
hr = arrow(color = color.magenta, pos = vector(0,0,0), axis = vector(1,0,0))
angle = 0
angle2 = 0
while True:
    rate(1000)
    angle = angle - 0.01
    sec.axis.x = cos(angle)*3
    sec.axis.y = sin(angle)*3

while (sec.axis == vector(0,3,0)):
    angle2 = angle2 - 0.01
    minu.axis.x = cos(angle)*2
    minu.axis.y = sin(angle)*2

when I tape this code the second loop for some reason doesnt work could you please tell me how can I fix it?

Your first while has no way to exit.

I dont want it to exit, i want the second loop to repeat every time when the first arrow makes a full turn ;)

So you want to embed the second loop inside the first loop? That's not the way it is now.

yeah? so whats the way could you please tell me? ;)

As your second while does not alter the variable used in the continuation condition for the loop, I guess you mean an if statement instead of while loop, and it would need to be indented to same level as other statements inside the while

I did like that and nothing happened
I mean that second arrow is still not moving after the first one finishes full turn

from visual import *
sec = arrow(color = color.cyan, pos = vector(0,0,0), axis = vector(0,3,0))
minu = arrow(color = color.red, pos = vector(0,0,0), axis = vector(0,2,0))
hr = arrow(color = color.magenta, pos = vector(0,0,0), axis = vector(1,0,0))
angle = 0
angle2 = 0


while True:

    rate(1000)
    angle = angle - 0.01
    sec.axis.x = cos(angle)*3
    sec.axis.y = sin(angle)*3
    if (sec.axis == vector(0,3,0)):
           angle2 = angle2 - 0.01
           minu.axis.x = cos(angle2)*2
           minu.axis.y = sin(angle2)*2

thats what i typed

And exactly i Want a second arrow to move just when the first one finishes full turn and again when it finishes another full turn - it is similar to a clock.

sec.axis most likely never becomes exactly same as the vector you compare to. You could make comparison based on sec.axis.x, which would work. Real solution would be integer counter increased circularly by modulo arithmetic and multiplication by turning step for drawing.

If I may comment (even if it is a bit late), I would add a recommendation to apply named constants more extensively than you have. You have a number of places where you are using magic numbers which are used repeatedly. It is good to get into the habit of saving any numeric constants in a variable (Python doesn't have constants per se) rather than having to figure out why that particular value was needed at a given point later on.

I've also noticed that you use the rate() function to set the speed of the clock. This isn't the correct function to use; it only affects the frame rate, not the speed at which the loop runs. I would recommend using sleep() instead, as it is more likely to be accurate to a second (it still won't be perfectly accurate, but it will be closer), and it also avoids busy waiting.

Finally, You presumably want to have the starting values for angle and angle2 (which really should have better names) to the value for the 12 O'Clock position, which would be 2π radians. Again, making this a named constant would make sense, as you'll use it in multiple cases. Similarly, you will want to advance the second and minute hands by 1/60th of the circle each time you move them, and the hour hand by 1/24th.

Here are the constants I recommend using for this. I would actually recommend making a class ClockArrow, as a subclass of arrow, but that's probably more advanced than you'd be ready for. Normally, I wouldn't do so much for a querent, but this is something I feel might be a worthwhile learning experience.

from visual import *

cycle = 2 * pi
sixtieth = cycle / 60.0
twentyfourth = cycle / 24.0
clockCenter = vector(0,0,0)
secLen = 3
minLen = 2
hrLen = 1

centerAngle = (pi / 2.0)

sec = arrow(color = color.cyan, pos = clockCenter, axis = vector(0, secLen, 0))
minu = arrow(color = color.red, pos = clockCenter, axis = vector(0, minLen, 0))
hr = arrow(color = color.magenta, pos = clockCenter, axis = vector(0, hrLen, 0))
secAngle = minAngle = hrAngle = centerAngle
secCount = minCount = hrCount = 0

while True:
    sleep(1)
    secCount += 1
    secAngle -= sixtieth
    sec.axis.x = cos(secAngle) * secLen
    sec.axis.y = sin(secAngle) * secLen
    if secCount == 60:
           secCount = 0
           minCount += 1
           sec.axis.x = centerAngle
           minAngle -= sixtieth
           minu.axis.x = cos(minAngle) * minLen
           minu.axis.y = sin(minAngle) * minLen
           if minCount == 60:
               minCount = 0
               hrCount += 1
               minAngle = centerAngle
               hrAngle -= twentyfourth
               hr.axis.x = cos(hrAngle) * hrLen
               hr.axis.y = sin(hrAngle) * hrLen
               if hrCount == 24:
                   hrCount = 0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.