How do I run multiple protocols at once?












-1















I need to run Wait, Begin, and Float all at the same time where
Wait is a timer, Begin sets up the bubbles and Float makes the bubbles rise




  • V is for setting off the timer


  • W is for making the bubbles rise


  • X is for the spawn location


  • Y is for slightly moving left/right


  • Z is for the bubble being used


Code:



import turtle
import random
from random import randint
turtle.bgcolor("black")
turtle.setup(500,500)
Await = randint(1,4)/2
Bwait = randint(1,4)/2 + Await
Cwait = randint(1,4)/2 + Bwait
Dwait = randint(1,4)/2 + Cwait
Ewait = randint(1,4)/2 + Dwait
Fwait = randint(1,4)/2 + Ewait
Gwait = randint(1,4)/2 + Fwait
Hwait = randint(1,4)/2 + Gwait
Iwait = randint(1,4)/2 + Hwait
Jwait = randint(1,4)/2 + Iwait
Kwait = randint(1,4)/2 + Jwait
Lwait = randint(1,4)/2 + Kwait
Mwait = randint(1,4)/2 + Lwait
Nwait = randint(1,4)/2 + Mwait
Owait = randint(1,4)/2 + Nwait
A = turtle.Turtle()
B = turtle.Turtle()
C = turtle.Turtle()
D = turtle.Turtle()
E = turtle.Turtle()
F = turtle.Turtle()
G = turtle.Turtle()
H = turtle.Turtle()
I = turtle.Turtle()
J = turtle.Turtle()
K = turtle.Turtle()
L = turtle.Turtle()
M = turtle.Turtle()
N = turtle.Turtle()
O = turtle.Turtle()
A.shapesize(.5)
B.shapesize(.5)
C.shapesize(.5)
D.shapesize(.5)
E.shapesize(.5)
F.shapesize(.5)
G.shapesize(.5)
H.shapesize(.5)
I.shapesize(.5)
J.shapesize(.5)
K.shapesize(.5)
L.shapesize(.5)
M.shapesize(.5)
N.shapesize(.5)
O.shapesize(.5)
def Float(z):
w = 1
while w < 520:
z.forward(1)
z.left(90)
y = randint(-1,1)
z.forward(y)
z.right(90)
w = w + 1
def Begin(z):
x = randint(-250,250)
z.shape('circle')
z.color('black')
z.penup()
z.right(90)
z.forward(260)
z.left(90)
z.forward(x)
z.left(90)
z.color('red')
z.speed(.5)
Float(z)
def Wait(v):
if v == Await:
Begin(A)
Wait(Await + .1)
if v == Bwait:
Begin(B)
Wait(Bwait + .1)
if v == Cwait:
Begin(C)
Wait(Cwait + .1)
if v == Dwait:
Begin(D)
Wait(Dwait + .1)
if v == Ewait:
Begin(E)
Wait(Ewait + .1)
if v == Fwait:
Begin(F)
Wait(Fwait + .1)
if v == Gwait:
Begin(G)
Wait(Gwait + .1)
if v == Hwait:
Begin(H)
Wait(Hwait + .1)
if v == Iwait:
Begin(I)
Wait(Iwait + .1)
if v == Jwait:
Begin(J)
Wait(Jwait + .1)
if v == Kwait:
Begin(K)
Wait(Kwait + .1)
if v == Lwait:
Begin(L)
Wait(Lwait + .1)
if v == Mwait:
Begin(M)
Wait(Mwait + .1)
if v == Nwait:
Begin(N)
Wait(Nwait + .1)
if v == Owait:
Begin(O)
v = v + .1
Wait(0)









share|improve this question




















  • 1





    It's not clear from your code exactly what you are trying to achieve here. Before we start trying to debug the code, can you explain at a higher level what the aim of the code is. What do you want to do/happen?

    – match
    Jan 1 at 18:14











  • Unrelated to your problem, but any time you are tempted to have variables like this, you should be thinking "no, this is wrong, I need a data structure instead". This is a perfect job for an array, or possibly dict. And most times when you want to gather several pieces of related data, like turtle object and associated wait time, and also some related behaviour, like beginning, floating and waiting, you might consider a class to bind them together.

    – Amadan
    Jan 1 at 18:29













  • I'm trying to make a rising bubbles animation using a timer. It's for a science fair project

    – Jefflit
    Jan 2 at 22:18
















-1















I need to run Wait, Begin, and Float all at the same time where
Wait is a timer, Begin sets up the bubbles and Float makes the bubbles rise




  • V is for setting off the timer


  • W is for making the bubbles rise


  • X is for the spawn location


  • Y is for slightly moving left/right


  • Z is for the bubble being used


Code:



import turtle
import random
from random import randint
turtle.bgcolor("black")
turtle.setup(500,500)
Await = randint(1,4)/2
Bwait = randint(1,4)/2 + Await
Cwait = randint(1,4)/2 + Bwait
Dwait = randint(1,4)/2 + Cwait
Ewait = randint(1,4)/2 + Dwait
Fwait = randint(1,4)/2 + Ewait
Gwait = randint(1,4)/2 + Fwait
Hwait = randint(1,4)/2 + Gwait
Iwait = randint(1,4)/2 + Hwait
Jwait = randint(1,4)/2 + Iwait
Kwait = randint(1,4)/2 + Jwait
Lwait = randint(1,4)/2 + Kwait
Mwait = randint(1,4)/2 + Lwait
Nwait = randint(1,4)/2 + Mwait
Owait = randint(1,4)/2 + Nwait
A = turtle.Turtle()
B = turtle.Turtle()
C = turtle.Turtle()
D = turtle.Turtle()
E = turtle.Turtle()
F = turtle.Turtle()
G = turtle.Turtle()
H = turtle.Turtle()
I = turtle.Turtle()
J = turtle.Turtle()
K = turtle.Turtle()
L = turtle.Turtle()
M = turtle.Turtle()
N = turtle.Turtle()
O = turtle.Turtle()
A.shapesize(.5)
B.shapesize(.5)
C.shapesize(.5)
D.shapesize(.5)
E.shapesize(.5)
F.shapesize(.5)
G.shapesize(.5)
H.shapesize(.5)
I.shapesize(.5)
J.shapesize(.5)
K.shapesize(.5)
L.shapesize(.5)
M.shapesize(.5)
N.shapesize(.5)
O.shapesize(.5)
def Float(z):
w = 1
while w < 520:
z.forward(1)
z.left(90)
y = randint(-1,1)
z.forward(y)
z.right(90)
w = w + 1
def Begin(z):
x = randint(-250,250)
z.shape('circle')
z.color('black')
z.penup()
z.right(90)
z.forward(260)
z.left(90)
z.forward(x)
z.left(90)
z.color('red')
z.speed(.5)
Float(z)
def Wait(v):
if v == Await:
Begin(A)
Wait(Await + .1)
if v == Bwait:
Begin(B)
Wait(Bwait + .1)
if v == Cwait:
Begin(C)
Wait(Cwait + .1)
if v == Dwait:
Begin(D)
Wait(Dwait + .1)
if v == Ewait:
Begin(E)
Wait(Ewait + .1)
if v == Fwait:
Begin(F)
Wait(Fwait + .1)
if v == Gwait:
Begin(G)
Wait(Gwait + .1)
if v == Hwait:
Begin(H)
Wait(Hwait + .1)
if v == Iwait:
Begin(I)
Wait(Iwait + .1)
if v == Jwait:
Begin(J)
Wait(Jwait + .1)
if v == Kwait:
Begin(K)
Wait(Kwait + .1)
if v == Lwait:
Begin(L)
Wait(Lwait + .1)
if v == Mwait:
Begin(M)
Wait(Mwait + .1)
if v == Nwait:
Begin(N)
Wait(Nwait + .1)
if v == Owait:
Begin(O)
v = v + .1
Wait(0)









share|improve this question




















  • 1





    It's not clear from your code exactly what you are trying to achieve here. Before we start trying to debug the code, can you explain at a higher level what the aim of the code is. What do you want to do/happen?

    – match
    Jan 1 at 18:14











  • Unrelated to your problem, but any time you are tempted to have variables like this, you should be thinking "no, this is wrong, I need a data structure instead". This is a perfect job for an array, or possibly dict. And most times when you want to gather several pieces of related data, like turtle object and associated wait time, and also some related behaviour, like beginning, floating and waiting, you might consider a class to bind them together.

    – Amadan
    Jan 1 at 18:29













  • I'm trying to make a rising bubbles animation using a timer. It's for a science fair project

    – Jefflit
    Jan 2 at 22:18














-1












-1








-1








I need to run Wait, Begin, and Float all at the same time where
Wait is a timer, Begin sets up the bubbles and Float makes the bubbles rise




  • V is for setting off the timer


  • W is for making the bubbles rise


  • X is for the spawn location


  • Y is for slightly moving left/right


  • Z is for the bubble being used


Code:



import turtle
import random
from random import randint
turtle.bgcolor("black")
turtle.setup(500,500)
Await = randint(1,4)/2
Bwait = randint(1,4)/2 + Await
Cwait = randint(1,4)/2 + Bwait
Dwait = randint(1,4)/2 + Cwait
Ewait = randint(1,4)/2 + Dwait
Fwait = randint(1,4)/2 + Ewait
Gwait = randint(1,4)/2 + Fwait
Hwait = randint(1,4)/2 + Gwait
Iwait = randint(1,4)/2 + Hwait
Jwait = randint(1,4)/2 + Iwait
Kwait = randint(1,4)/2 + Jwait
Lwait = randint(1,4)/2 + Kwait
Mwait = randint(1,4)/2 + Lwait
Nwait = randint(1,4)/2 + Mwait
Owait = randint(1,4)/2 + Nwait
A = turtle.Turtle()
B = turtle.Turtle()
C = turtle.Turtle()
D = turtle.Turtle()
E = turtle.Turtle()
F = turtle.Turtle()
G = turtle.Turtle()
H = turtle.Turtle()
I = turtle.Turtle()
J = turtle.Turtle()
K = turtle.Turtle()
L = turtle.Turtle()
M = turtle.Turtle()
N = turtle.Turtle()
O = turtle.Turtle()
A.shapesize(.5)
B.shapesize(.5)
C.shapesize(.5)
D.shapesize(.5)
E.shapesize(.5)
F.shapesize(.5)
G.shapesize(.5)
H.shapesize(.5)
I.shapesize(.5)
J.shapesize(.5)
K.shapesize(.5)
L.shapesize(.5)
M.shapesize(.5)
N.shapesize(.5)
O.shapesize(.5)
def Float(z):
w = 1
while w < 520:
z.forward(1)
z.left(90)
y = randint(-1,1)
z.forward(y)
z.right(90)
w = w + 1
def Begin(z):
x = randint(-250,250)
z.shape('circle')
z.color('black')
z.penup()
z.right(90)
z.forward(260)
z.left(90)
z.forward(x)
z.left(90)
z.color('red')
z.speed(.5)
Float(z)
def Wait(v):
if v == Await:
Begin(A)
Wait(Await + .1)
if v == Bwait:
Begin(B)
Wait(Bwait + .1)
if v == Cwait:
Begin(C)
Wait(Cwait + .1)
if v == Dwait:
Begin(D)
Wait(Dwait + .1)
if v == Ewait:
Begin(E)
Wait(Ewait + .1)
if v == Fwait:
Begin(F)
Wait(Fwait + .1)
if v == Gwait:
Begin(G)
Wait(Gwait + .1)
if v == Hwait:
Begin(H)
Wait(Hwait + .1)
if v == Iwait:
Begin(I)
Wait(Iwait + .1)
if v == Jwait:
Begin(J)
Wait(Jwait + .1)
if v == Kwait:
Begin(K)
Wait(Kwait + .1)
if v == Lwait:
Begin(L)
Wait(Lwait + .1)
if v == Mwait:
Begin(M)
Wait(Mwait + .1)
if v == Nwait:
Begin(N)
Wait(Nwait + .1)
if v == Owait:
Begin(O)
v = v + .1
Wait(0)









share|improve this question
















I need to run Wait, Begin, and Float all at the same time where
Wait is a timer, Begin sets up the bubbles and Float makes the bubbles rise




  • V is for setting off the timer


  • W is for making the bubbles rise


  • X is for the spawn location


  • Y is for slightly moving left/right


  • Z is for the bubble being used


Code:



import turtle
import random
from random import randint
turtle.bgcolor("black")
turtle.setup(500,500)
Await = randint(1,4)/2
Bwait = randint(1,4)/2 + Await
Cwait = randint(1,4)/2 + Bwait
Dwait = randint(1,4)/2 + Cwait
Ewait = randint(1,4)/2 + Dwait
Fwait = randint(1,4)/2 + Ewait
Gwait = randint(1,4)/2 + Fwait
Hwait = randint(1,4)/2 + Gwait
Iwait = randint(1,4)/2 + Hwait
Jwait = randint(1,4)/2 + Iwait
Kwait = randint(1,4)/2 + Jwait
Lwait = randint(1,4)/2 + Kwait
Mwait = randint(1,4)/2 + Lwait
Nwait = randint(1,4)/2 + Mwait
Owait = randint(1,4)/2 + Nwait
A = turtle.Turtle()
B = turtle.Turtle()
C = turtle.Turtle()
D = turtle.Turtle()
E = turtle.Turtle()
F = turtle.Turtle()
G = turtle.Turtle()
H = turtle.Turtle()
I = turtle.Turtle()
J = turtle.Turtle()
K = turtle.Turtle()
L = turtle.Turtle()
M = turtle.Turtle()
N = turtle.Turtle()
O = turtle.Turtle()
A.shapesize(.5)
B.shapesize(.5)
C.shapesize(.5)
D.shapesize(.5)
E.shapesize(.5)
F.shapesize(.5)
G.shapesize(.5)
H.shapesize(.5)
I.shapesize(.5)
J.shapesize(.5)
K.shapesize(.5)
L.shapesize(.5)
M.shapesize(.5)
N.shapesize(.5)
O.shapesize(.5)
def Float(z):
w = 1
while w < 520:
z.forward(1)
z.left(90)
y = randint(-1,1)
z.forward(y)
z.right(90)
w = w + 1
def Begin(z):
x = randint(-250,250)
z.shape('circle')
z.color('black')
z.penup()
z.right(90)
z.forward(260)
z.left(90)
z.forward(x)
z.left(90)
z.color('red')
z.speed(.5)
Float(z)
def Wait(v):
if v == Await:
Begin(A)
Wait(Await + .1)
if v == Bwait:
Begin(B)
Wait(Bwait + .1)
if v == Cwait:
Begin(C)
Wait(Cwait + .1)
if v == Dwait:
Begin(D)
Wait(Dwait + .1)
if v == Ewait:
Begin(E)
Wait(Ewait + .1)
if v == Fwait:
Begin(F)
Wait(Fwait + .1)
if v == Gwait:
Begin(G)
Wait(Gwait + .1)
if v == Hwait:
Begin(H)
Wait(Hwait + .1)
if v == Iwait:
Begin(I)
Wait(Iwait + .1)
if v == Jwait:
Begin(J)
Wait(Jwait + .1)
if v == Kwait:
Begin(K)
Wait(Kwait + .1)
if v == Lwait:
Begin(L)
Wait(Lwait + .1)
if v == Mwait:
Begin(M)
Wait(Mwait + .1)
if v == Nwait:
Begin(N)
Wait(Nwait + .1)
if v == Owait:
Begin(O)
v = v + .1
Wait(0)






python turtle-graphics






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 4:55









cdlane

19.2k21145




19.2k21145










asked Jan 1 at 17:22









JefflitJefflit

41




41








  • 1





    It's not clear from your code exactly what you are trying to achieve here. Before we start trying to debug the code, can you explain at a higher level what the aim of the code is. What do you want to do/happen?

    – match
    Jan 1 at 18:14











  • Unrelated to your problem, but any time you are tempted to have variables like this, you should be thinking "no, this is wrong, I need a data structure instead". This is a perfect job for an array, or possibly dict. And most times when you want to gather several pieces of related data, like turtle object and associated wait time, and also some related behaviour, like beginning, floating and waiting, you might consider a class to bind them together.

    – Amadan
    Jan 1 at 18:29













  • I'm trying to make a rising bubbles animation using a timer. It's for a science fair project

    – Jefflit
    Jan 2 at 22:18














  • 1





    It's not clear from your code exactly what you are trying to achieve here. Before we start trying to debug the code, can you explain at a higher level what the aim of the code is. What do you want to do/happen?

    – match
    Jan 1 at 18:14











  • Unrelated to your problem, but any time you are tempted to have variables like this, you should be thinking "no, this is wrong, I need a data structure instead". This is a perfect job for an array, or possibly dict. And most times when you want to gather several pieces of related data, like turtle object and associated wait time, and also some related behaviour, like beginning, floating and waiting, you might consider a class to bind them together.

    – Amadan
    Jan 1 at 18:29













  • I'm trying to make a rising bubbles animation using a timer. It's for a science fair project

    – Jefflit
    Jan 2 at 22:18








1




1





It's not clear from your code exactly what you are trying to achieve here. Before we start trying to debug the code, can you explain at a higher level what the aim of the code is. What do you want to do/happen?

– match
Jan 1 at 18:14





It's not clear from your code exactly what you are trying to achieve here. Before we start trying to debug the code, can you explain at a higher level what the aim of the code is. What do you want to do/happen?

– match
Jan 1 at 18:14













Unrelated to your problem, but any time you are tempted to have variables like this, you should be thinking "no, this is wrong, I need a data structure instead". This is a perfect job for an array, or possibly dict. And most times when you want to gather several pieces of related data, like turtle object and associated wait time, and also some related behaviour, like beginning, floating and waiting, you might consider a class to bind them together.

– Amadan
Jan 1 at 18:29







Unrelated to your problem, but any time you are tempted to have variables like this, you should be thinking "no, this is wrong, I need a data structure instead". This is a perfect job for an array, or possibly dict. And most times when you want to gather several pieces of related data, like turtle object and associated wait time, and also some related behaviour, like beginning, floating and waiting, you might consider a class to bind them together.

– Amadan
Jan 1 at 18:29















I'm trying to make a rising bubbles animation using a timer. It's for a science fair project

– Jefflit
Jan 2 at 22:18





I'm trying to make a rising bubbles animation using a timer. It's for a science fair project

– Jefflit
Jan 2 at 22:18












2 Answers
2






active

oldest

votes


















0














You are incrementing v by one every time the function Wait() is called once. It looks like you want it to loop? It's hard to understand. This makes the code actually run, but I don't know if that's what you want it to do.



def Wait(v):
while True:
if v == Await:
Begin(A)
Wait(Await + .1)
if v == Bwait:
Begin(B)
Wait(Bwait + .1)
if v == Cwait:
Begin(C)
Wait(Cwait + .1)
if v == Dwait:
Begin(D)
Wait(Dwait + .1)
if v == Ewait:
Begin(E)
Wait(Ewait + .1)
if v == Fwait:
Begin(F)
Wait(Fwait + .1)
if v == Gwait:
Begin(G)
Wait(Gwait + .1)
if v == Hwait:
Begin(H)
Wait(Hwait + .1)
if v == Iwait:
Begin(I)
Wait(Iwait + .1)
if v == Jwait:
Begin(J)
Wait(Jwait + .1)
if v == Kwait:
Begin(K)
Wait(Kwait + .1)
if v == Lwait:
Begin(L)
Wait(Lwait + .1)
if v == Mwait:
Begin(M)
Wait(Mwait + .1)
if v == Nwait:
Begin(N)
Wait(Nwait + .1)
if v == Owait:
Begin(O)
v = v + .1


Regardless of what you want it to do. Look into classes. You're creating a lot of repetitive data. Classes are like templates of data, that you can then use easily. I rewrote the code for you:



class Turtle:
def __init__(self, wait, turtle):
self.wait = wait
self.turtle = turtle
self.turtle.shapesize(.5)
self.v = 0
def Wait(self, time):
if self.v == 2:
return
self.Begin()
self.v += 1
self.Wait(self.v)
def Begin(self):
x = randint(-250,250)
self.turtle.shape('circle')
self.turtle.color('black')
self.turtle.penup()
self.turtle.right(90)
self.turtle.forward(260)
self.turtle.left(90)
self.turtle.forward(x)
self.turtle.left(90)
self.turtle.color('red')
self.turtle.speed(.5)
self.Float()
def Float(self):
w = 1
while w < 520:
self.turtle.forward(1)
self.turtle.left(90)
y = randint(-1,1)
self.turtle.forward(y)
self.turtle.right(90)
w = w + 1



turtles =
prev_wait = 0
for x in range(20):
wait = randint(1,4)/2 + prev_wait
turtles.append(Turtle(wait, turtle.Turtle()))
prev_wait = wait

for turtle in turtles:
turtle.Wait(0)





share|improve this answer
























  • I want the timer to loop and end when it spawns the last bubble. It needs to keep running while Begin runs. Thanks tho

    – Jefflit
    Jan 2 at 22:39



















0














Below is an implementation of what I believe your code tries to do. It's likely more complicated than you're prepared to take on at this point, but I hope it gives you ideas of how to rework your own code. Particularly in the concept of a bubble prototype and cloning to avoid much redundant code:



from turtle import Screen, Turtle
from random import randint

BUBBLE_COUNT = 9
BUBBLE_DIAMETER = 10
WIDTH, HEIGHT = 500, 500
CURSOR_SIZE = 20

def bubbles_rise():
for start_time, bubble in bubbles:
if time > start_time and bubble.ycor() < HEIGHT/2 + BUBBLE_DIAMETER:
bubble.forward(1)

dx = randint(-1, 1)

if dx != 0:
bubble.setx(bubble.xcor() + dx)

if any(bubble.ycor() < HEIGHT/2 + BUBBLE_DIAMETER for _, bubble in bubbles):
screen.ontimer(bubbles_rise, 10)
else:
print("Finished rising!")

def bubbles_launch():
global time

for start_time, bubble in bubbles:
if time >= start_time:
bubble.showturtle()

if any(start_time > time for start_time, _ in bubbles):
time += 0.1
screen.ontimer(bubbles_launch, 100)
else:
print("Finished launching!")

screen = Screen()
screen.setup(WIDTH, HEIGHT)
screen.bgcolor("black")

bubble_prototype = Turtle('circle', visible=False)
bubble_prototype.penup()
bubble_prototype.sety(-HEIGHT/2 - BUBBLE_DIAMETER) # just out of sight
bubble_prototype.color('red')
bubble_prototype.shapesize(BUBBLE_DIAMETER / CURSOR_SIZE)
bubble_prototype.setheading(90)
bubble_prototype.speed('fastest')

bubbles =

start_time = 0

for _ in range(BUBBLE_COUNT):
start_time += randint(1, 4) / 2
new_bubble = bubble_prototype.clone()
new_bubble.setx(randint(BUBBLE_DIAMETER - WIDTH/2, WIDTH/2 - BUBBLE_DIAMETER)) # just inside
bubbles.append((start_time, new_bubble))

time = 0

bubbles_rise()
bubbles_launch()

screen.mainloop()





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997460%2fhow-do-i-run-multiple-protocols-at-once%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You are incrementing v by one every time the function Wait() is called once. It looks like you want it to loop? It's hard to understand. This makes the code actually run, but I don't know if that's what you want it to do.



    def Wait(v):
    while True:
    if v == Await:
    Begin(A)
    Wait(Await + .1)
    if v == Bwait:
    Begin(B)
    Wait(Bwait + .1)
    if v == Cwait:
    Begin(C)
    Wait(Cwait + .1)
    if v == Dwait:
    Begin(D)
    Wait(Dwait + .1)
    if v == Ewait:
    Begin(E)
    Wait(Ewait + .1)
    if v == Fwait:
    Begin(F)
    Wait(Fwait + .1)
    if v == Gwait:
    Begin(G)
    Wait(Gwait + .1)
    if v == Hwait:
    Begin(H)
    Wait(Hwait + .1)
    if v == Iwait:
    Begin(I)
    Wait(Iwait + .1)
    if v == Jwait:
    Begin(J)
    Wait(Jwait + .1)
    if v == Kwait:
    Begin(K)
    Wait(Kwait + .1)
    if v == Lwait:
    Begin(L)
    Wait(Lwait + .1)
    if v == Mwait:
    Begin(M)
    Wait(Mwait + .1)
    if v == Nwait:
    Begin(N)
    Wait(Nwait + .1)
    if v == Owait:
    Begin(O)
    v = v + .1


    Regardless of what you want it to do. Look into classes. You're creating a lot of repetitive data. Classes are like templates of data, that you can then use easily. I rewrote the code for you:



    class Turtle:
    def __init__(self, wait, turtle):
    self.wait = wait
    self.turtle = turtle
    self.turtle.shapesize(.5)
    self.v = 0
    def Wait(self, time):
    if self.v == 2:
    return
    self.Begin()
    self.v += 1
    self.Wait(self.v)
    def Begin(self):
    x = randint(-250,250)
    self.turtle.shape('circle')
    self.turtle.color('black')
    self.turtle.penup()
    self.turtle.right(90)
    self.turtle.forward(260)
    self.turtle.left(90)
    self.turtle.forward(x)
    self.turtle.left(90)
    self.turtle.color('red')
    self.turtle.speed(.5)
    self.Float()
    def Float(self):
    w = 1
    while w < 520:
    self.turtle.forward(1)
    self.turtle.left(90)
    y = randint(-1,1)
    self.turtle.forward(y)
    self.turtle.right(90)
    w = w + 1



    turtles =
    prev_wait = 0
    for x in range(20):
    wait = randint(1,4)/2 + prev_wait
    turtles.append(Turtle(wait, turtle.Turtle()))
    prev_wait = wait

    for turtle in turtles:
    turtle.Wait(0)





    share|improve this answer
























    • I want the timer to loop and end when it spawns the last bubble. It needs to keep running while Begin runs. Thanks tho

      – Jefflit
      Jan 2 at 22:39
















    0














    You are incrementing v by one every time the function Wait() is called once. It looks like you want it to loop? It's hard to understand. This makes the code actually run, but I don't know if that's what you want it to do.



    def Wait(v):
    while True:
    if v == Await:
    Begin(A)
    Wait(Await + .1)
    if v == Bwait:
    Begin(B)
    Wait(Bwait + .1)
    if v == Cwait:
    Begin(C)
    Wait(Cwait + .1)
    if v == Dwait:
    Begin(D)
    Wait(Dwait + .1)
    if v == Ewait:
    Begin(E)
    Wait(Ewait + .1)
    if v == Fwait:
    Begin(F)
    Wait(Fwait + .1)
    if v == Gwait:
    Begin(G)
    Wait(Gwait + .1)
    if v == Hwait:
    Begin(H)
    Wait(Hwait + .1)
    if v == Iwait:
    Begin(I)
    Wait(Iwait + .1)
    if v == Jwait:
    Begin(J)
    Wait(Jwait + .1)
    if v == Kwait:
    Begin(K)
    Wait(Kwait + .1)
    if v == Lwait:
    Begin(L)
    Wait(Lwait + .1)
    if v == Mwait:
    Begin(M)
    Wait(Mwait + .1)
    if v == Nwait:
    Begin(N)
    Wait(Nwait + .1)
    if v == Owait:
    Begin(O)
    v = v + .1


    Regardless of what you want it to do. Look into classes. You're creating a lot of repetitive data. Classes are like templates of data, that you can then use easily. I rewrote the code for you:



    class Turtle:
    def __init__(self, wait, turtle):
    self.wait = wait
    self.turtle = turtle
    self.turtle.shapesize(.5)
    self.v = 0
    def Wait(self, time):
    if self.v == 2:
    return
    self.Begin()
    self.v += 1
    self.Wait(self.v)
    def Begin(self):
    x = randint(-250,250)
    self.turtle.shape('circle')
    self.turtle.color('black')
    self.turtle.penup()
    self.turtle.right(90)
    self.turtle.forward(260)
    self.turtle.left(90)
    self.turtle.forward(x)
    self.turtle.left(90)
    self.turtle.color('red')
    self.turtle.speed(.5)
    self.Float()
    def Float(self):
    w = 1
    while w < 520:
    self.turtle.forward(1)
    self.turtle.left(90)
    y = randint(-1,1)
    self.turtle.forward(y)
    self.turtle.right(90)
    w = w + 1



    turtles =
    prev_wait = 0
    for x in range(20):
    wait = randint(1,4)/2 + prev_wait
    turtles.append(Turtle(wait, turtle.Turtle()))
    prev_wait = wait

    for turtle in turtles:
    turtle.Wait(0)





    share|improve this answer
























    • I want the timer to loop and end when it spawns the last bubble. It needs to keep running while Begin runs. Thanks tho

      – Jefflit
      Jan 2 at 22:39














    0












    0








    0







    You are incrementing v by one every time the function Wait() is called once. It looks like you want it to loop? It's hard to understand. This makes the code actually run, but I don't know if that's what you want it to do.



    def Wait(v):
    while True:
    if v == Await:
    Begin(A)
    Wait(Await + .1)
    if v == Bwait:
    Begin(B)
    Wait(Bwait + .1)
    if v == Cwait:
    Begin(C)
    Wait(Cwait + .1)
    if v == Dwait:
    Begin(D)
    Wait(Dwait + .1)
    if v == Ewait:
    Begin(E)
    Wait(Ewait + .1)
    if v == Fwait:
    Begin(F)
    Wait(Fwait + .1)
    if v == Gwait:
    Begin(G)
    Wait(Gwait + .1)
    if v == Hwait:
    Begin(H)
    Wait(Hwait + .1)
    if v == Iwait:
    Begin(I)
    Wait(Iwait + .1)
    if v == Jwait:
    Begin(J)
    Wait(Jwait + .1)
    if v == Kwait:
    Begin(K)
    Wait(Kwait + .1)
    if v == Lwait:
    Begin(L)
    Wait(Lwait + .1)
    if v == Mwait:
    Begin(M)
    Wait(Mwait + .1)
    if v == Nwait:
    Begin(N)
    Wait(Nwait + .1)
    if v == Owait:
    Begin(O)
    v = v + .1


    Regardless of what you want it to do. Look into classes. You're creating a lot of repetitive data. Classes are like templates of data, that you can then use easily. I rewrote the code for you:



    class Turtle:
    def __init__(self, wait, turtle):
    self.wait = wait
    self.turtle = turtle
    self.turtle.shapesize(.5)
    self.v = 0
    def Wait(self, time):
    if self.v == 2:
    return
    self.Begin()
    self.v += 1
    self.Wait(self.v)
    def Begin(self):
    x = randint(-250,250)
    self.turtle.shape('circle')
    self.turtle.color('black')
    self.turtle.penup()
    self.turtle.right(90)
    self.turtle.forward(260)
    self.turtle.left(90)
    self.turtle.forward(x)
    self.turtle.left(90)
    self.turtle.color('red')
    self.turtle.speed(.5)
    self.Float()
    def Float(self):
    w = 1
    while w < 520:
    self.turtle.forward(1)
    self.turtle.left(90)
    y = randint(-1,1)
    self.turtle.forward(y)
    self.turtle.right(90)
    w = w + 1



    turtles =
    prev_wait = 0
    for x in range(20):
    wait = randint(1,4)/2 + prev_wait
    turtles.append(Turtle(wait, turtle.Turtle()))
    prev_wait = wait

    for turtle in turtles:
    turtle.Wait(0)





    share|improve this answer













    You are incrementing v by one every time the function Wait() is called once. It looks like you want it to loop? It's hard to understand. This makes the code actually run, but I don't know if that's what you want it to do.



    def Wait(v):
    while True:
    if v == Await:
    Begin(A)
    Wait(Await + .1)
    if v == Bwait:
    Begin(B)
    Wait(Bwait + .1)
    if v == Cwait:
    Begin(C)
    Wait(Cwait + .1)
    if v == Dwait:
    Begin(D)
    Wait(Dwait + .1)
    if v == Ewait:
    Begin(E)
    Wait(Ewait + .1)
    if v == Fwait:
    Begin(F)
    Wait(Fwait + .1)
    if v == Gwait:
    Begin(G)
    Wait(Gwait + .1)
    if v == Hwait:
    Begin(H)
    Wait(Hwait + .1)
    if v == Iwait:
    Begin(I)
    Wait(Iwait + .1)
    if v == Jwait:
    Begin(J)
    Wait(Jwait + .1)
    if v == Kwait:
    Begin(K)
    Wait(Kwait + .1)
    if v == Lwait:
    Begin(L)
    Wait(Lwait + .1)
    if v == Mwait:
    Begin(M)
    Wait(Mwait + .1)
    if v == Nwait:
    Begin(N)
    Wait(Nwait + .1)
    if v == Owait:
    Begin(O)
    v = v + .1


    Regardless of what you want it to do. Look into classes. You're creating a lot of repetitive data. Classes are like templates of data, that you can then use easily. I rewrote the code for you:



    class Turtle:
    def __init__(self, wait, turtle):
    self.wait = wait
    self.turtle = turtle
    self.turtle.shapesize(.5)
    self.v = 0
    def Wait(self, time):
    if self.v == 2:
    return
    self.Begin()
    self.v += 1
    self.Wait(self.v)
    def Begin(self):
    x = randint(-250,250)
    self.turtle.shape('circle')
    self.turtle.color('black')
    self.turtle.penup()
    self.turtle.right(90)
    self.turtle.forward(260)
    self.turtle.left(90)
    self.turtle.forward(x)
    self.turtle.left(90)
    self.turtle.color('red')
    self.turtle.speed(.5)
    self.Float()
    def Float(self):
    w = 1
    while w < 520:
    self.turtle.forward(1)
    self.turtle.left(90)
    y = randint(-1,1)
    self.turtle.forward(y)
    self.turtle.right(90)
    w = w + 1



    turtles =
    prev_wait = 0
    for x in range(20):
    wait = randint(1,4)/2 + prev_wait
    turtles.append(Turtle(wait, turtle.Turtle()))
    prev_wait = wait

    for turtle in turtles:
    turtle.Wait(0)






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 1 at 18:22









    koralkoral

    384




    384













    • I want the timer to loop and end when it spawns the last bubble. It needs to keep running while Begin runs. Thanks tho

      – Jefflit
      Jan 2 at 22:39



















    • I want the timer to loop and end when it spawns the last bubble. It needs to keep running while Begin runs. Thanks tho

      – Jefflit
      Jan 2 at 22:39

















    I want the timer to loop and end when it spawns the last bubble. It needs to keep running while Begin runs. Thanks tho

    – Jefflit
    Jan 2 at 22:39





    I want the timer to loop and end when it spawns the last bubble. It needs to keep running while Begin runs. Thanks tho

    – Jefflit
    Jan 2 at 22:39













    0














    Below is an implementation of what I believe your code tries to do. It's likely more complicated than you're prepared to take on at this point, but I hope it gives you ideas of how to rework your own code. Particularly in the concept of a bubble prototype and cloning to avoid much redundant code:



    from turtle import Screen, Turtle
    from random import randint

    BUBBLE_COUNT = 9
    BUBBLE_DIAMETER = 10
    WIDTH, HEIGHT = 500, 500
    CURSOR_SIZE = 20

    def bubbles_rise():
    for start_time, bubble in bubbles:
    if time > start_time and bubble.ycor() < HEIGHT/2 + BUBBLE_DIAMETER:
    bubble.forward(1)

    dx = randint(-1, 1)

    if dx != 0:
    bubble.setx(bubble.xcor() + dx)

    if any(bubble.ycor() < HEIGHT/2 + BUBBLE_DIAMETER for _, bubble in bubbles):
    screen.ontimer(bubbles_rise, 10)
    else:
    print("Finished rising!")

    def bubbles_launch():
    global time

    for start_time, bubble in bubbles:
    if time >= start_time:
    bubble.showturtle()

    if any(start_time > time for start_time, _ in bubbles):
    time += 0.1
    screen.ontimer(bubbles_launch, 100)
    else:
    print("Finished launching!")

    screen = Screen()
    screen.setup(WIDTH, HEIGHT)
    screen.bgcolor("black")

    bubble_prototype = Turtle('circle', visible=False)
    bubble_prototype.penup()
    bubble_prototype.sety(-HEIGHT/2 - BUBBLE_DIAMETER) # just out of sight
    bubble_prototype.color('red')
    bubble_prototype.shapesize(BUBBLE_DIAMETER / CURSOR_SIZE)
    bubble_prototype.setheading(90)
    bubble_prototype.speed('fastest')

    bubbles =

    start_time = 0

    for _ in range(BUBBLE_COUNT):
    start_time += randint(1, 4) / 2
    new_bubble = bubble_prototype.clone()
    new_bubble.setx(randint(BUBBLE_DIAMETER - WIDTH/2, WIDTH/2 - BUBBLE_DIAMETER)) # just inside
    bubbles.append((start_time, new_bubble))

    time = 0

    bubbles_rise()
    bubbles_launch()

    screen.mainloop()





    share|improve this answer




























      0














      Below is an implementation of what I believe your code tries to do. It's likely more complicated than you're prepared to take on at this point, but I hope it gives you ideas of how to rework your own code. Particularly in the concept of a bubble prototype and cloning to avoid much redundant code:



      from turtle import Screen, Turtle
      from random import randint

      BUBBLE_COUNT = 9
      BUBBLE_DIAMETER = 10
      WIDTH, HEIGHT = 500, 500
      CURSOR_SIZE = 20

      def bubbles_rise():
      for start_time, bubble in bubbles:
      if time > start_time and bubble.ycor() < HEIGHT/2 + BUBBLE_DIAMETER:
      bubble.forward(1)

      dx = randint(-1, 1)

      if dx != 0:
      bubble.setx(bubble.xcor() + dx)

      if any(bubble.ycor() < HEIGHT/2 + BUBBLE_DIAMETER for _, bubble in bubbles):
      screen.ontimer(bubbles_rise, 10)
      else:
      print("Finished rising!")

      def bubbles_launch():
      global time

      for start_time, bubble in bubbles:
      if time >= start_time:
      bubble.showturtle()

      if any(start_time > time for start_time, _ in bubbles):
      time += 0.1
      screen.ontimer(bubbles_launch, 100)
      else:
      print("Finished launching!")

      screen = Screen()
      screen.setup(WIDTH, HEIGHT)
      screen.bgcolor("black")

      bubble_prototype = Turtle('circle', visible=False)
      bubble_prototype.penup()
      bubble_prototype.sety(-HEIGHT/2 - BUBBLE_DIAMETER) # just out of sight
      bubble_prototype.color('red')
      bubble_prototype.shapesize(BUBBLE_DIAMETER / CURSOR_SIZE)
      bubble_prototype.setheading(90)
      bubble_prototype.speed('fastest')

      bubbles =

      start_time = 0

      for _ in range(BUBBLE_COUNT):
      start_time += randint(1, 4) / 2
      new_bubble = bubble_prototype.clone()
      new_bubble.setx(randint(BUBBLE_DIAMETER - WIDTH/2, WIDTH/2 - BUBBLE_DIAMETER)) # just inside
      bubbles.append((start_time, new_bubble))

      time = 0

      bubbles_rise()
      bubbles_launch()

      screen.mainloop()





      share|improve this answer


























        0












        0








        0







        Below is an implementation of what I believe your code tries to do. It's likely more complicated than you're prepared to take on at this point, but I hope it gives you ideas of how to rework your own code. Particularly in the concept of a bubble prototype and cloning to avoid much redundant code:



        from turtle import Screen, Turtle
        from random import randint

        BUBBLE_COUNT = 9
        BUBBLE_DIAMETER = 10
        WIDTH, HEIGHT = 500, 500
        CURSOR_SIZE = 20

        def bubbles_rise():
        for start_time, bubble in bubbles:
        if time > start_time and bubble.ycor() < HEIGHT/2 + BUBBLE_DIAMETER:
        bubble.forward(1)

        dx = randint(-1, 1)

        if dx != 0:
        bubble.setx(bubble.xcor() + dx)

        if any(bubble.ycor() < HEIGHT/2 + BUBBLE_DIAMETER for _, bubble in bubbles):
        screen.ontimer(bubbles_rise, 10)
        else:
        print("Finished rising!")

        def bubbles_launch():
        global time

        for start_time, bubble in bubbles:
        if time >= start_time:
        bubble.showturtle()

        if any(start_time > time for start_time, _ in bubbles):
        time += 0.1
        screen.ontimer(bubbles_launch, 100)
        else:
        print("Finished launching!")

        screen = Screen()
        screen.setup(WIDTH, HEIGHT)
        screen.bgcolor("black")

        bubble_prototype = Turtle('circle', visible=False)
        bubble_prototype.penup()
        bubble_prototype.sety(-HEIGHT/2 - BUBBLE_DIAMETER) # just out of sight
        bubble_prototype.color('red')
        bubble_prototype.shapesize(BUBBLE_DIAMETER / CURSOR_SIZE)
        bubble_prototype.setheading(90)
        bubble_prototype.speed('fastest')

        bubbles =

        start_time = 0

        for _ in range(BUBBLE_COUNT):
        start_time += randint(1, 4) / 2
        new_bubble = bubble_prototype.clone()
        new_bubble.setx(randint(BUBBLE_DIAMETER - WIDTH/2, WIDTH/2 - BUBBLE_DIAMETER)) # just inside
        bubbles.append((start_time, new_bubble))

        time = 0

        bubbles_rise()
        bubbles_launch()

        screen.mainloop()





        share|improve this answer













        Below is an implementation of what I believe your code tries to do. It's likely more complicated than you're prepared to take on at this point, but I hope it gives you ideas of how to rework your own code. Particularly in the concept of a bubble prototype and cloning to avoid much redundant code:



        from turtle import Screen, Turtle
        from random import randint

        BUBBLE_COUNT = 9
        BUBBLE_DIAMETER = 10
        WIDTH, HEIGHT = 500, 500
        CURSOR_SIZE = 20

        def bubbles_rise():
        for start_time, bubble in bubbles:
        if time > start_time and bubble.ycor() < HEIGHT/2 + BUBBLE_DIAMETER:
        bubble.forward(1)

        dx = randint(-1, 1)

        if dx != 0:
        bubble.setx(bubble.xcor() + dx)

        if any(bubble.ycor() < HEIGHT/2 + BUBBLE_DIAMETER for _, bubble in bubbles):
        screen.ontimer(bubbles_rise, 10)
        else:
        print("Finished rising!")

        def bubbles_launch():
        global time

        for start_time, bubble in bubbles:
        if time >= start_time:
        bubble.showturtle()

        if any(start_time > time for start_time, _ in bubbles):
        time += 0.1
        screen.ontimer(bubbles_launch, 100)
        else:
        print("Finished launching!")

        screen = Screen()
        screen.setup(WIDTH, HEIGHT)
        screen.bgcolor("black")

        bubble_prototype = Turtle('circle', visible=False)
        bubble_prototype.penup()
        bubble_prototype.sety(-HEIGHT/2 - BUBBLE_DIAMETER) # just out of sight
        bubble_prototype.color('red')
        bubble_prototype.shapesize(BUBBLE_DIAMETER / CURSOR_SIZE)
        bubble_prototype.setheading(90)
        bubble_prototype.speed('fastest')

        bubbles =

        start_time = 0

        for _ in range(BUBBLE_COUNT):
        start_time += randint(1, 4) / 2
        new_bubble = bubble_prototype.clone()
        new_bubble.setx(randint(BUBBLE_DIAMETER - WIDTH/2, WIDTH/2 - BUBBLE_DIAMETER)) # just inside
        bubbles.append((start_time, new_bubble))

        time = 0

        bubbles_rise()
        bubbles_launch()

        screen.mainloop()






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 4:52









        cdlanecdlane

        19.2k21145




        19.2k21145






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997460%2fhow-do-i-run-multiple-protocols-at-once%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            Npm cannot find a required file even through it is in the searched directory

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith