xxxxxxxxxx
90
let label = "B";
let tileSize = 50; // size tiles to make
let tiles; // list of tiles, created in setup()
let font; // font we'll use
function preload() {
font = loadFont('assets/Akira Expanded Demo.otf');
}
function setup() {
createCanvas(windowWidth, windowHeight);
// draw the text to a graphics object
let pg = createGraphics(width, height);
pg.background('#b6b7b9');
pg.textFont(font); // note we have to start all
pg.textAlign(CENTER, CENTER); // commands with the name of
pg.textSize(400); // the graphics object
pg.fill('#151618');
pg.noStroke();
pg.text('B', pg.width/2, pg.height/2-38);
pg.textSize(12);
for (let i=0; i<500; i++) {
pg.text('', random(pg.width), random(pg.height));
}
tiles = [];
for (let y=0; y<pg.height; y+=tileSize) {
for (let x=0; x<pg.width; x+=tileSize) {
let tile = new Tile(x, y, tileSize, pg);
tiles.push(tile);
}
}
// start the background all black
// note: there's no background in draw()
background('#cdff00');
}
// display the tiles (real work is in the
// Tile class below)
function draw() {
for (let i=0; i<tiles.length; i++) {
tiles[i].display();
}
}
// a simple class for the tiles
// this lets us more easily create images
// from the graphics we made in setup(),
// handle displaying them, etc though you
// could definitely do this without a class
class Tile {
constructor(x, y, w, pg) {
this.x = x;
this.y = y;
this.img = createImage(w, w);
this.img.copy(pg, x,y, w,w, 0,0, w,w);
}
// display the tile!
display() {
push();
translate(this.x, this.y);
rotate( map(60, 30,width, 0.1,TWO_PI) );
image(this.img, 0,0);
pop();
}
}
// if you want to use the SVG export
// option, go to setup and enable SVG mode
// no need to make any changes below.
function keyPressed() {
if (key === "s") {
if(this._renderer.elt.svg !== undefined) {
saveSVG(label + ".svg");
} else {
saveCanvas(label + ".png");
}
}
}