Difference between revisions of "project01:Frontpage"
(→Running Out Of Gas On The Fast Lane) |
(→Running Out Of Gas On The Fast Lane) |
||
Line 47: | Line 47: | ||
[[File:160919_oil-rig_ZF22pz2.gif|850px]] | [[File:160919_oil-rig_ZF22pz2.gif|850px]] | ||
<br> | <br> | ||
+ | |||
+ | import processing.core.*; | ||
+ | import processing.data.*; | ||
+ | import processing.event.*; | ||
+ | import processing.opengl.*; | ||
+ | |||
+ | import java.util.HashMap; | ||
+ | import java.util.ArrayList; | ||
+ | import java.io.File; | ||
+ | import java.io.BufferedReader; | ||
+ | import java.io.PrintWriter; | ||
+ | import java.io.InputStream; | ||
+ | import java.io.OutputStream; | ||
+ | import java.io.IOException; | ||
+ | |||
+ | public class sketch_2D_DLA_basic_growth_grid extends PApplet { | ||
+ | |||
+ | int[][] grid; | ||
+ | //the pixels taken up by one grid square | ||
+ | int grid_size = 2; | ||
+ | |||
+ | public void setup() { | ||
+ | |||
+ | background(255); | ||
+ | fill(0); | ||
+ | //initialize grid | ||
+ | grid = new int[width/grid_size][height/grid_size]; | ||
+ | for(int i=0;i<grid.length;++i) { | ||
+ | for(int j=0;j<grid[0].length;++j) { | ||
+ | grid[i][j] = 0; | ||
+ | } | ||
+ | } | ||
+ | grid[grid.length/2][grid[0].length/2] = 1; | ||
+ | drawGridSquare(grid.length/2,grid[0].length/2); | ||
+ | } | ||
+ | |||
+ | public void draw() { | ||
+ | addPoint(); | ||
+ | } | ||
+ | |||
+ | public void drawGridSquare(int x, int y) { | ||
+ | rect(x*grid_size,y*grid_size,grid_size,grid_size); | ||
+ | } | ||
+ | |||
+ | public void addPoint() { | ||
+ | //initialize random boundary point | ||
+ | int x,y; | ||
+ | if(random(1) < .5f) { | ||
+ | x = PApplet.parseInt(random(grid.length)); | ||
+ | y = PApplet.parseInt(random(2))*(grid[0].length-1); | ||
+ | } else { | ||
+ | x = PApplet.parseInt(random(2))*(grid.length-1); | ||
+ | y = PApplet.parseInt(random(grid[0].length)); | ||
+ | } | ||
+ | while(true) { | ||
+ | //check neighbors | ||
+ | if(checkNeighbors(x,y) > 0) break; | ||
+ | //move in a random direction | ||
+ | float rand = random(1.0f); | ||
+ | //wrap around the grid | ||
+ | if(rand < .25f) { | ||
+ | x = (x+1)%grid.length; | ||
+ | } else if(rand < .5f) { | ||
+ | x = (x+grid.length-1)%grid.length; | ||
+ | } else if(rand < .75f) { | ||
+ | y = (y+1)%grid[0].length; | ||
+ | } else { | ||
+ | y = (y+grid[0].length-1)%grid[0].length; | ||
+ | } | ||
+ | } | ||
+ | grid[x][y] = 1; | ||
+ | drawGridSquare(x,y); | ||
+ | } | ||
+ | |||
+ | public int checkNeighbors(int x, int y) { | ||
+ | int neighbors = 0; | ||
+ | if(x > 0) neighbors += grid[x-1][y]; | ||
+ | if(x < grid.length-1) neighbors += grid[x+1][y]; | ||
+ | if(y > 0) neighbors += grid[x][y-1]; | ||
+ | if(y < grid[0].length-1) neighbors += grid[x][y+1]; | ||
+ | return neighbors; | ||
+ | } | ||
+ | public void settings() { size(600,600); } | ||
+ | static public void main(String[] passedArgs) { | ||
+ | String[] appletArgs = new String[] { "sketch_2D_DLA_basic_growth_grid" }; | ||
+ | if (passedArgs != null) { | ||
+ | PApplet.main(concat(appletArgs, passedArgs)); | ||
+ | } else { | ||
+ | PApplet.main(appletArgs); | ||
+ | } | ||
+ | } | ||
+ | } | ||
==North Sea Locations== | ==North Sea Locations== |
Revision as of 20:33, 26 September 2016
Benjamin Kemper
Running Out Of Gas On The Fast Lane
Repurpose of abandoned drilling rigs in the North Sea (in 20-50 years)
import processing.core.*; import processing.data.*; import processing.event.*; import processing.opengl.*;
import java.util.HashMap; import java.util.ArrayList; import java.io.File; import java.io.BufferedReader; import java.io.PrintWriter; import java.io.InputStream; import java.io.OutputStream; import java.io.IOException;
public class sketch_2D_DLA_basic_growth_grid extends PApplet {
int[][] grid; //the pixels taken up by one grid square int grid_size = 2;
public void setup() {
background(255); fill(0); //initialize grid grid = new int[width/grid_size][height/grid_size]; for(int i=0;i<grid.length;++i) { for(int j=0;j<grid[0].length;++j) { grid[i][j] = 0; } } grid[grid.length/2][grid[0].length/2] = 1; drawGridSquare(grid.length/2,grid[0].length/2);
}
public void draw() {
addPoint();
}
public void drawGridSquare(int x, int y) {
rect(x*grid_size,y*grid_size,grid_size,grid_size);
}
public void addPoint() {
//initialize random boundary point int x,y; if(random(1) < .5f) { x = PApplet.parseInt(random(grid.length)); y = PApplet.parseInt(random(2))*(grid[0].length-1); } else { x = PApplet.parseInt(random(2))*(grid.length-1); y = PApplet.parseInt(random(grid[0].length)); } while(true) { //check neighbors if(checkNeighbors(x,y) > 0) break; //move in a random direction float rand = random(1.0f); //wrap around the grid if(rand < .25f) { x = (x+1)%grid.length; } else if(rand < .5f) { x = (x+grid.length-1)%grid.length; } else if(rand < .75f) { y = (y+1)%grid[0].length; } else { y = (y+grid[0].length-1)%grid[0].length; } } grid[x][y] = 1; drawGridSquare(x,y);
}
public int checkNeighbors(int x, int y) {
int neighbors = 0; if(x > 0) neighbors += grid[x-1][y]; if(x < grid.length-1) neighbors += grid[x+1][y]; if(y > 0) neighbors += grid[x][y-1]; if(y < grid[0].length-1) neighbors += grid[x][y+1]; return neighbors;
}
public void settings() { size(600,600); } static public void main(String[] passedArgs) { String[] appletArgs = new String[] { "sketch_2D_DLA_basic_growth_grid" }; if (passedArgs != null) { PApplet.main(concat(appletArgs, passedArgs)); } else { PApplet.main(appletArgs); } }
}
North Sea Locations
Interactive map: http://www.petroleumskartet.no/