A friend recently showed me Processing.
Executive summary, it's Java, kind of. I'm more of a backend guy, so anything to make prototyping a GUI fast, or just playing with graphics is a fun diversion out of my wheelhouse.
I present a random Settlers of Catan map generator:

After exploring for an hour or so it appears that most anything from Java SE is available to use (Java 1.6+).
The code is pretty simple:
You can simulate buttons and such and that shall be the next task, and perhaps do some hexes with triangles. Happy Coding!
Quote
Processing is a programming language, development environment, and online community. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology. Initially created to serve as a software sketchbook and to teach computer programming fundamentals within a visual context, Processing evolved into a development tool for professionals. Today, there are tens of thousands of students, artists, designers, researchers, and hobbyists who use Processing for learning, prototyping, and production.
Executive summary, it's Java, kind of. I'm more of a backend guy, so anything to make prototyping a GUI fast, or just playing with graphics is a fun diversion out of my wheelhouse.
I present a random Settlers of Catan map generator:

After exploring for an hour or so it appears that most anything from Java SE is available to use (Java 1.6+).
The code is pretty simple:
import java.util.Map;
import java.util.Collections;
import java.awt.Color;
class Tile{
Color col;
color c_p = #000000;
String name;
float xpos;
float ypos;
int row_pos;
Tile(String n, Color c){
name = n;
col = c;
c_p = col.getRGB();
}
void setRow(int r){
row_pos = r;
}
void setX(float x){
xpos = x;
}
void setY(float y){
ypos = y;
}
void display(){
rectMode(CENTER);
fill(c_p);
//x,y coords, width height
noStroke();
ellipse(xpos, ypos, 50, 50);
}
}
class CatanBoard{
HashMap<String, Color> tileColors = new HashMap<String, Color>();
ArrayList<Tile> tiles = new ArrayList<Tile>();
CatanBoard(){
//fill hash map
tileColors.put("ore", Color.BLACK);
tileColors.put("wood", Color.GREEN.darker());
tileColors.put("sheep", Color.GREEN);
tileColors.put("brick", new Color(88,60,50)); //brown
tileColors.put("wheat", Color.YELLOW);
tileColors.put("desert", new Color(236, 222, 201)); //tan
//create a vector of pieces, randomly put them in some order
//standard catan map for now
//3 ore, brick
//4 wood, sheep, wheat
//1 desert
//this is kinda dumb, refactor this
tiles.add(new Tile("desert", tileColors.get("desert")));
for(int i = 0; i < 3; i++) {
tiles.add(new Tile("ore", tileColors.get("ore")));
tiles.add(new Tile("brick", tileColors.get("brick")));
}
for(int i = 0; i < 4; i++) {
tiles.add(new Tile("wood", tileColors.get("wood")));
tiles.add(new Tile("sheep", tileColors.get("sheep")));
tiles.add(new Tile("wheat", tileColors.get("wheat")));
}
//huzzah no wheel reinvention
Collections.shuffle(tiles);
//set rows in original catan setup
//generate x, y pos based on location in the queue and row on board
int rowSep = 0;
for(int i = 0, row = 0; i < tiles.size(); i++){
if((i == 3) || (i == 7) || (i == 12) || (i == 16) ) {
row++;
rowSep = 0;
}
tiles.get(i).setRow(row);
switch (row){
case 0:
tiles.get(i).setX(120 + (55 * (rowSep+1)) );
break;
case 1:
tiles.get(i).setX(80 + (55 * (rowSep+1)) );
break;
case 2:
tiles.get(i).setX(50 + (55 * (rowSep+1)) );
break;
case 3:
tiles.get(i).setX(80 + (55 * (rowSep+1)) );
break;
case 4:
tiles.get(i).setX(120 + (55 * (rowSep+1)) );
break;
default:
break;
}
rowSep++;
tiles.get(i).setY(100 + 55 * (row+1));
}
}
//only need to draw this once
void display(){
fill(255,0,0);
textSize(42);
text("Random Catan Map", 50, 50);
for(int i = 0; i < tiles.size(); i++) tiles.get(i).display();
}
}
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
//main
CatanBoard board;
void setup(){
size(500,500);
background(0,0,255);
board = new CatanBoard();
}
void draw(){
board.display();
}
You can simulate buttons and such and that shall be the next task, and perhaps do some hexes with triangles. Happy Coding!
0 Comments On This Entry
← January 2022 →
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 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 |
Tags
My Blog Links
Recent Entries
Recent Comments
Search My Blog
7 user(s) viewing
7 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)



Leave Comment









|