もっとInteractiveに
スペースキーが押されたら、updateTable()関数を呼び出して、値をランダムに更新
1 2 3 4 5 6 7 8 9 10 |
def keyPressed(): if (key == ' '): updateTable() def updateTable(): global dataTable global rowCount for row in range(rowCount): newValue = random(-10, 10) dataTable.setFloat(row, 1, newValue) |
step11_randomize_on_keypress_py.pyde
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
import Table dataMin = -10 dataMax = 10 def setup(): global locationTable global nameTable global mapImage global rowCount global dataTable global dataMin global dataMax global closestDist global closestText global closestText2 global closestTextX global closestTextY size(640, 400) mapImage = loadImage("map.png") locationTable = Table.Table("locations.tsv") nameTable = Table.Table("names.tsv") rowCount = locationTable.getRowCount() print rowCount dataTable = Table.Table("random.tsv") font = loadFont("Univers-Bold-12.vlw") textFont(font) smooth() noStroke() def draw(): global locationTable global nameTable global mapImage global rowCount global dataTable global dataMin global dataMax global closestDist global closestText global closestText2 global closestTextX global closestTextY background(255) #print(rowCount) image(mapImage, 0, 0) closestDist = width*height #fill(192, 0, 0) #noStroke() for row in range(0,rowCount): abbrev = dataTable.getRowName(row) x = locationTable.getFloat2(abbrev, 1) y = locationTable.getFloat2(abbrev, 2) drawData(x, y, abbrev) if (closestDist != width*height): fill(0); textAlign(CENTER); text(closestText, closestTextX, closestTextY-15) text(closestText2, closestTextX, closestTextY) # Map the size of the ellipse to the data value def drawData(x, y, abbrev): global dataTable global dataMin global dataMax global closestDist global closestText global closestText2 global closestTextX global closestTextY #Get data value for state value = dataTable.getFloat2(abbrev, 1) radius = 0 if value >= 0: radius = map(value, 0, dataMax, 1.5, 15) fill('#333366') #blue else: radius = map(value, 0, dataMin, 1.5, 15) fill('#ec5166') #red ellipseMode(RADIUS) ellipse(x, y, radius, radius) d = dist(x, y, mouseX, mouseY) # Because the following check is done each time a new # circle is drawn, we end up with the values of the # circle closest to the mouse. if ((d < radius + 2) and (d < closestDist)): closestDist = d name = nameTable.getString2(abbrev, 1) closestText = name closestText2 = value closestTextX = x closestTextY = y-radius-4 def keyPressed(): if (key == ' '): updateTable() def updateTable(): global dataTable global rowCount for row in range(rowCount): newValue = random(-10, 10) dataTable.setFloat(row, 1, newValue) |
step12_randomize_with_nfp_py.pyde
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
import Table dataMin = -10 dataMax = 10 def setup(): global locationTable global nameTable global mapImage global rowCount global dataTable global dataMin global dataMax global closestDist global closestText global closestText2 global closestTextX global closestTextY size(640, 400) mapImage = loadImage("map.png") locationTable = Table.Table("locations.tsv") nameTable = Table.Table("names.tsv") rowCount = locationTable.getRowCount() print rowCount dataTable = Table.Table("random.tsv") font = loadFont("Univers-Bold-12.vlw") textFont(font) smooth() noStroke() def draw(): global locationTable global nameTable global mapImage global rowCount global dataTable global dataMin global dataMax global closestDist global closestText global closestText2 global closestTextX global closestTextY background(255) #print(rowCount) image(mapImage, 0, 0) closestDist = width*height #fill(192, 0, 0) #noStroke() for row in range(0,rowCount): abbrev = dataTable.getRowName(row) x = locationTable.getFloat2(abbrev, 1) y = locationTable.getFloat2(abbrev, 2) drawData(x, y, abbrev) if (closestDist != width*height): fill(0); textAlign(CENTER) text(closestText, closestTextX, closestTextY-15) text(closestText2, closestTextX, closestTextY) # Map the size of the ellipse to the data value def drawData(x, y, abbrev): global dataTable global dataMin global dataMax global closestDist global closestText global closestText2 global closestTextX global closestTextY #Get data value for state value = dataTable.getFloat2(abbrev, 1) radius = 0 if value >= 0: radius = map(value, 0, dataMax, 1.5, 15) fill('#333366') #blue else: radius = map(value, 0, dataMin, 1.5, 15) fill('#ec5166') #red ellipseMode(RADIUS) ellipse(x, y, radius, radius) d = dist(x, y, mouseX, mouseY) # Because the following check is done each time a new # circle is drawn, we end up with the values of the # circle closest to the mouse. if ((d < radius + 2) and (d < closestDist)): closestDist = d name = nameTable.getString2(abbrev, 1) closestText = name closestText2 = nfp(value, 0, 2) closestTextX = x closestTextY = y-radius-4 def keyPressed(): if (key == ' '): updateTable() def updateTable(): global dataTable global rowCount for row in range(rowCount): newValue = random(-10, 10) dataTable.setFloat(row, 1, newValue) |
step13_randomize_from_cgi_py.pyde
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
import Table dataMin = -10 dataMax = 10 def setup(): global locationTable global nameTable global mapImage global rowCount global dataTable global dataMin global dataMax global closestDist global closestText global closestText2 global closestTextX global closestTextY size(640, 400) mapImage = loadImage("map.png") locationTable = Table.Table("locations.tsv") nameTable = Table.Table("names.tsv") rowCount = locationTable.getRowCount() updateTable() font = loadFont("Univers-Bold-12.vlw") textFont(font) smooth() noStroke() def draw(): global locationTable global nameTable global mapImage global rowCount global dataTable global dataMin global dataMax global closestDist global closestText global closestText2 global closestTextX global closestTextY background(255) #print(rowCount) image(mapImage, 0, 0) closestDist = width*height #fill(192, 0, 0) #noStroke() for row in range(0,rowCount): abbrev = dataTable.getRowName(row) x = locationTable.getFloat2(abbrev, 1) y = locationTable.getFloat2(abbrev, 2) drawData(x, y, abbrev) if (closestDist != width*height): fill(0); textAlign(CENTER) text(closestText, closestTextX, closestTextY-15) text(closestText2, closestTextX, closestTextY) # Map the size of the ellipse to the data value def drawData(x, y, abbrev): global dataTable global dataMin global dataMax global closestDist global closestText global closestText2 global closestTextX global closestTextY #Get data value for state value = dataTable.getFloat2(abbrev, 1) radius = 0 if value >= 0: radius = map(value, 0, dataMax, 1.5, 15) fill('#333366') #blue else: radius = map(value, 0, dataMin, 1.5, 15) fill('#ec5166') #red ellipseMode(RADIUS) ellipse(x, y, radius, radius) d = dist(x, y, mouseX, mouseY) # Because the following check is done each time a new # circle is drawn, we end up with the values of the # circle closest to the mouse. if ((d < radius + 2) and (d < closestDist)): closestDist = d name = nameTable.getString2(abbrev, 1) closestText = name closestText2 = nfp(value, 0, 2) closestTextX = x closestTextY = y-radius-4 def keyPressed(): if (key == ' '): updateTable() def updateTable(): global dataTable dataTable = Table.Table("http://benfry.com/writing/map/random.cgi") |