Sketches | Creative coding sketches made with Java | Code Editor library
kandi X-RAY | Sketches Summary
kandi X-RAY | Sketches Summary
This project contains my newest Processing sketches. The finished animations can be found on my Instagram and Reddit.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Draw the image
- Get the canvas as a shader
- Provides a visualization for the selected ray key shader
- Draw the slider
- Creates a radio button in the current group
- Draws this graph
- Draw the tree
- Draw the outline
- Drawer ellipses around the specified detail
- Draw the frame
- Draw the image mirror
- Draw the gradient
- Draw the image
- Draw the gauge
- Draw a sphere
- Starts the static shader
- Draw the grid
- Draws this image
- Draws the circle s circles
- Draws the background
- Draw the background
- Draws the polygon
- Draws the grid
- Draws the slider
- Draw the background
- Draws the gauge
Sketches Key Features
Sketches Examples and Code Snippets
Community Discussions
Trending Discussions on Sketches
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
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'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
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
In the following p5.js code I'm trying to create 2 separate methods.
centerInWindow()
is meant to keep the image centered in the canvas while it's being scaled down after the user clicks on the canvas.
centerToClick()
is meant to keep the image centered on the point the user clicked on, while it's being scaled up.
None of them work and I'm having trouble getting the logic right.
...ANSWER
Answered 2022-Jan-28 at 03:39There are probably multiple ways to solve this problem, but here's one:
Imaging your viewport is an NxM rectangle, and you are drawing some portion of a scene in within that viewport. In order to zoom in and out you can shift the origin at which you draw that scene and increase or decrease the scale. The tricky part is to make it possible to zoom in and out centered on an arbitrary point within the currently visible portion of the scene, keeping that point in the scene locked to the current point in the viewport.
Given some center point, and a desired scale factor, it is possible to determine the necessary change in the offset of the scene to preserve the position of the center point after scaling.
There's probably some complicated trigonometric proof for how to calculate this, but conveniently it is a simple calculation based on the ratio of the offset of the mouse from the current top left of the scene, to the scaled height of the scene.
QUESTION
A common pattern in Arduino C++ sketches is the use of Serial.print()
or Serial.println()
to debug problems.
What is the corresponding Rust idiom when programming for the Arduino Uno?
...ANSWER
Answered 2022-Jan-27 at 18:21One technique involves the use of arduino_hal::default_serial!
and ufmt::writeln!
For setup:
QUESTION
TL;DR Why isn't the ball bouncing off of the edge in the link below?
I'm currently going through the CodingTrain P5JS videos. What I'm trying to achieve is a simple toggle button:
https://editor.p5js.org/S_Oda/sketches/uF_dgcQP-
When the button is 'on' it changes to red and the ball moves until it hits the left or right edge where it will bounce off and change to the opposite direction. When the button is toggled 'off' the ball will freeze in place, it will resume movement when the button is pressed again.
My problem is, when the ball hits the edge, it seems to glitch in place. The bouncing was working before I introduced the toggle button. The resoning for my code is that if I tie the 'speed' variable of the ball to be dependant on a boolean ("ballState"), then the button can just change whether 'ballState' is true or false, i.e. move or not move. So I'm wondering if the problem is here somewhere:
...ANSWER
Answered 2022-Jan-12 at 15:17The problem is mostly this, which runs every frame in the draw
function:
QUESTION
I want to turn this halting, discontinuous trails in the particle on this simulation
to something worth staring at as in this beautiful field flow in here (not my work, but I don't remember where I got it from).
I have tried different permutations of the code in the accomplished field flow without getting anything remotely close to the smoothness in the transitions that I was aiming for. I suspect I am mishandling the updates or the placement of the black rectangle that seems to circumvent the need for a black background, which would erase the wake of the particles.
...ANSWER
Answered 2022-Jan-11 at 17:55You can get trials in multiple ways. The sketch you mentioned creates the trails by adding opacity to the background with the "fill( 0, 10 )" function.
If you want to know more about p5 functions you can always look them up here: https://p5js.org/reference/. The fill() page shows that the first argument is the color ( 0 for black ) and the second argument is the opacity ( 10 out of 255 ).
In the sketch you mentioned, in draw(), they wrote:
QUESTION
I got half-way through what I wanted in the representation of physics vector fields in 2D with p5js here. The other half is to get random particles to dynamically follow the forces of the vector field, and I am having a lot of problems with it. I have tried multiple things to take into account the wrap-around of the particles, as well as the fact that I am translating the origin of the plot to the center of the canvas. However, the particles seem minimally affected by the individual vectors in the field, and ultimately march along the x axis with slight bumpiness.
The fact that I am completely new at JS doesn't help splice all these elements from several presentations available online, and I would appreciate any advise as to what may be going wrong, and where I should focus on.
Here is what I have so far: a file sketch.js
corresponding to my own answer quoted above:
ANSWER
Answered 2022-Jan-09 at 22:38I found the mixing of coordinate systems very confusing in your code. I think it is better to have the particles and the flow field vectors both exist in the same coordinate system, here is an example:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Sketches
You can use Sketches like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the Sketches component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
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