Adding multi-colors to canvas particles

User Generated

ZeKbegnk

Programming

Description

Hello.

This is a particle system made using Javascript (CoffeeScript) http://cssdeck.com/labs/53gonama3x

How do I add more colors to the particles? Like Rainbow colors or RGB?

Thanks.


User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Try the below code snippet. (i+j)% number of colors will give value from 0 to number of colors-1. Each time you push a new particle value of i+j%5 will increase by 1. Use this fact to change the value of colors to one of your choice of color. In below I have chosen 5 values of colors at random which gives nice pattern. By the way, it's pretty cool code.

switch ((i+j)%5)
when 0 then colors = ['#FF2233']
when 1 then colors = ['#002233']
when 2 then colors = ['#FF33FF']
when 3 then colors = ['#0033FF']
when 4 then colors = ['#00FF00']
display_list.push new Particle(i)

Related Tags