aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakobS1n <jakob@Jakobs-MacBook-Pro.local>2016-03-19 09:39:38 +0100
committerJakobS1n <jakob@Jakobs-MacBook-Pro.local>2016-03-23 15:45:17 +0100
commit9b7f5836ee3cf48e2f4ad8ac672f8aecc078dbe7 (patch)
treea14b93f5938038d514faf6c2ef38c96ff810b1c8
parenta31732c05157ea08655af7c10a328f43d09f67cc (diff)
downloadmath-draw-9b7f5836ee3cf48e2f4ad8ac672f8aecc078dbe7.tar.gz
math-draw-9b7f5836ee3cf48e2f4ad8ac672f8aecc078dbe7.zip
Stable
-rw-r--r--math-draw.py68
1 files changed, 36 insertions, 32 deletions
diff --git a/math-draw.py b/math-draw.py
index 544870e..ffa2231 100644
--- a/math-draw.py
+++ b/math-draw.py
@@ -18,9 +18,9 @@ def setup():
global currentHeading
center = (0, 0)
- radiusInt = 320
- pointsInt = 300
- multiplier = 3
+ radiusInt = 375
+ pointsInt = 700
+ multiplier = 2
pointsArray = [[0 for x in range(pointsInt)] for x in range(pointsInt)]
def drawPolygon(t, sideLength, numSides):
@@ -34,40 +34,45 @@ def drawCircle(anyTurtle, radius):
sideLength = circumference / 360
drawPolygon(anyTurtle, sideLength, 360)
-def calculatePoints(center, radius, intPoints, t):
+def calculatePoints(center, radius, intPoints, t, dots, update):
global differAngle
+
fullCircle = 360
differAngle = float(fullCircle) / float(pointsInt)
-
- foreachDivider = pointsInt
currDegree = 30 # sett til 90 for aa starte fra toppen
- test = 0
- print differAngle
- for i in xrange(foreachDivider):
- print i
+
+ for i in xrange(pointsInt):
t.setx(0)
t.sety(0)
t.setheading(currDegree)
- #t.pendown()
+
+ # t.pendown()
t.forward(radiusInt)
- t.penup()
+ # t.penup()
+
currDegree = currDegree - differAngle
- #t.dot()
- turtle.update()
+
+ if dots:
+ t.dot()
+ if update:
+ turtle.update()
+
print t.pos()
pointsArray[i][0] = t.pos()[0]
pointsArray[i][1] = t.pos()[1]
-def drawChord(t):
+def drawChord(t, update, animation):
global currentHeading
currentPoint = 1
t.setheading(0)
currentHeading = 0
- #t.tracer(True)
+
+ if animation:
+ t.tracer(True)
+
for i in pointsArray:
nextPoint = currentPoint*multiplier
- #print nextPoint
while True:
if nextPoint <= pointsInt:
@@ -75,12 +80,6 @@ def drawChord(t):
if nextPoint >= (pointsInt):
nextPoint = nextPoint - pointsInt
-
- #print nextPoint
-
- #if nextPoint >= pointsInt:
- #break
-
x = nextPoint-currentPoint
angleMultiplier = differAngle*x
chordLengthOne = (radiusInt**2+radiusInt**2-2*radiusInt*radiusInt*math.cos(math.radians(angleMultiplier))) # a = radius^2 + radius^2 - 2 * radius * radius * cosVinkel
@@ -91,18 +90,18 @@ def drawChord(t):
nextPointHeading = t.towards(pointsArray[nextPoint-1][0], pointsArray[nextPoint-1][1])
-
-
t.setheading(nextPointHeading)
t.setx(i[0])
t.sety(i[1])
- turtle.update()
+ if update:
+ turtle.update()
+
t.pendown()
t.forward(chordLengthOne)
t.penup()
- print currentPoint
+
currentPoint = currentPoint + 1
if currentPoint > (pointsInt):
break
@@ -117,7 +116,6 @@ def main():
# Skru av tegne-animasjon
wheel.tracer(False)
- #turtle.tracer(0, 0)
# Faa sirkelen til aa starte aa tegnes radius fra sentrum
wheel.penup()
@@ -131,10 +129,14 @@ def main():
wheel.pendown()
wheel.write("Radius: " + str(radiusInt))
wheel.penup()
- wheel.sety(currXY[1] + 10)
+ wheel.sety(currXY[1] - 10)
wheel.pendown()
wheel.write("Points: " + str(pointsInt))
wheel.penup()
+ wheel.sety(currXY[1] - 20)
+ wheel.pendown()
+ wheel.write("Multiplier: " + str(multiplier))
+ wheel.penup()
# Tegn sirkelen
wheel.goto(startPosition)
@@ -143,17 +145,19 @@ def main():
wheel.penup()
# Calculate points
- calculatePoints(center, radiusInt, pointsInt, wheel)
+ calculatePoints(center, radiusInt, pointsInt, wheel, False, False)
# tegn korder
- drawChord(wheel)
+ drawChord(wheel, True, False)
# Skjul skilpadden
wheel.hideturtle()
- turtle.update() # Refresh screen
+ # Refresh screen
+ turtle.update()
wn.exitonclick()
+
setup()
main() \ No newline at end of file