473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

circle loop?

10
I am trying to make some code which creates 5 set of circles. But this is the best i could do

00000(all red)
00000(all white)
00000(all red)
00000(all white)

Expand|Select|Wrap|Line Numbers
  1. from graphics import *
  2.  
  3. def main():
  4.     win = GraphWin("My Circle", 300, 300)
  5.     # count backwards
  6.     for k in range(6, 1, -1):
  7.         c = Circle(Point(150,150), 20*k)
  8.         # alternate
  9.         if k % 2 == 0:
  10.             c.setFill('red')
  11.         else:
  12.             c.setFill('white')
  13.         c.draw(win)
  14.  
  15.     win.getMouse() # pause for click in window
  16.     win.close()
  17.  
  18. main()
  19.  
Jun 20 '10 #1
9 2750
bvdet
2,851 Expert Mod 2GB
@cid11
cid11,

Do you have a question or does it not work the way you want?
Jun 20 '10 #2
cid11
10
sorry i posted in a hurry so none of tht make sense...it works but not the way i want it to.. now it does concentric circles.. but i want it to have seperate circles as i have tried to show below.. any help would be appreciated..

00000(all red)
00000(all white)
00000(all red)
00000(all white)
Jun 20 '10 #3
bvdet
2,851 Expert Mod 2GB
cid11,

You want the circles to be the same size organized in rows and columns. Alternate the color for each row. Calculate the size of the canvas based on the number of rows and columns and the size of the circle. Iterate on the number of rows and the number of columns in a nested for loop. Calculate the position of each circle using the row number (Y direction) and the column number (X direction).


Here's part of some sample code:
Expand|Select|Wrap|Line Numbers
  1.     win = GraphWin("My Circle", length, height)
  2.     for row in range(rows):
  3.         for col in range(cols):
  4.             x = size+col*size
  5.             y = size+row*size
  6.             c = Circle(Point(x,y), size/2)
Jun 20 '10 #4
cid11
10
@bvdet
so wht does the sample code u gave do?
Jun 20 '10 #5
bvdet
2,851 Expert Mod 2GB
The sample code does part of what I described in my previous post. Do understand what a for loop is?
Jun 20 '10 #6
cid11
10
yup i kinda understand what a for loop is.. but a bit rusty on python as i am retaking a module and had studied it in sept and just learned java.. what exactly would I have to do? to complete what i want the program to do?

thx
Jun 20 '10 #7
bvdet
2,851 Expert Mod 2GB
Before the sample code you need to calculate length and height and assign a value to size. After the sample code, you need an if/else block to decide on the color. The rest is the same as your original code.
Jun 20 '10 #8
cid11
10
So the length and height are to calculate the size of the graphic window according to the number of circles required? could I use the if and else from the previous code I gave? and do I keep my orignal code and add code to it and remove and add?

thx
Jun 20 '10 #9
cid11
10
for the size of the graphic window.. would it be

size of the window - ((number of circles + 1) * spacing)) / number of circles
Jun 23 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: rdeaton | last post by:
I need to design and code a Java program that calculates and prints the (D) diameter, the (C) circumference, or the (A) area of a circle, given the radius. The program inputs two data items: the...
0
by: Chua Wen Ching | last post by:
Hi.. just wonder i draw a circle in the picturebox1 1) and i want to store the circle in memory (only circle) when i store into bmp... i want to see the circle with transparent...
6
by: Craig Parsons | last post by:
Folks, I have an image of a circle, which I am trying to straighten out into a flat line. I am essentially wanting to look at the image, and read a straight line from the centre, and then plot...
14
by: Pythor | last post by:
I wrote the following code for a personal project. I need a function that will plot a filled circle in a two dimensional array. I found Bresenham's algorithm, and produced this code. Please tell...
9
by: saraaana | last post by:
Given the center and a point on the circle, you can use this formula to find the radius of the circle. Write a program that prompts the user to enter the center and a point on the circle. The program...
7
by: heterodon7 | last post by:
hello, can anyone give me a clue or simple code on task: for example we have in 2D an equation fo circle: (x - 3)^2 + (y - 4)^2 = 25. now the program must return for example a 40 pairs of...
5
by: defn noob | last post by:
Im using PyGame to draw images of graphs and trees. Howver right now i am looping using: while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() ...
14
by: DeadSilent | last post by:
I have this code and for some reason I keep getting an error where it says "exporting non-public type through public api ".. I'm not sure why this keeps happening but it does so for getCircleInfo /...
26
by: OzzyB | last post by:
This is another problem in the Zelle book. def drawCircle(win, centre, radius, colour): circle = Circle(radius) circle.setFill(colour) circle.setWidth(2) circle.draw(win) ...
3
by: cid11 | last post by:
how could I loop this to repeat the circles with one circle filled with red colour and one without? from graphics import * w = 300 h = 300 win = GraphWin("Red Circle", w, h)
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.