This p5.js sketch integrates with the Google Gemini API to generate text based on your prompt and the current canvas. See geminiAPI.js for info on how to obtain your own API key. Based on work by Amit Pitaru.
Draw with the cursor.
Press any key to send the canvas to the Gemini AI.
Start drawing again to clear the screen.
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Forks of this sketch will no longer be attributed to this sketch.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
Draw with the cursor. Press any key to send the canvas to the Gemini AI. Start drawing again to clear the screen.
CC Attribution NonCommercial ShareAlike
Gemini-Sample
Levin
xxxxxxxxxx
/**
* This p5.js sketch integrates with the Google Gemini API
* to generate text — based on your text prompt and the p5.js canvas.
* See geminiAPI.js for info on how to obtain your own API key.
* Based on https://editor.p5js.org/pitaru/sketches/Ixu00bucD
* by Amit Pitaru. Uses p5.js v.1.11.0 and geminiAPI 0.1.5.
*
* When you fork this sketch, make sure to include geminiAPI.js,
* and make sure to enable the geminiAPI.js library.
*
* Instructions for use:
* 1. Draw with the cursor.
* 2. Press any key to transmit the canvas to the Gemini API.
* 3. To clear the screen, start drawing again.
*/
let bRestart = true;
function setup() {
createCanvas(500, 500);
background('white');
text("Make a drawing to start, then press a key.", 20,30);
}
function keyPressed(){
// (Here are some quick examples, try them out.)
// let myPrompt = "In 1 word and one emoji, tell me what you see.";
// let myPrompt = "Count how many things you see. Provide a number";
// let myPrompt = "Give 1 paragraph of art-school analysis of my drawing."
// let myPrompt = "Provide one number that quantifies how smooth (0) or wiggly (1) my line is.";
let myPrompt = "Provide one caption for this New Yorker cartoon. Only provide the caption."
askGeminiWithCanvas(myPrompt);
}
function onGeminiResponse(resp) {
fill('black');
noStroke();
textSize(16);
text(resp, 20, 30, width-40);
bRestart = true;
}
function mousePressed(){
if (bRestart){
background('white');
bRestart = false;
}
}
function mouseDragged() {
stroke('black');
strokeWeight(3);
line(pmouseX,pmouseY, mouseX,mouseY);
}
See More Shortcuts
Please verify your email to comment
Verify Email