+ 10

How to make different objects in canvas

I have made a drawing[ star] and now i want that multiple stars like that can be created..My question is can i reference that star drawing..Maybe i can make it a object and then but i am not able to do that...Can anyone plz help me to do this

29th May 2017, 9:58 AM
Nikhil
Nikhil - avatar
4 Answers
+ 13
you can create an array to hold the coordinates of the starts and then iterate all over them, drawing each one
29th May 2017, 10:00 AM
Burey
Burey - avatar
+ 11
first, how do you draw the star? it could help if i have more info the general idea is a function that draws an object at a given points (given as parameters) from there it's simply sending different parameters each time imagine we drawing a rectangles with x,y width and height function drawObj(obj){ draw(obj.x, obj.y, obj.width, obj.width) } of course this is just a simplified code but the idea is that you can call the function like so if you have an array of objects: for(var i=0;i<objects.length;i++){ drawObj(objects[i]); } and each object will be drawn on a different place
29th May 2017, 12:27 PM
Burey
Burey - avatar
+ 4
Burey i didn't got you can you elaborate plz
29th May 2017, 12:19 PM
Nikhil
Nikhil - avatar
29th May 2017, 4:08 PM
The Coding Sloth
The Coding Sloth - avatar