Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Fill pixel by pixel #554

Closed
joex92 opened this issue Aug 31, 2021 · 4 comments
Closed

[Question] Fill pixel by pixel #554

joex92 opened this issue Aug 31, 2021 · 4 comments
Labels

Comments

@joex92
Copy link

joex92 commented Aug 31, 2021

Hi,
I'm working on a project where, part of it, I fill the canvas pixel by pixel with a Simplex Noise algorithm (I did it that way on p5).

I was thinking about doing it with a Two.Group with Two.Rectangles, but when doing it, the page freezes and fps drops. I suppose it's because the quantity of rectangle objects. Then I thought about using a Two.Points, but those doesn't let me change the color for each vertices, which would be good the be able to as I explained here: #553.

Looking up through Two. on console, I see that there is a Two.Gradient, would that be what I need? but how do I use it? There are only docs for Two.RadialGradient and Two.LinearGradient...

Is there another way to "paint" a shape/canvas with a better performance? or is there another alternative?

I want to do something like this but with color gradients and not characters...

@joex92
Copy link
Author

joex92 commented Sep 1, 2021

I was looking up for ways, and found that using a canvas type renderer I can create an ImageData object and set each pixel's value... that could work, but how do I add it to the Two canvas? I see there is a .makeImageSequence but It only accepts image files, I guess...
Also this could work only on a canvas renderer, how do I use it on a SVG renderer?

@jonobr1
Copy link
Owner

jonobr1 commented Sep 3, 2021

Sorry for the delay, if you'd like to "paint" like p5.js you can do this in the canvas and webgl renderers using the overdraw property when constructing Two.js like so:

var two = new Two({
  type: Two.Types.canvas,
  overdraw: true
}).appendTo(document.body);

This gives you the control to manually clear the canvas when you need or want to. So, you can make a Two.Points with one vertex and move it around. Here's an example of that: https://jsfiddle.net/jonobr1/w9ma4t5b/

@joex92
Copy link
Author

joex92 commented Sep 6, 2021

Interesting.. thanks, didn't know that... I´ll test this approach in my code...

@jonobr1
Copy link
Owner

jonobr1 commented Jan 20, 2022

Closing question due to inactivity

@jonobr1 jonobr1 closed this as completed Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants