I could manage to cache the array as pixels on my canvas with the help of this code using loadPixels(); and updatePixels(); functions. The problem with that method is it's loading/updating the whole canvas. I only want to cache the array named drawings because if I want to put some UI controls or mouse cursor later, it's going to print them on the canvas as well. What could be the easiest way to rasterize what's stored in that drawings array?
Processing.js - updatePixels() for a specific array
321 Views Asked by ofer dofer At
1
There are 1 best solutions below
Related Questions in JAVASCRIPT
- Using Puppeteer to scrape a public API only when the data changes
- inline SVG text (js)
- An array of images and a for loop display the buttons. How to assign each button to open its own block by name?
- Storing the preferred font-size in localStorage
- Simple movie API request not showing up in the console log
- Authenticate Flask rest API
- Deploying sveltekit app with gunjs on vercel throws cannot find module './lib/text-encoding'
- How to request administrator rights?
- mp4 embedded videos within github pages website not loading
- Scrimba tutorial was working, suddenly stopped even trying the default
- In Datatables, start value resets to 0, when column sorting
- How do I link two models in mongoose?
- parameter values only being sent to certain columns in google sheet?
- Run main several times of wasm in browser
- Variable inside a Variable, not updating
Related Questions in ARRAYS
- How could you print a specific String from an array with the values of an array from a double array on the same line, using iteration to print all?
- What does: "char *argv[]" mean?
- How to populate two dimensional array
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- Function is returning undefined but should be returning a matched object from array in JavaScript
- The rules of Conway's Game of Life aren't working in my Javascript version. What am I doing wrong?
- Array related question, cant find the pattern
- Setting the counter (j) for (inner for loop)
- I want to flip an image (with three channels RGB) horizontally just using array slicing. How can I do it with python?
- Numpy array methods are faster than numpy functions?
- How to enter data in mongodb array at specific position such that if there is only 2 data in array and I want to insert at 5, then rest data is null
- How to return array to ArrayPool when it was rented by inner function?
- best way to remove a word from an array in a react app
- Vue display output of two dimensional array
- Undot Array with Wildcards in Laravel
Related Questions in PROCESSING
- Processing substitute long variables for something shorter
- How do I shuffle these blocks and make a win/loss game-state?
- How to read and process big csv file fast and keep memory usage low in java?
- Why does the shadow appear above the image in this p5.js code?
- How to fix rendering issue when rotating an arc in processing?
- Kinect V1 not connecting to Kinect Studio v1.8.0
- How to create a 2d top-down movement system where moving while holding two keys is possible in processing?
- How to fix the problem on converting ShaderToy color to Processing?
- 2d UI elements in a 3d environment in Processing
- Using A* to Create Procedurally Generated Rooms in Processing
- Having some issues with Void Draw in Processing
- Understanding NAudio and converting buffer to floats
- Processing ZoomOut
- I struggle with a basic feedback delay network
- i cant seem to find the syntaxerror in setup and draw in this flowfield sketch
Related Questions in P5.JS
- Performance of sketch drastically decreases outside of the P5 Web Editor
- The p5js library's loadFont function does not seem to work for me?
- Why is toDataURL() returning blank image? (with p5 video)
- how to stretch the video feed from camera on p5.js
- "Invalid JSON response: null" error when using Gemini Pro Vision AI API in Node.js
- Why does the shadow appear above the image in this p5.js code?
- Is it possible to unpack/destructure class attributes into variables?
- How to make the ball act more realisticly in my pong game?
- p5.js rotate unexpected results
- P5.js button that displays a 3D model when touched
- How to extend p5.js's TypeScript definition?
- Does p5.js support steering wheel and gas pedal input and how to read input?
- How can I optimize this specific part of my p5js code (using trig functions) to reduce lag while maintaining the visual effect?
- Rendering p5.js sketch on my Jekyll website
- Add p5js to the typescript and webpack template app created in electron forge
Related Questions in PROCESSING.JS
- How would I add a sound from a url to a processing js program?
- Weird visual bug when using my pixel art program
- (ProcessingJS) Pixelating noise
- Change array list into multiple array lists every 3 items
- Detecting if something in a position already exists
- How to convert ProcessingJS library to p5.js?
- How does the ProcessingJS link work without an internet connection?
- Arc function not working properly after canvas is resized
- Processing - logo banner not loading on website
- How do i make a third scene for the menu screen?
- How do I get the code that was run inside a function to remain on the canvas after I refresh the background
- How can I use p5.js without it polluting the global scope?
- How to play sound inside a Processing.js program running in the canvas on a webpage?
- Playing sound with Processing.js on browser
- Processing.js - updatePixels() for a specific array
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
While
loadPixels()load the whole drawing (which is great since it's the end result of your work you get that way, not every damn sprite), there is an easy way to load the pixels of a specific image:The PImage class has it's own
loadPixels()method. In short, every image has it's ownmyPImage.pixels[]array, but you need to load it withmyPImage.loadPixels()before you can use it.Here's some skeleton code right from the Processing reference material:
I'll hang around in case you have follow-up questions. Have fun!
EDIT: after reading your questions, I decided that you would gain more insight from a working example which demonstrate how to use the
pixels[]array than just the basic documentation, so here it is. You can copy and paste it in a Processing IDE and play with the code to get a better understanding of these concepts.I took the liberty to simplify the example you provided to it's bare core so you can understand the basics of
pixels[],updatePixels()andloadPixels(). I first wanted to just edit it, but the way it works would have made the exercise too confusing for my taste.I basically just underlined how to use these concepts by creating a white canvas where you can "draw" with the mouse. When you press "s", it saves the current state of the drawing . When you press "l", you'll load the previously saved state. I think it'll show you what you wanted to understand here.
(the drawing will be sketchy since this isn't the object here so I didn't care about that)
Here's the code. Comments are included for additional insights.
Have fun!