xxxxxxxxxx
82
// Exports a high-resolution image when 'e' key is pressed.
let outputScale = 5;
let currentScale;
let myScaledCanvas;
let canvas;
//=================================================================
function setup() { // setup
canvas = createCanvas(800, 800);
myScaledCanvas = createGraphics(800, 800);
currentScale = 1; // initialize to 1; don't touch
}
function draw() {
// Don't touch the contents of the draw loop!
// Instead, modify the guts of the drawMyDesign() function.
myScaledCanvas.clear();
myScaledCanvas.push();
myScaledCanvas.scale(currentScale);
drawMyDesign();
myScaledCanvas.pop();
image(myScaledCanvas, 0, 0); // Show on the main canvas
noLoop();
}
// Scale up graphics before exporting
function exportHighResolution() {
currentScale = outputScale; // High-Res Export
myScaledCanvas = createGraphics(currentScale * 800, currentScale * 800);
draw();
save(myScaledCanvas, "highResImage", 'png');
currentScale = 1; // Reset to default scale 1:1
myScaledCanvas = createGraphics(800, 800);
draw();
}
function keyReleased() {
if (key == 'e') exportHighResolution();
}
function mousePressed() {
loop();
}
//=================================================================
function drawMyDesign() {
myScaledCanvas.background(255);
//colors
let reds = [color(226, 178, 142), color(215, 151, 99), color(229, 193, 144), color(147, 80, 35), color(55, 40, 37), color(109, 68, 36)];
let greens = [color(89, 112, 68), color(91, 104, 78),
color(142, 138, 91), color(60, 71, 28)
];
let blues = [color(145, 177, 190), color(49, 64, 85)];
// test shape
myScaledCanvas.angleMode(DEGREES);
xoff = 0.0;
for (j = 0; j < 360; j += 5 ) {
myScaledCanvas.beginShape();
myScaledCanvas.strokeWeight(1);
myScaledCanvas.stroke(230);
myScaledCanvas.fill(random(50, 180));
xoff = xoff + 0.01;
n = myScaledCanvas.noise(xoff) * 80;
rad = n;
firstx = rad * cos(j);
firsty = rad * sin(j);
secondx = rad * cos(j + 10);
secondy = rad * sin(j + 10);
startx = 100;
starty = 200;
myScaledCanvas.vertex(startx, starty);
myScaledCanvas.vertex (firstx + startx, firsty + starty);
myScaledCanvas.vertex(secondx + startx, secondy + starty );
myScaledCanvas.endShape(CLOSE);
}
}