I am trying to write a program so when it runs, it makes one circle of say 50 radius, then the next one would be 45 and so on going down by 5 each time.
What I am unsure of is how can I do this with a loop or is it impossible. I look forwards to any help that I can get.
Are you planning to use Tkinter or some other GUI interface? Your radiuses can be defined in a list comprehension. - >>> [rad for rad in range(50, 0, -5)]
-
[50, 45, 40, 35, 30, 25, 20, 15, 10, 5]
-
>>>
Using Tkinter, you can create a canvas and place circles on the canvas. Here's an example: - from Tkinter import *
-
-
class Point(object):
-
def __init__(self, x=0.0, y=0.0):
-
self.x = float(x)
-
self.y = float(y)
-
def __add__(self, other):
-
return Point(self.x+other.x, self.y+other.y)
-
-
def drawCircles(columns, rows, radius=100, space=0):
-
root = Tk()
-
canvas_width = columns*(radius*2+space)
-
canvas_height = rows*(radius*2+space)
-
-
w = Canvas(root, width=canvas_width, height=canvas_height)
-
# create a black background
-
w.create_rectangle(0,0,canvas_width,canvas_height,fill="black")
-
# calculate UL and LR coordinates in column 1, row 1
-
pt1 = Point(space/2.0, space/2.0)
-
pt2 = pt1+Point(radius*2, radius*2)
-
for i in range(0, columns):
-
for j in range(0, rows):
-
# xy = UL.x, UL.y, LR.x, LR.y
-
xy = pt1.x+i*(radius*2+space), \
-
pt1.y+j*(radius*2+space), \
-
pt2.x+i*(radius*2+space), \
-
pt2.y+j*(radius*2+space)
-
# create a circle with red fill
-
w.create_oval(xy, fill='red')
-
-
w.pack()
-
root.mainloop()
-
-
if __name__ == '__main__':
-
drawCircles(4, 3, 125)
-
drawCircles(4, 2, 75, 20)
-
drawCircles(4, 2, 75, 100)
-
drawCircles(24, 16, 12, 6)
-
1 1913 bvdet 2,851
Expert Mod 2GB
Are you planning to use Tkinter or some other GUI interface? Your radiuses can be defined in a list comprehension. - >>> [rad for rad in range(50, 0, -5)]
-
[50, 45, 40, 35, 30, 25, 20, 15, 10, 5]
-
>>>
Using Tkinter, you can create a canvas and place circles on the canvas. Here's an example: - from Tkinter import *
-
-
class Point(object):
-
def __init__(self, x=0.0, y=0.0):
-
self.x = float(x)
-
self.y = float(y)
-
def __add__(self, other):
-
return Point(self.x+other.x, self.y+other.y)
-
-
def drawCircles(columns, rows, radius=100, space=0):
-
root = Tk()
-
canvas_width = columns*(radius*2+space)
-
canvas_height = rows*(radius*2+space)
-
-
w = Canvas(root, width=canvas_width, height=canvas_height)
-
# create a black background
-
w.create_rectangle(0,0,canvas_width,canvas_height,fill="black")
-
# calculate UL and LR coordinates in column 1, row 1
-
pt1 = Point(space/2.0, space/2.0)
-
pt2 = pt1+Point(radius*2, radius*2)
-
for i in range(0, columns):
-
for j in range(0, rows):
-
# xy = UL.x, UL.y, LR.x, LR.y
-
xy = pt1.x+i*(radius*2+space), \
-
pt1.y+j*(radius*2+space), \
-
pt2.x+i*(radius*2+space), \
-
pt2.y+j*(radius*2+space)
-
# create a circle with red fill
-
w.create_oval(xy, fill='red')
-
-
w.pack()
-
root.mainloop()
-
-
if __name__ == '__main__':
-
drawCircles(4, 3, 125)
-
drawCircles(4, 2, 75, 20)
-
drawCircles(4, 2, 75, 100)
-
drawCircles(24, 16, 12, 6)
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Gregory |
last post by:
Hello,
I've managed to build two web pages, one that can display images with
associated text data in a table, and one that can resize and display images
without the text. I'd like to resize the...
|
by: Remi Villatel |
last post by:
Hi there,
There is always a "nice" way to do things in Python but this time I can't
find one.
What I'm trying to achieve is a conditionnal loop of which the condition
test would be done at...
|
by: Terry Olsen |
last post by:
How do I loop back to the beginning of a for/next loop before getting to
the end of it? Isn't there an "iterate" command or something like that?
For Each This in That
...code
if This = False...
|
by: triplejump24 |
last post by:
Hey. Im trying to make program that basically displays all the prime
numbers. I need to use bool and for but im not quite sure if i have this
right. So far i have this bunch of a mess but can...
|
by: Crcullen3916 |
last post by:
Hi, I have this assignment that I have almost finished except I have one problem. I'm having trouble making my for loop find the sum of the first n odd numbers ( n being the variable in which a value...
|
by: a.mil |
last post by:
I am programming for code-speed, not for ansi or other nice-guy stuff
and I encountered the following problem:
When I have a for loop like this:
b=b0;
for (a=0,i=0;i<100;i++,b--) {
if (b%i)...
|
by: danielkun |
last post by:
I'm building a simple slideshow and would like to exchange the FOR loop below into an infinite loop that will start over with picure 1 when picture 5 has been shown.
Im still new to C and I hope...
|
by: z1 |
last post by:
hi-
i wrote a program with java using eclipse and i think i remember it used
70,000k in the process list in windows in task manager. i understand that
there is some eclipse runtime overhead...
|
by: ronparker |
last post by:
First of all, thank you for taking the time to read my question. With the following code, what I have done is make a database in MySQL and created a table using python. I then imported an excel...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |