いよいよInteractive
Mouseとの距離を判定し、テキストを表示する。
1 2 3 4 5 |
if dist(x, y, mouseX, mouseY) < radius+2: fill(0) textAlign(CENTER) text(value, x, y-radius-4) text(abbrev, x, y-radius-19) |
step08_rollovers_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 |
import Table dataMin = 0 dataMax = 0 def setup(): global locationTable global nameTable global mapImage global rowCount global dataTable global dataMin global dataMax size(640, 400) mapImage = loadImage("map.png") locationTable = Table.Table("locations.tsv") rowCount = locationTable.getRowCount() print rowCount dataTable = Table.Table("random.tsv") # Find the minimum and maximum values for row in range(rowCount): value = dataTable.getFloat(row, 1) if value > dataMax: dataMax = value if value < dataMin: dataMin = value 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 background(255) #print(rowCount) image(mapImage, 0, 0) #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) # Map the size of the ellipse to the data value def drawData(x, y, abbrev): global dataTable global dataMin global dataMax #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) if dist(x, y, mouseX, mouseY) < radius+2: fill(0) textAlign(CENTER) text(value, x, y-radius-4) text(abbrev, x, y-radius-19) |
step09_rollovers_full_names_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 |
import Table dataMin = 0 dataMax = 0 def setup(): global locationTable global nameTable global mapImage global rowCount global dataTable global dataMin global dataMax 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") # Find the minimum and maximum values for row in range(rowCount): value = dataTable.getFloat(row, 1) if value > dataMax: dataMax = value if value < dataMin: dataMin = value def draw(): global locationTable global nameTable global mapImage global rowCount global dataTable global dataMin global dataMax background(255) #print(rowCount) image(mapImage, 0, 0) 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) # Map the size of the ellipse to the data value def drawData(x, y, abbrev): global dataTable global dataMin global dataMax #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) if dist(x, y, mouseX, mouseY) < radius+2: fill(0) textAlign(CENTER) name = nameTable.getString2(abbrev, 1) #text(name + " " + value, x, y-radius-4) text(name, x, y-radius-20) text(value, x, y-radius-4) |
step10_single_rollover_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 |
import Table dataMin = 0 dataMax = 0 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") # Find the minimum and maximum values for row in range(rowCount): value = dataTable.getFloat(row, 1) if value > dataMax: dataMax = value if value < dataMin: dataMin = value 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 |