function selectoption() {
AB.headerRHS();
AB.newDiv("selectdiv");
$("#selectdiv").css({
"margin": "30",
});
$("#selectdiv").html(" Pick a shape: <span id='shapelist'></span> ");
shapes = ["square", "circle"];
shapelist = createSelect(); // https://p5js.org/reference/#/p5/createSelect
shapelist.parent('shapelist');
for (var i = 0; i < shapes.length; i++)
shapelist.option(shapes[i]);
}
function setup() // "setup" is called once at start of run
{
createCanvas ( ABWorld.fullwidth(), ABWorld.fullheight(), WEBGL );
selectoption();
draw_cubes([
{"x": 0, "y": 0, "z": 0},
{"x": 1, "y": 0, "z": 0},
{"x": 1, "y": 1, "z": 0},
{"x": 0, "y": 1, "z": 0},
{"x": 0, "y": 0, "z": 1},
{"x": 1, "y": 0, "z": 1},
{"x": 1, "y": 1, "z": 1},
{"x": 0, "y": 1, "z": 1}
]);
}
//var angle = 30;
//const anglechange = 0.01;
function draw_cubes(cubes)
{
background("green"); // background color
for ( var i=0; i < cubes.length; i++ )
{
console.log(cubes[i]);
translate(cubes[i]['x'], cubes[i]['y'], cubes[i]['z'] + 50); // get box position i
box(1);
}
//angle = angle + anglechange; // change angle each step to get rotate movement
}
/*
const token = "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";
const url = "https://api.openai.com/v1/chat/completions";
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token,
},
body: JSON.stringify({
"model": "gpt-3.5-turbo",
"messages": [{
"role": "user",
"content": "Generate an array of cubes in the following json format {'cubes':[{'coordinates': {'x': _, 'y': _, 'z': _}}]}, replace all '_'s with a number from -200 to 200."}]
})
})
.then(response => {
return response.json(); // Return the JSON data from the response
})
.then(result => {
r = result.choices[0].message.content;
console.log(r);
var firstOpen, firstClose;
firstOpen = r.indexOf('{', firstOpen + 1);
lastClose = r.lastIndexOf('}');
draw_cubes(JSON.parse(r.slice(firstOpen, lastClose + 1)).cubes);
})
.catch(error => {
console.error(error); // Handle any errors that occur during the request
});*/