Adding multi-colors to canvas particles

Question Description

I need an explanation for this Programming question to help me study.


This is a particle system made using Javascript (CoffeeScript)

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


Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

Final 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)

University of Virginia

Top quality work from this tutor! I’ll be back!

It’s my second time using SP and the work has been great back to back :) The one and only resource on the Interwebs for the work that needs to be done!

Thanks, good work


Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors