sketch.js | Cross-Platform JavaScript Creative Coding Framework | Canvas library
kandi X-RAY | sketch.js Summary
kandi X-RAY | sketch.js Summary
A tiny (~2kb gzipped) platform for JavaScript creative coding. A few examples from the showcase.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Constructs a pointer event .
- Update the rendering .
- resize the canvas
- trigger pointer events
- Merge a mouse event .
- Clone object .
- Binds a node .
- augments target with a touch
- Destroy the context
- Extend the target object with another .
sketch.js Key Features
sketch.js Examples and Code Snippets
Community Discussions
Trending Discussions on sketch.js
QUESTION
I want to recursively produce the vertices (points) of a unit n-hypercube (for the sake of clarity, just a cube here). The idea is to specify the points of the cube by recursively going through the x, y, and z components. Why not just use nested for-loops? Recursion is intrinsically swag. This is my function:
...ANSWER
Answered 2022-Apr-15 at 04:11I think I solved the problem:
QUESTION
I have some simple code that I've written in Python. It's working. Now I'm trying to port it to JavaScript. The code is here. I'm getting this error:
...ANSWER
Answered 2022-Apr-02 at 18:56The error is here (Starting line 28).
QUESTION
I am using this jQuery plugin to make free drawing over a canvas.
I want to clear the canvas for redrawing but after I do and when I click inside canvas for redrawing the old drawing that I cleared appears again
ANSWER
Answered 2022-Mar-30 at 07:38You can try to save the state of the canvas as a blob. For example, as image/png. There are two bad things here:
A small inconvenience. Methods for converting a blob to an image and back are asynchronous. Promises have to be used.
Speed. I strongly doubt that this solution is suitable for tasks that require speed - games, videos, etc.
QUESTION
I'm trying to use Matter.Query.region
to see if the character in my game is grounded. But, when I try to run region
with a bounds object that I created (displayed with the dots shown in the game), it doesn't come up with any collisions even though it is clearly intersecting other bodies.
Code:
...ANSWER
Answered 2022-Mar-24 at 00:20The bounds object doesn't appear to be properly created. The purple p5 vertices you're rendering may be giving you a false sense of confidence, since those aren't necessarily related to what MJS sees.
It's actually a pretty simple fix, passing an array of vertices instead of individual arguments:
QUESTION
I've created a simple sketch using Instance Mode:
...ANSWER
Answered 2022-Jan-13 at 02:05The fallback when the div isn't found is by design, although if the div exists, p5 does indeed use it. Let's look at the source:
QUESTION
I'm currently making a 2D game in Javascript, but I want to the game to have different lighting levels, for example, if I were to create a day and night cycle. However, I want to be able to cut holes in the lighting/foreground, or do something so that I can make certain parts of the screen lit up, for example like a flashlight or candle. Note: I'm also using the P5.js library.
The most obvious idea that came to mind for going about in creating a foreground is just creating a rectangle with some opacity that covers the entire screen. This is good, but how am I supposed cut through this? Obviously, the code below won't work because I'm just layering on another element, and the rectangle is still obstructed and not perfectly clear.
...ANSWER
Answered 2022-Jan-22 at 03:11The erase()
function may be what you are looking for. It is more flexible than trying to explicitly paint over the areas you want to cover (such as in the approach of using the stroke of a circle and rectangle to cover everything except a circle). And it is easier to use than beginContour()
since you can use it with any of the built in drawing primitives (rect, ellipse, triangle, etc).
QUESTION
I'm trying to make a voice recorder visualizer where the shapes would interact with little squares that are being passed from the left to the right of the screen to make it seem like it's recording a voice note. For some reason, I cannot get the squares to space exactly how I want them to, so I decided to push one square out at a time and when that square reaches a certain part on the screen, another square would start from the beginning so they can move at the speed and have the distance between each other I would like.
The problem is when I get the square to reach a certain part on the screen, the other square does not add at all, I tried adding a fill to change the color to see what happens but it just changes the color of the current square and that's it.
...ANSWER
Answered 2022-Jan-17 at 21:26I believe you have fundamentally misunderstood how the rect()
function works. The rect()
function, and other shape drawing functions in p5.js, do not return a value. All shapes are draw in what is called "immediate mode" which means the shapes are drawn right away and are not persistent objects that can be manipulated. If you want to move a rectangle for example you need to clear the canvas and redraw the rectangle.
Here's is the most sensible adjustment of your sketch that I could come up with:
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:
QUESTION
I'm making a small animation in which the main square is rotating constantly. Now I wanted to add a trail to it so i searched online and watched a video by the Coding Train. Then I tried to rotate the particles, but when I try this everything just looks awful. I know that you can rotate things in p5 using the rotate()
function, but first you have to use translate()
and that can break everything.
I have used these functions, but as I mentioned before then everything just breaks. I want to ask You if there is any other way of rotating these particles at their center, which doesn't break everything.
Here is my code:
...ANSWER
Answered 2022-Jan-07 at 02:18Instead of drawing your particles at the position you want them translate them their instead. This allows the (0, 0) coordinate of the canvas to be positioned at the mouseX and mouseY. To center the particles at the (0, 0) of the canvas just draw them at -w/2
and -h/2
. Once you have them translated and rotated be sure to roate and translate them back to the original.
QUESTION
So what I am trying to do is make a clicker game, yet when I use the standard:
...ANSWER
Answered 2021-Dec-17 at 05:22In p5js you need to implement "hit testing" yourself. In this case you can do so by checking if the distance between the mouse and the center of the coin is less than the radius of the coin.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install sketch.js
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