Art Truchet


Project Code

This code is written and rendered using Processing (v3), a quick and easy graphical sketchbook engine written in Java
class Truchet {
	float x;
	float y;
	int state;
	
	Truchet(float x_, float y_) {
		x = x_;
		y = y_;
		
		state = round(random(1));
	}
	
	void update() {
		
	}
	
	void draw() {
		pushMatrix();
		pushStyle();
		
		translate(x, y);
		
		fill(color(255));
		noStroke();
		rect(0, 0, tile_size, tile_size);
		
		noFill();
		stroke(color(0));
		strokeWeight( floor((tile_size * 0.1)) );
		
		if(state == 1) {
			arc(
				tile_size, 0,
				tile_size, tile_size,
				HALF_PI, PI
			);
			
			arc(
				0, tile_size,
				tile_size, tile_size,
				(TWO_PI - HALF_PI), TWO_PI
			);
		} else {
			arc(
				tile_size, tile_size,
				tile_size, tile_size,
				PI, (TWO_PI - HALF_PI)
			);
			
			arc(
				0, 0,
				tile_size, tile_size,
				0, HALF_PI
			);
		}
		
		popStyle();
		popMatrix();
	}
}
ArrayList tiles;

float tile_size = 24;

void setup() {
	size(640, 640);
	
	tiles = new ArrayList();
	
	int num_y = ceil( (height / tile_size) );
	int num_x = ceil( (width / tile_size) );
	
	for(int y = 0; y < num_y; y++) {
		for(int x = 0; x < num_x; x++) {
			Truchet tile = new Truchet(
				(x * tile_size),
				(y * tile_size)
			);
			
			tiles.add(tile);
		}
	}
}

void draw() {
	background(30);
	
	for(Truchet tile : tiles) {
		tile.update();
		tile.draw();
	}
	
	if(frameCount == 50) { save("preview.png"); }
}
please visit our Contact Us page to get in touch
pyxol © 2021