+ 3

How to create an array of shapes(e.g. circles, rectangles) using just javascript?

26th May 2018, 11:39 AM
Akash Khobare
Akash Khobare - avatar
6 Answers
+ 6
Oh. If you mean draw shapes then you need canvas. To be able to draw using JavaScript, you need HTML as well Check the lesson👇 https://www.sololearn.com/learn/HTML/2201/
26th May 2018, 12:26 PM
Jonathan Pizarra
Jonathan Pizarra - avatar
+ 5
var shapes = ["circle", "square", "triangle", "rectangle"];
26th May 2018, 11:44 AM
Jonathan Pizarra
Jonathan Pizarra - avatar
+ 5
svg
27th May 2018, 10:09 PM
Real Gutch
Real Gutch - avatar
+ 4
i mean to create shapes like rectangle, circle in browser using JS
26th May 2018, 12:11 PM
Akash Khobare
Akash Khobare - avatar
+ 4
thank you for help 😊
26th May 2018, 12:28 PM
Akash Khobare
Akash Khobare - avatar
+ 4
create canvas element and define id ex: id="canvas1" canvas default size is width 300 height 150 move to js and get canvas id and create var for getContext var can = document.getElementById('canvas1') var ctx = can.getContext('2d') now we can draw in canvas ex: circle var x = 50; var y = 50; var r = 100; ctx.beginPath(); ctx.arc(x,y,r,0,360,false) ctx.fillStyle ='red'; ctx.fill(); ctx.stroke() ctx.closePath() x and y is move the center of circle to x coordinates and y coordinates r is for radius of circle 0 is for start of circle 360 is for end of circle 0,360 is full circle 0,180 is half circle 0,90 is half of half circle if you want to draw circle in counter clockwise set false to true fillStyle is define a color of circle default is black stroke is for stroke of circle u can set the stroke width ex : ctx.lineWidth = '10' closePath is for end the drawing copy paste this example to see the result
13th Jun 2018, 6:28 AM
Real Gutch
Real Gutch - avatar