We have project that draws fully connected 24-gon. Use colorsys library to gradually change the hue of lines as they get longer.
Daily Archives: 10/14/2020
Fully Connected 24-gon
Refer to fully connected octagon before drawing this fully connected 24-gon.
Fully Connected Octagon
Use nested for loop and list to draw the following fully connected octagon.
Center Connected Hexagon (Source Code)
Draw a regular hexagon that have vertices connected to the center. Use for loop to draw this shape.
Source Code:
hideturtle()
for angle in range(0,360,60):
up()
goto(0,0)
seth(angle)
down()
fd(300)
up()
goto(300,0)
seth(120)
down()
for _ in range(6):
fd(300)
left(60)
Real Stock Price Chart (GOOG, AAPL, SPY) with Source Code
Download historical stock prices for Google, Apple, and SPY. Read the file and draw the stock charts for these companies. The following figures show the stock prices for these companies:
Source Code:
import turtle
with open('spy.us.txt','r') as fin:
lines = fin.readlines()
n = len(lines)-1
prices = [None]*n
for i in range(1,len(lines)):
row = lines[i].split(',')
prices[i-1] = float(row[4])
minprice, maxprice = min(prices),max(prices)
screen = turtle.Screen()
screen.title('Stock Price From File - PythonTurtle.Academy')
screen.setup(1000,1000)
screen.setworldcoordinates(0,minprice*0.9,n,maxprice*1.1)
turtle.speed(0)
turtle.hideturtle()
turtle.up()
turtle.goto(0,prices[0])
turtle.down()
for i in range(1,n):
turtle.goto(i,prices[i])