Simulation von Bürgern
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

citizen_blobdetect.pde 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. PImage img_houses;
  2. void setup() {
  3. size(400, 300);
  4. textSize(30);
  5. fill(0);
  6. img_houses = loadImage(dataPath("map/houses_with_borders.png"));
  7. surface.setSize(img_houses.width, img_houses.height);
  8. }
  9. void mousePressed() {
  10. img_houses.loadPixels();
  11. if (int(red(img_houses.pixels[mouseY*img_houses.width+mouseX])) == 187) {
  12. println("clicked on house");
  13. spawnAreas.add(new SpawnArea(mouseX, mouseY));
  14. }
  15. img_houses.updatePixels();
  16. }
  17. ArrayList<SpawnArea> spawnAreas = new ArrayList<SpawnArea>();
  18. class SpawnArea {
  19. //simplified hull?
  20. ArrayList<PVector> v2_points = new ArrayList<PVector>();
  21. SpawnArea(int startX, int startY) {
  22. int x = startX;
  23. int y = startY;
  24. v2_points.add(new PVector(x, y));
  25. //while (int(red(img_houses.pixels[y*img_houses.width+x])) == 187) {
  26. // y++;
  27. // v2_points.add(new PVector(x, y));
  28. // while (int(red(img_houses.pixels[y*img_houses.width+x])) == 187) {
  29. // v2_points.add(new PVector(x, y));
  30. // y++;
  31. // }
  32. // y = startY;
  33. // x++;
  34. //}
  35. //x = startX-1;
  36. //y = startY+1;
  37. //while(int(red(img_houses.pixels[y*img_houses.width+x])) == 187){
  38. // v2_points.add(new PVector(x, y));
  39. // x--;
  40. //}
  41. }
  42. }
  43. void draw() {
  44. background(255);
  45. image(img_houses, 0, 0, img_houses.width, img_houses.height);
  46. for (SpawnArea spawn : spawnAreas) {
  47. for (PVector point : spawn.v2_points) {
  48. point(point.x, point.y);
  49. }
  50. }
  51. text(int(frameRate), 0, 30);
  52. }