p5js | Simplex Noise & WebGL with p5js from Processing.Org | Graphics library
kandi X-RAY | p5js Summary
kandi X-RAY | p5js Summary
My Experiments with p5js using simplex noise on 3d grids and matrix systems. You can change the render file called in index.js, each variation explores different features in rendering and shader functions. Using dat-gui to control display and render options. Current Mapping --> index.js --> (render file) renders\Render.js (or just about any other file in src). Render - Original Render, initial framework with basic interaction.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of p5js
p5js Key Features
p5js Examples and Code Snippets
Community Discussions
Trending Discussions on p5js
QUESTION
I have a code that activates an image and leaves it activated but i want to change to other images if the parameters are met. i want to activate one thing and deactivate the other if i say a certain word
My code: https://editor.p5js.org/perikleousd910/sketches/OI1glzfWS
...ANSWER
Answered 2022-Apr-08 at 12:04If I understand you correctly, you might want something like this; the global variable shownImageSet
is "held" to the last value if there is no pose and label.
There is no need for flag
/flag2
variables.
QUESTION
I created a sketch which draws 100s of thousands of lines. As expected, it is quite slow. So, I tried the same sketch with WEBGL mode. But this turned out to be slower than the default mode.
My understanding was that WEBGL leverages GPU for fast rendering. Is it not true?
Thank you.
createCanvas(windowWidth, windowHeight, WEBGL)
Side note: I coded this sketch first in Processing (java), where the WEBGL mode was 100 times faster than the default mode. So, I expected the same with P5js.
...ANSWER
Answered 2022-Mar-24 at 00:02Drawing numerous stroked shapes in p5.js with WEBGL is notoriously slow. See: Sketch runs slow in P5.js WEBGL on the processing.org Discourse forum. If you specifically want to draw lines and/or curves and you don't need 3d perspective then a 2d canvas will actually perform better (and in most browsers it will still utilize the GPU). If you are actually utilizing 3d perspective and other WEBGL rendering capabilities then the key thing is to reduce the number of drawing instructions, and if possible avoid relying on p5.js to draw strokes. In order to give you more specific advice on how to do that you are going to have to post a minimal reproducible example of what you are trying to do.
QUESTION
I am a super early user of coding from Italy. I came up with an idea to promote a company logo on their website and I almost reached the goal so I am sharing this problem.
The idea is to obtain a sort of clipping mask effect when the mouse/cursor move on the image I've made so far a code that does the work with a still ellipse.
When I set the position parameters of the ellipse as mouseX and mouseY the effect does not work if not just a bit of a glitch at the start. How can I make it work as intended?
Here you can find the link of what I have now: https://editor.p5js.org/francesco.ficini.designer/full/FLBuhggW-
Here the code:
...ANSWER
Answered 2022-Mar-21 at 03:56The thing about the p5.Image.mask
function is that it modifies the image that is being masked. Which means that any pixels that are cleared by the mask are gone for good. So if you want to dynamically change the mask you will need to make a copy of the original and re-apply the modified mask any time it changes.
Additionally you will want to avoid creating images and graphics objects in your draw()
function because this can result in excessive memory allocation. Instead create a single set of graphics/images and re-use them.
QUESTION
What I am trying to create is a point and click adventure game with decisions that effect your outcome. So far, I have only added text so I wanted to upload images and use them in my scenes. One of my attempts to get this to work is as below as well as an example of one of the scenes. I also tried creating properties within the scene and then tried code something along the lines of image(scenes[pointer].sceneGraphic, scenes[pointer].graphicXPosition, scenes[pointer].graphicYPosition)
, which resulted in a possible scope error in the console.
The following code can be seen in full at this p5js editor link.
...ANSWER
Answered 2022-Mar-13 at 22:29The line containing if (scenes[pointer] == 4) {
should be if (pointer == 4) {
if you wanted the image to be drawn on the canvas. Changing that on your p5js editor link drew the cat image after pressing Space until it showed Scene 4.
As for setting images in each specific scene, you just need to reference the image when setting up each scene such as
QUESTION
I have seen some closed posts on GitHub, and the occasional unsolved similar question on random returns, but I can get a good explanation as to why on a simple print()
command of a defined object the object is being printed on the console seemingly in a loop:
I just started using p5js, and don't know javascript. So it may be where the commands are placed (function setup()
or function draw()
), which I am still unsure why they are defaulted on the editor start page, or else I need to specify that I want the result printed just once (?).
ANSWER
Answered 2022-Mar-10 at 20:37This happens because draw()
runs on a loop. Behind the scenes, the p5js library is using requestAnimationFrame
to call draw()
.
You could move the print
statement to be within the setup()
function, which only runs once at the start of the script.
QUESTION
I'm using p5js to turn some barnsley fern code into an object using the coding train's code.
I'm trying to animate it by changing one of the coefficients but I need the fern to at least render properly as an object first.
My issue is that the fern doesn't render correctly after I've ported the properties and methods into a barnsley fern object. The only thing that renders sometimes is the stem but none of the leaves do.
I've tried changing the order in the draw function, using a function factory approach and object literals but I keep getting the same result 😭
...ANSWER
Answered 2022-Mar-02 at 01:56You missed out updating r in the nextPoint() function
QUESTION
I'm really struggling here and I can't get it right, not even knowing why.
I'm using p5.js
in WEBGL mode, I want to compute the position of on point rotated on the 3 axes around the origin in order to follow the translation and the rotation given to object through p5.js, translation and rotatation on X axis, Y axis and Z axis.
The fact is that drawing a sphere in 3d space, withing p5.js
, is obtained by translating and rotating, since the sphere is created at the center in the origin, and there is no internal model giving the 3d-coordinates.
After hours of wandering through some math too high for my knowledge, I understood that the rotation over 3-axis is not as simple as I thought, and I ended up using Quaternion.js. But I'm still not able to match the visual position of the sphere in the 3d world with the coordinates I have computed out of the original point on the 2d-plane (150, 0, [0]).
For example, here the sphere is rotated on 3 axis. At the beginning the coordinates are good (if I ignore the fact that Z is negated) but at certain point it gets completely out of sync. The computed position of the sphere seems to be completely unrelated:
It's really hours that I'm trying to solve this issue, with no result, what did I miss?
Here it follows my code:
...ANSWER
Answered 2022-Feb-26 at 22:25I've finally sorted out. I can't really understand why works this way but I didn't need quaternion at all, and my first intuition of using matrix multiplications to apply rotation on 3-axis was correct.
What I did miss in first instance (and made my life miserable) is that matrix multiplication is not commutative. This means that applying rotation on x, y and z-axis is not equivalent to apply same rotation angle on z, y and x.
The working solution has been achieved with 3 simple steps:
- Replace quaternion with matrix multiplications using vectors (method
#resize2
) - Rotating the drawing plane with Z-Y-X order
- Doing the math of rotation in X-Y-Z order
QUESTION
The thing that i wanna do is similiar with this video. In p5.js, I am using get() function. After use this, I will create small images (by dividing big tileset) and push them into an array. But in my code get()
returns an empty pixels array. Here is a part of my code:
ANSWER
Answered 2022-Feb-23 at 20:00I believe the issue here is that you are not waiting for the image to actually be loaded. The loadImage
function is asynchronous. That is, it only starts the process of loading the image, but it returns before it actually finish loading the image. So any code that comes after that will run immediately, while the loading is still in progress. You can use the callback function to run code after loading is complete. Here's a modified version of your code that should alleviate the problem:
QUESTION
My logic is simple, create a state array and a stateIndex, when the user interacts with the drawing, save the current state as an entry in the array and increment the stateIndex.
When the user presses "undo" (for this sketch press any key), decrement the stateIndex and draw to the page whatever value is in state for that index.
I've implemented it in this sketch https://editor.p5js.org/mr_anonymous/sketches/s0C1M7x1w but as you can see instead of storing the last state of the drawing it seems to only store the blank state.
Anyone know what's going wrong?
Edit: Added source code
...ANSWER
Answered 2022-Feb-23 at 08:52You're using the set()
function incorrectly. While get()
can be used to get a p5.Image
object, there is no overload of set()
that takes one (a bit idiosyncratic, I know). Instead you'll want to use the image()
function:
QUESTION
I thought I had the hang of promises in all situations, but I'm stuck here: I'd like an animation to happen on a timer. The only thing I can get from the graphics package is the frame number, so I compute an end frame based on a frame rate estimate.
The graphics package is p5.js, which exposes frameCount
, that just runs up at about 60 fps on each draw cycle. (I named it currentFrame in this question, hoping that would clarify). As far as I can tell, this is the only visibility I get into the animation frame state in p5.js
ANSWER
Answered 2022-Feb-14 at 18:02Instead of storing the promise to resolve, you need to store the resolver to call:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install p5js
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page