#CrazyQuiltPrj_S7 ''' File: Site: Path: Date: 10/2/19 Author: Comments: TODO: ''' import random from SpecialClasses import * #wide-scoped variables go here #adjust your canvas size if desired, here canvas_width = 600 canvas_height = 600 #adjust for background refresh and grid here shouldRefreshBackground = True shouldShowGrid = True t = 0 def setup(): global shouldRefreshBackground, shouldShowGrid, numSquares, count, inc global white, my_red, my_blue, my_green, yellow, black, lightGray, orange global bgColr, myRate global t, tinc global h, k global position, velocity, diamX, diamY, hueCycle, opacityCycle, jitterCycleX, jitterCycleY, velXCycle1, velYCycle1 global circ1, myBCs size(canvas_width, canvas_height) #color mode and basic colors colorMode(HSB, 360, 100, 100, 100) #hue, saturation, brightness, alpha white = color(0, 0, 100) #red, green and blue are reserved words in Processing my_red = color(0, 100, 100) my_blue = color(240, 80, 60) my_green = color(120, 60, 40) yellow = color(60, 100, 100) black = color(0, 0, 0) lightGray = color(0, 0, 95) #sketch settings myRate = 60 # default is 60 frames/second bgColr = yellow frameRate(myRate) background(white) #additional setup variables/functions here msg = "===Welcome to Crazy Quilt!===" print(msg) tinc = 1 shouldShowGrid = True; h = 0 k = 0 count = 0 #eureka: it makes a difference whether you say 11 or 11.0 numSquares = 8.0 if numSquares % 2 == 0: numSquares += 1.0 orange = color(30, 100, 100) inc = width/numSquares print("inc = ", inc) #circle_1 h = random.randint(.10*width, .9*width) k = random.randint(.10*height, .9*height) position = Position(h, k) initVelocityWave = Sinusoid("s", 0, 0, 120, 0) v1x = initVelocityWave.getY(random.randint(0, 120)) v1y = initVelocityWave.getY(random.randint(0, 120)) velocity = Velocity(v1x,v1y) diamX = Sinusoid("s", .3*inc, .8*inc, 30, 0) diamY = Sinusoid("s", .4*inc, .7*inc, 30, 0) hueCycle = Sinusoid("s", 30, 50, 120, 0) opacityCycle = Sinusoid("s", 20, 80, 30, 0) velXCycle1 = Sinusoid("s", 0, 0, 30, 0) velYCycle1 = Sinusoid("c", 0, 0, 30, 0) jitterCycleX = Sinusoid("s", 0, 0, 120, 0) jitterCycleY = Sinusoid("c", 0, 0, 30, 0) circ1 = BreathingCircle(diamX, diamY, hueCycle, opacityCycle, velXCycle1, velYCycle1, position, velocity, 0, jitterCycleX, jitterCycleY) h = 0 k = 0 myBCs = [] drawCheckerboard(numSquares, my_green) #end function setup def drawGrid(inc): drawHorizLines(inc) drawVertLines(inc) drawAxes() #end function drawGrid def drawHorizLines(inc): stroke(0, 0, 50) strokeWeight(1) y = 0 while y < height: line(0, y, width, y) y += inc #end while loop #end function drawHorizLines def drawVertLines(inc): stroke(0, 0, 50) strokeWeight(1) x = 0 while x < width: line(x, 0, x, height) x += inc #end while loop #end function drawVertLines def drawAxes(): stroke(0, 0, 50) strokeWeight(2) #x-axis line(0, height/2, width, height/2) #y-axis line(width/2, 0, width/2, height) #end function drawAxes def drawGrid(inc, shouldShowAxes): drawHorizLines(inc) drawVertLines(inc) if shouldShowAxes: drawAxes() #end function drawGrid def drawCheckerboard(siz, colr): global count, inc, h, k, position, circ1, t inc = width/siz noStroke() print("t = " + str(t)) print("count = ", count) while count < siz*siz: t += tinc if count % 2 == 0: fill(colr) position = Position(h + .5*inc, k + .5*inc) hueCycle = Sinusoid("s", 30, 50, 120+t, 0) opacityCycle = Sinusoid("s", 20, 80, 30+5*t, 0) #deltaDeg = random.randint(5, 30) deltaDeg = 0 diamX = Sinusoid("s", .3*inc, .8*inc, 30*random.randint(3, 8), t) diamY = Sinusoid("s", .4*inc, .7*inc, 30*random.randint(5, 9), 2*t) jitterCycleX = Sinusoid("s", -.002*inc, .002*inc, 120 + 2*t*random.randint(0,4), 0) jitterCycleY = Sinusoid("c", -.002*inc, .002*inc, 120 + 2*t*random.randint(0,4), 0) circ1 = BreathingCircle(diamX, diamY, hueCycle, opacityCycle, velXCycle1, velYCycle1, position, velocity, deltaDeg, jitterCycleX, jitterCycleY) myBCs.append(circ1) circ1.update(t, 0) circ1.display(t) count += 1 h += 1*inc if count % siz == 0: #move to next row k += inc; h = h % width if count > pow(siz, 2): print("Quilt done!") #end drawCheckerboard def draw(): global t #adjust background color if desired if shouldRefreshBackground: background(lightGray) if shouldShowGrid: drawGrid(inc, False) t += tinc print("t = " + str(t)) for c in myBCs: c.update(t, 20) c.move(1, t) c.display(t) #drawCheckerboard(numSquares, my_green) #end function draw