``````Program to make snowflake!

# Local graphics module. Must be in same folder as this
# program (or both on Desktop)
import ecs10graphics as gr
# Math module that comes with Python
import math

def pointOnCircle(f, r):
# f is fraction of the way around
# produces a point f way around circle c,r

# Use the global variable "center".
c = center
a = (2*math.pi)*f + math.pi/2.0
x = c[0] + math.cos(a)*r
y = c[1] + math.sin(a)*r
return [x,y]

def circleSegment(f1, f2, r1, r2):
# f1 is first fraction, r1 first radius
# f2 is second fraction, r2 second radius
# draws a segment from point f1, r1 to point f2, r2
p1 = pointOnCircle(f1, r1)
p2 = pointOnCircle(f2, r2)
gr.line(p1[0], p1[1], p2[0], p2[1], lineWidth=5)

# Start graphics window
gr.begin_graphics(500, 500, title="Snow Flakes",
background = gr.Color.dark_blue)

gr.set_Color(gr.Color.white)

center = [250,250]

for i in range(6):
frac = i/6.0

circleSegment(frac, frac, 0, 250)

# A line
circleSegment(frac+.05, frac+.05, 100, 200)
# It's mirror image
circleSegment(frac-.05, frac-.05, 100, 200)

# A line
circleSegment(frac+.05, frac, 200, 220)
# Its mirror image
circleSegment(frac-.05, frac, 200, 220)

# A line
circleSegment(frac+.05, frac+(1.0/12), 100, 100)
# Its mirror image
circleSegment(frac-.05, frac-(1.0/12), 100, 100)

# Display loop.
# Display the window, and wait for it to be closed
alive = True
while alive:
alive = gr.sleep(.05)

gr.end_graphics()

# Put new drawing code here, followed by another display loop.

# Start graphics window

raw_input("Press enter to exit:")``````

i was able to make a snowflake for my assignment but now im confused what to do now i need to make a function instead of writing out the program
here's the instructions:
Add a function drawBothLines() that draws a line and its mirror image. And change the program so that instead of calling circleSegment() six times in the block under the for loop, it calls drawBothLines() three times.

So drawBothLines() should draw two line segments instead of one, and it will need to figure out two points for each segment, for a total of four points. So it will have four calls to pointOnCircle(), and two calls to gr.line().

can i get some help please

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by vegaseat

I have are hard time understand why instructors use outdatet module like graphics.

It has to be much better to learn student basic Tkinter(graphical user interface) or another GUI toolkit.
That is useful othert than education purpose.

And getting help with graphics is hard,because very few has the graphics module.

A forum like this can make the unimaginative instructor's life pretty challenging. If every student gets the same homework, the homework handed in can look like an exact copy of everybody else's homework. One of the students may hand in original work, but who would that be?

Students are very internet savvy, and a short Google search can give them the answer to their homework. A good instructor should customize homework, maybe individualize it a little. Some instructors customize with these somewhat obscure modules.

Good instructors also visit the forums to see what is going on. We, who like to help solve problems, have to walk a fine line with homework questions, give hints, related examples and references, but not give total solutions. The goal is to help the student learn the language using his/her own efforts.

Edited by vegaseat: n/a