xxxxxxxxxx
64
let vertices = [20, 100, 265, 78, 335, 120, 85, 190]; // Array to store vertex objects
// create a variable to hold the current position in the deck
var position = 0;
let frame;
function preload(){
frame = loadImage("images/frame.png");
}
function setup() {
createCanvas(400, 400);
// shuffle the deck first
vertices = shuffle(vertices);
frameRate(1); // Set the frame rate to 5 frames per second
}
function draw() {
background(random(255), random(255), random(255));
push();
scale(0.75);
translate(100,100);
for (let i = 0; i < 2; i++) {
// Draw the shape using the vertex points
beginShape();
for (let i = 0; i < vertices.length; i++) {
noStroke();
fill(valueFromDeck(),valueFromDeck(),valueFromDeck());
let x = valueFromDeck();
let y = valueFromDeck();
curveVertex(x, y);
//noLoop();
}
endShape(CLOSE);
}
pop();
image(frame,0,0,width,height);
}
function valueFromDeck() {
// find the value at the current position in the deck
var v = vertices[position];
// change the position for next time
position++;
// if that was the last value, shuffle and start over from the top
if (position == vertices.length) {
vertices = shuffle(vertices);
position = 0;
}
// return the value
return v;
}
function keyPressed(){
if(key === "s"){
saveCanvas();
}
}