xxxxxxxxxx
84
let picture; //画像の変数imgを定義
let frame; //画像の変数imgを定義
function preload() {
frame = loadImage("frame.png");
picture = loadImage("samoyed.png");
}
function setup() {
createCanvas(windowWidth, windowHeight);
const api_key = "SG_1a152342b25f06ca";
const url = "https://api.segmind.com/v1/ssd-1b";
const data = {
prompt:
"Samoyed dog playing club DJ.",
negative_prompt: "painting",
samples: 1,
scheduler: "UniPC",
num_inference_steps: 20,
guidance_scale: "10",
img_width: "1024",
img_height: "1024",
base64: false,
};
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": api_key
},
body: JSON.stringify(data),
})
.then((response) => {
console.log(response);
return response.blob();
}
).then((data)=>{
console.log(data);
var reader = new FileReader();
reader.onload = function(evt) {
picture = loadImage(reader.result)
image(
picture,
windowWidth / 2 - (windowWidth * frameWidth) / wallWidth / 2,
windowHeight / 2 - (windowHeight * frameHeight) / wallHeight / 2,
(windowWidth * frameWidth) / wallWidth,
(windowHeight * frameHeight) / wallHeight
);
}
reader.readAsDataURL(data);
})
.catch((error) => console.log("error", error));
}
const frameWidth = 1163;
const frameHeight = 1163;
const wallWidth = 4400;
const wallHeight = 2475;
function draw() {
background(220);
fullscreen();
image(frame, 0, 0, windowWidth, windowHeight);
if (picture === undefined) {
return;
}
image(
picture,
windowWidth / 2 - (windowWidth * frameWidth) / wallWidth / 2,
windowHeight / 2 - (windowHeight * frameHeight) / wallHeight / 2,
(windowWidth * frameWidth) / wallWidth,
(windowHeight * frameHeight) / wallHeight
);
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}