storing old versions here
This commit is contained in:
74
archive/citizen_blobdetect/citizen_blobdetect.pde
Normal file
74
archive/citizen_blobdetect/citizen_blobdetect.pde
Normal file
@@ -0,0 +1,74 @@
|
||||
PImage img_houses;
|
||||
|
||||
void setup() {
|
||||
size(400, 300);
|
||||
textSize(30);
|
||||
fill(0);
|
||||
|
||||
img_houses = loadImage(dataPath("map/houses_with_borders.png"));
|
||||
|
||||
surface.setSize(img_houses.width, img_houses.height);
|
||||
}
|
||||
|
||||
void mousePressed() {
|
||||
img_houses.loadPixels();
|
||||
if (int(red(img_houses.pixels[mouseY*img_houses.width+mouseX])) == 187) {
|
||||
println("clicked on house");
|
||||
spawnAreas.add(new SpawnArea(mouseX, mouseY));
|
||||
}
|
||||
img_houses.updatePixels();
|
||||
}
|
||||
|
||||
ArrayList<SpawnArea> spawnAreas = new ArrayList<SpawnArea>();
|
||||
|
||||
|
||||
class SpawnArea {
|
||||
//simplified hull?
|
||||
ArrayList<PVector> v2_points = new ArrayList<PVector>();
|
||||
|
||||
SpawnArea(int startX, int startY) {
|
||||
int x = startX;
|
||||
int y = startY;
|
||||
|
||||
v2_points.add(new PVector(x, y));
|
||||
|
||||
|
||||
|
||||
//while (int(red(img_houses.pixels[y*img_houses.width+x])) == 187) {
|
||||
// y++;
|
||||
// v2_points.add(new PVector(x, y));
|
||||
|
||||
// while (int(red(img_houses.pixels[y*img_houses.width+x])) == 187) {
|
||||
// v2_points.add(new PVector(x, y));
|
||||
// y++;
|
||||
// }
|
||||
|
||||
// y = startY;
|
||||
|
||||
// x++;
|
||||
//}
|
||||
|
||||
//x = startX-1;
|
||||
//y = startY+1;
|
||||
//while(int(red(img_houses.pixels[y*img_houses.width+x])) == 187){
|
||||
// v2_points.add(new PVector(x, y));
|
||||
// x--;
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(img_houses, 0, 0, img_houses.width, img_houses.height);
|
||||
for (SpawnArea spawn : spawnAreas) {
|
||||
|
||||
for (PVector point : spawn.v2_points) {
|
||||
point(point.x, point.y);
|
||||
}
|
||||
}
|
||||
|
||||
text(int(frameRate), 0, 30);
|
||||
}
|
||||
BIN
archive/citizen_blobdetect/data/map/houses_with_borders.png
Normal file
BIN
archive/citizen_blobdetect/data/map/houses_with_borders.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
90
archive/citizen_blobdetect2/Houses.pde
Normal file
90
archive/citizen_blobdetect2/Houses.pde
Normal file
@@ -0,0 +1,90 @@
|
||||
import java.util.ArrayDeque;
|
||||
|
||||
PImage img_houses;
|
||||
PImage img_spawnPoints;
|
||||
int i_biggestHouse;
|
||||
|
||||
ArrayList<SpawnArea> spawnAreas = new ArrayList<SpawnArea>();
|
||||
|
||||
void initHouses() {
|
||||
|
||||
//get houses from image
|
||||
img_houses = loadImage(dataPath("map/houses_with_borders.png"));
|
||||
|
||||
|
||||
img_houses.loadPixels();
|
||||
for (int x = 0; x < img_houses.width; x++) {
|
||||
for (int y = 0; y < img_houses.height; y++) {
|
||||
if (int(red(img_houses.pixels[y*img_houses.width+x])) == 187) { //red must be 187 for a pixel to be part of a house
|
||||
spawnAreas.add(new SpawnArea(x, y));
|
||||
img_houses.updatePixels();
|
||||
img_houses.loadPixels();
|
||||
}
|
||||
}
|
||||
}
|
||||
img_houses.updatePixels();
|
||||
for(SpawnArea spawn : spawnAreas){
|
||||
spawn.i_size = int(map(spawn.i_size,0,i_biggestHouse,0,100));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class SpawnArea {
|
||||
|
||||
|
||||
PVector v2_center;
|
||||
int i_size;
|
||||
|
||||
void display(){
|
||||
text(i_size,v2_center.x,v2_center.y);
|
||||
}
|
||||
|
||||
|
||||
|
||||
ArrayDeque<PVector> v2d_selected = new ArrayDeque<PVector>();
|
||||
ArrayList<PVector> v2d_points = new ArrayList<PVector>();
|
||||
boolean isToSelect(int px, int py, int[] pxl, int pw, int ph, int orgColor) {
|
||||
if (px < 0 || px >= pw || py < 0 || py >= ph)
|
||||
return false;
|
||||
return pxl[px + py * pw] == orgColor;
|
||||
}
|
||||
|
||||
SpawnArea(int startX, int startY) {
|
||||
int [] pxl = img_houses.pixels;
|
||||
int pw = img_houses.width;
|
||||
int ph = img_houses.height;
|
||||
int orgColor = pxl[startX + startY * pw];
|
||||
PVector v2_p = new PVector(startX, startY);
|
||||
color randCol = color(int(random(0, 255)), int(random(0, 255)), int(random(0, 255)));
|
||||
v2d_selected.add(v2_p);
|
||||
int west, east;
|
||||
while (!v2d_selected.isEmpty () ) { //&& q.size() < 500) {
|
||||
v2_p = v2d_selected.removeFirst();
|
||||
if (isToSelect(int(v2_p.x), int(v2_p.y), pxl, pw, ph, orgColor)) {
|
||||
west = east = int(v2_p.x);
|
||||
while (isToSelect(--west, int(v2_p.y), pxl, pw, ph, orgColor));
|
||||
while (isToSelect(++east, int(v2_p.y), pxl, pw, ph, orgColor));
|
||||
for (int x = west + 1; x < east; x++) {
|
||||
v2d_points.add(new PVector(x, int(v2_p.y)));
|
||||
pxl[x + int(v2_p.y) * pw] = color(188, 188, 188); //important for not selecting the same area more than once
|
||||
if (isToSelect(x, int(v2_p.y) - 1, pxl, pw, ph, orgColor))
|
||||
v2d_selected.add(new PVector(x, int(v2_p.y) - 1));
|
||||
if (isToSelect(x, int(v2_p.y) + 1, pxl, pw, ph, orgColor))
|
||||
v2d_selected.add(new PVector(x, v2_p.y + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
i_size = v2d_points.size();
|
||||
PVector avgPoint = new PVector(0,0);
|
||||
for (PVector point : v2d_points) {
|
||||
avgPoint.add(point);
|
||||
}
|
||||
avgPoint.x = avgPoint.x/i_size;
|
||||
avgPoint.y = avgPoint.y/i_size;
|
||||
v2_center = avgPoint;
|
||||
|
||||
if(i_size > i_biggestHouse) i_biggestHouse = i_size;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
5
archive/citizen_blobdetect2/UI.pde
Normal file
5
archive/citizen_blobdetect2/UI.pde
Normal file
@@ -0,0 +1,5 @@
|
||||
void UI() {
|
||||
|
||||
textSize(30);
|
||||
text(int(frameRate), 30, 30);
|
||||
}
|
||||
24
archive/citizen_blobdetect2/citizen_blobdetect2.pde
Normal file
24
archive/citizen_blobdetect2/citizen_blobdetect2.pde
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
void setup() {
|
||||
size(400, 300);
|
||||
textAlign(CENTER);
|
||||
fill(0);
|
||||
|
||||
|
||||
initHouses();
|
||||
|
||||
surface.setSize(img_houses.width, img_houses.height);
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
image(img_houses, 0, 0, img_houses.width, img_houses.height);
|
||||
textSize(7);
|
||||
for (SpawnArea spawn : spawnAreas) {
|
||||
spawn.display();
|
||||
}
|
||||
|
||||
|
||||
UI();
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
91
archive/citizen_floodfill/citizen_floodfill.pde
Normal file
91
archive/citizen_floodfill/citizen_floodfill.pde
Normal file
@@ -0,0 +1,91 @@
|
||||
import java.util.ArrayDeque;
|
||||
|
||||
PImage img;
|
||||
ArrayDeque<Point> q = new ArrayDeque<Point>();
|
||||
|
||||
public void setup() {
|
||||
size(400, 400, P2D);
|
||||
img = makeImage();
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
background(255);
|
||||
image(img, 0, 0);
|
||||
}
|
||||
|
||||
public void mouseClicked() {
|
||||
// Flood fill with random colour
|
||||
int c = (int)(random(1, 0xFFFFFF)) | 0xFF000000;
|
||||
floodFill(img, mouseX, mouseY, c);
|
||||
}
|
||||
|
||||
void floodFill(PImage picture, int orgX, int orgY, int newColor) {
|
||||
int pw = picture.width;
|
||||
int ph = picture.height;
|
||||
if (orgX < 0 || orgX >= pw || orgY < 0 || orgY >= ph)
|
||||
return;
|
||||
picture.loadPixels();
|
||||
int [] pxl = picture.pixels;
|
||||
int orgColor = pxl[orgX + orgY * pw];
|
||||
// Stop if the color is not being changed.
|
||||
if (newColor == orgColor)
|
||||
return;
|
||||
// Proceed with flood fill
|
||||
Point p = new Point(orgX, orgY);
|
||||
q.add(p);
|
||||
int west, east;
|
||||
while (!q.isEmpty () ) { //&& q.size() < 500) {
|
||||
p = q.removeFirst();
|
||||
if (isToFill(p.x, p.y, pxl, pw, ph, orgColor)) {
|
||||
west = east = p.x;
|
||||
while (isToFill(--west, p.y, pxl, pw, ph, orgColor));
|
||||
while (isToFill(++east, p.y, pxl, pw, ph, orgColor));
|
||||
for (int x = west + 1; x < east; x++) {
|
||||
pxl[x + p.y * pw] = newColor;
|
||||
if (isToFill(x, p.y - 1, pxl, pw, ph, orgColor))
|
||||
q.add(new Point(x, p.y - 1));
|
||||
if (isToFill(x, p.y + 1, pxl, pw, ph, orgColor))
|
||||
q.add(new Point(x, p.y + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
picture.updatePixels();
|
||||
}
|
||||
|
||||
// Returns true if the specified pixel requires filling
|
||||
boolean isToFill(int px, int py, int[] pxl, int pw, int ph, int orgColor) {
|
||||
if (px < 0 || px >= pw || py < 0 || py >= ph)
|
||||
return false;
|
||||
return pxl[px + py * pw] == orgColor;
|
||||
}
|
||||
|
||||
// Make a simple image to test the flood fill function
|
||||
PImage makeImage() {
|
||||
PGraphics pg = createGraphics(width, height, P2D);
|
||||
pg.noSmooth();
|
||||
pg.beginDraw();
|
||||
pg.background(255);
|
||||
pg.fill(255, 200, 200);
|
||||
pg.noStroke();
|
||||
pg.ellipse(width/2, height/3, 0.4f*width, 0.4f*height);
|
||||
pg.ellipse(width/3, height/1.8f, 0.4f*width, 0.4f*height);
|
||||
pg.ellipse(2*width/3, height/1.8f, 0.4f*width, 0.4f*height);
|
||||
pg.fill(255, 255, 200);
|
||||
pg.ellipse(width/2, height/2, 0.2f*width, 0.2f*height);
|
||||
pg.endDraw();
|
||||
return pg.get();
|
||||
}
|
||||
|
||||
// Could use java.awt.Point instead
|
||||
class Point {
|
||||
int x, y;
|
||||
|
||||
public Point(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "[" + x + ", " + y + "]";
|
||||
}
|
||||
}
|
||||
BIN
archive/citizen_floodfill/data/map/houses_with_borders.png
Normal file
BIN
archive/citizen_floodfill/data/map/houses_with_borders.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
57
archive/citizen_floodfill2/citizen_floodfill2.pde
Normal file
57
archive/citizen_floodfill2/citizen_floodfill2.pde
Normal file
@@ -0,0 +1,57 @@
|
||||
PImage img;
|
||||
|
||||
int diff;
|
||||
int px;
|
||||
color fillC;
|
||||
color test;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(400, 300);
|
||||
img = loadImage("map/houses_with_borders.png");
|
||||
surface.setSize(img.width, img.height);
|
||||
stroke(255,0,0);
|
||||
noFill();
|
||||
px = width*height;
|
||||
fillC = color(255,0,0);
|
||||
diff = 50;
|
||||
}
|
||||
|
||||
int l(int x, int y){
|
||||
return x + (y * width);
|
||||
}
|
||||
|
||||
color[] flood(int x, int y, color[] pixel){
|
||||
if(x<0 || x>= width || y < 0 || y >= height) return pixel;
|
||||
|
||||
float rt = red(test);
|
||||
float gt = green(test);
|
||||
float bt = blue(test);
|
||||
|
||||
float rc = red(pixel[l(x, y)]);
|
||||
float gc = green(pixel[l(x, y)]);
|
||||
float bc = blue(pixel[l(x, y)]);
|
||||
|
||||
if(dist(rt, gt, bt, rc, gc, bc) <= diff){
|
||||
println(dist(rt, gt, bt, rc, gc, bc));
|
||||
pixel[l(x, y)] = fillC;
|
||||
|
||||
pixel = flood(x+1, y, pixel);
|
||||
pixel = flood(x-1, y, pixel);
|
||||
pixel = flood(x, y+1, pixel);
|
||||
pixel = flood(x, y-1, pixel);
|
||||
}
|
||||
return pixel;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if(mousePressed){
|
||||
img.loadPixels();
|
||||
|
||||
test = img.pixels[l(mouseX, mouseY)];
|
||||
img.pixels = flood(mouseX, mouseY, img.pixels);
|
||||
|
||||
img.updatePixels();
|
||||
}
|
||||
image(img, 0, 0, width, height);
|
||||
}
|
||||
BIN
archive/citizen_floodfill2/data/map/houses_with_borders.png
Normal file
BIN
archive/citizen_floodfill2/data/map/houses_with_borders.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
Reference in New Issue
Block a user