#assume a square grid gridWidth = 20 gridInc = 1 showAxes = True #set the range of x-values xmin = -gridWidth/2 xmax = gridWidth/2 #range of y-values ymin = -gridWidth/2 ymax = gridWidth/2 #calculate the range rangex = xmax - xmin rangey = ymax - ymin t = 0 initialRadius = 3 circleList = [] def setup(): global xscl, yscl, radius size(600,600) xscl = width/rangex yscl = -height/rangey colorMode(HSB, 360, 100, 100) radius = initialRadius #end function setup def draw(): global xscl, yscl, t, circleList, initialRadius, radius background(0, 0, 100) #white translate(width/2, height/2) grid(xscl, yscl) center = (-6, 0) inc = .01 radius = 3 # radius -= inc # if radius < .5: # radius = initialRadius + inc hsb = (90, 50, 50) drawCircle(center, initialRadius, hsb) #orbiting circle fill(60, 100, 100) dotRad = .075*radius x = (center[0] + (radius)*cos(t))*xscl y = (center[1] + (radius)*sin(t))*yscl #x = (center[0] + (radius))*xscl #y = (center[1] + (radius))*yscl ellipse(x, y, 2*dotRad*xscl, 2*dotRad*yscl) circleList = [y] + circleList[:249] #line stroke(240, 100, 100) line(x, y, 2*xscl, y) ellipse(2*xscl, y, 2*dotRad*xscl, 2*dotRad*yscl) #loop over circleList to leave a trail fill(0, 100, 100) noStroke() for i in range(len(circleList)): #small circle for trail: ellipse(i+ 2*xscl, circleList[i], .25*xscl, .25*xscl) t += .05 #end function draw def grid(xscl, yscl): #draws a grid for graphing #cyan lines strokeWeight(1) stroke(200, 100, 100) #lightBlue #vertical lines for i in range(xmin, xmax + 1): line(i*xscl, ymin*yscl, i*xscl, ymax*yscl) #horizontal lines for i in range(ymin, ymax + 1): line(xmin*xscl, i*yscl, ymax*xscl, i*yscl) if showAxes: axes() #end function grid def axes(): stroke(0, 0, 0) #black strokeWeight(2) #y axis line(0, ymin*yscl, 0, ymax*yscl) #x axis line(xmin*xscl, 0, xmax*xscl, 0) #end function axes def drawCircle(center, radius, hsb): h = center[0] * xscl k = center[1] * yscl radius *= xscl diam = radius*2 fill(hsb[0], hsb[1], hsb[2]) ellipse(h, k, diam, diam)