mardi 21 avril 2020

I need 100 Dots to appear on my screen but how?

I'm using python to code a very simple picture of 1000 dots on a screen like a starry night but I don't know what went wrong. Please help!

import random
import simplegui

dotcount = 0
x = random.randint(1,600)
y = random.randint(1,600)
r = random.randint(1,255)
g = random.randint(1,255)
b = random.randint(1,255)

def draw_handler(canvas):
    canvas.draw_point([100,1], "Yellow")
    dotcount = 0
    x = random.randint(1,600)
    y = random.randint(1,600)
    while dotcount in range (1000):
        r = random.randint(1,255)
        g = random.randint(1,255)
        b = random.randint(1,255)
        colors = "rgb(" + str(r) + str(g) + str(b) + ")"
        canvas.draw_point([x,y],colors)
        dotcount = dotcount + 1

frame = simplegui.create_frame("1000 Dots", 650, 650)
frame.set_draw_handler(draw_handler)
frame.start()

Edit: I made this in py3 codeskulptor




Aucun commentaire:

Enregistrer un commentaire