Jump to content

Efficient way to fill the canvas with random pixels


rainerpl
 Share

Recommended Posts

Hi,

Im trying to make a simple app/feature, that fills an area with random pixels(random color at random time)
I have a working solution that is only a handful of lines of code, but its crazy slow. (uses WegGL and Nvidia GTX1060 gfx card + i7 cpu ).
The way i fill the canvas with random pixels at the moment is like this:
1) set interval that calls the drawRandomPixels function( it struggles to draw 1 frame every 250 ms )
2) loop over every pixel coordinate(x, y) and use 

this.contentGfx.fillColor = 0xFFFFFF * Math.random();
this.contentGfx.drawRect(x, y, 2, 2);

3) after all the pixels have been looped over, call the endFill() and render the stage.

Very simple and basic, yet it has massively worse FPS than what i get when i play Battlefield 5 on highest settings.

The area that im trying to fill is 250 x 250 canvas. I used 2x2 pixel size to get a bit better performance but its still damn awful.

Is there a better way to draw pixels in PIXI ?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...