how to draw a flower in javascript
JavaScript
const ctx = canvas.getContext("2d");
const petal = [
[
[0, 0],
[0.3, -1],
[0.7, -1],
[1, 0],
[0.7, 1],
[0.3, 1],
[0, 0]
],
[
[0, 0],
[1, 0]
],
];
function drawPetal(path, width, height) {
var i = 0;
do { // loop through paths
const p = path[i];
let j = 0;
ctx.moveTo(p[j][0] * width, p[j++][1] * height);
while (j < p.length - 1) {
ctx.lineTo(p[j][0] * width, p[j++][1] * height);
}
if (p[j][0] === p[0][0] && p[j][1] === p[0][1]) { // is the path closed ?
ctx.closePath();
} else {
ctx.lineTo(p[j][0] * width, p[j][1] * height)
}
} while (++i < path.length);
}
function drawPetals(x, y, count, startAt, petal, width, height) {
const step = (Math.PI * 2) / count;
ctx.setTransform(1, 0, 0, 1, x, y);
ctx.rotate(startAt);
for (var i = 0; i < count; i += 1) {
drawPetal(petal, width, height);
ctx.rotate(step);
}
ctx.setTransform(1, 0, 0, 1, 0, 0); // restore default
}
function drawFlower(col, lineWidth, fitScale, petalCount) {
ctx.strokeStyle = col;
ctx.lineWidth = lineWidth;
const size = Math.min(ctx.canvas.width, ctx.canvas.height) * fitScale * 0.5;
ctx.beginPath();
drawPetals(ctx.canvas.width / 2, ctx.canvas.height / 2, 5, -Math.PI / 2, petal, size, size * 0.2);
ctx.stroke();
ctx.beginPath();
ctx.arc(ctx.canvas.width / 2, ctx.canvas.height / 2, size * 0.15, 0, Math.PI * 2);
ctx.fillStyle = col;
ctx.fill();
}
drawFlower("black", 4, 0.95, 5);
Also in JavaScript:
- Title
- disable copy past jquery
- Category
- JavaScript
- Title
- How to send JSON Web Token (JWT Token) as header with Postman and golang
- Category
- JavaScript
- Title
- angular local storage
- Category
- JavaScript
- Title
- edit onclick event
- Category
- JavaScript
- Title
- how to compare two strings in javascript if condition
- Category
- JavaScript
- Title
- how to use chart js in vue js
- Category
- JavaScript
- Title
- javascript array stackoverflow
- Category
- JavaScript
- Title
- how to do a classname variable and string react
- Category
- JavaScript
- Title
- format date js
- Category
- JavaScript
- Title
- access angular app outside localhost
- Category
- JavaScript
- Title
- event.stoppropagation
- Category
- JavaScript
- Title
- async await promise all javascript
- Category
- JavaScript
- Title
- how to update react context inside functional component
- Category
- JavaScript
- Title
- javascript check if value in array
- Category
- JavaScript
- Title
- find particular object from array in js
- Category
- JavaScript
- Title
- if statement in ejs
- Category
- JavaScript
- Title
- javascript class click event
- Category
- JavaScript
- Title
- firebase app named default already exists react native
- Category
- JavaScript
- Title
- como ler um arquivo json com javascript
- Category
- JavaScript
- Title
- install node js lts ubuntu 18.04
- Category
- JavaScript
- Title
- clear input field javascript
- Category
- JavaScript
- Title
- custom status discord bot
- Category
- JavaScript
- Title
- how to pass a value to a react funtion without immediately firing it
- Category
- JavaScript
- Title
- how to print two arrays together
- Category
- JavaScript
- Title
- delegate jquery
- Category
- JavaScript
- Title
- angular delete from array by name
- Category
- JavaScript
- Title
- how the concat function works javascript
- Category
- JavaScript
- Title
- javascript check if variable is number
- Category
- JavaScript
- Title
- firebase cloud functions send email
- Category
- JavaScript
- Title
- how to count the rows of gridview in asp.net using jquery
- Category
- JavaScript
- Title
- character to ascii in js
- Category
- JavaScript
- Title
- axios post with header
- Category
- JavaScript
- Title
- add char in specific index stirng javascript
- Category
- JavaScript
- Title
- javascript array of objects
- Category
- JavaScript
- Title
- how to setstate in parent in child component in react native
- Category
- JavaScript
- Title
- Add disclaimer for best browser experience in angular
- Category
- JavaScript
- Title
- how to disable cash through get request in angular
- Category
- JavaScript
- Title
- how to create simple node project
- Category
- JavaScript
- Title
- javascript base64 encode
- Category
- JavaScript
- Title
- angular moment pipe timeAgo
- Category
- JavaScript
- Title
- Cannot deserialize the current JSON array (e.g. [1,2,3]) into type
- Category
- JavaScript
- Title
- how to play sound on load js
- Category
- JavaScript
- Title
- difference between e.preventdefault and e.stoppropagation and return false
- Category
- JavaScript
- Title
- empty array js
- Category
- JavaScript
- Title
- Angular Quick Tip: Binding Specific Keys to the Keyup and Keydown Events
- Category
- JavaScript
- Title
- how to remove a property from an object in javascript
- Category
- JavaScript
- Title
- document queryselector click event
- Category
- JavaScript
- Title
- how to create response time router node js
- Category
- JavaScript
- Title
- if else javascript
- Category
- JavaScript
- Title
- hackerrank fizzbuzz javascript
- Category
- JavaScript
- Title
- factorial javascript
- Category
- JavaScript
- Title
- array shift javascript
- Category
- JavaScript
- Title
- alphabet array js
- Category
- JavaScript
- Title
- eslint ignore javascript
- Category
- JavaScript
- Title
- How can I refresh a page with jQuery
- Category
- JavaScript
- Title
- javascrip reverse text
- Category
- JavaScript
- Title
- how to transpose json data
- Category
- JavaScript
- Title
- email regex javascript
- Category
- JavaScript
- Title
- document delete element
- Category
- JavaScript
- Title
- how to do radio button validation in jquery
- Category
- JavaScript
- Title
- html loop through array
- Category
- JavaScript
- Title
- Alternating Sums
- Category
- JavaScript
- Title
- javascript click button by id
- Category
- JavaScript
- Title
- funciones invocan a funciones javascript
- Category
- JavaScript
- Title
- how to get timestamp in javascript of a date object
- Category
- JavaScript
- Title
- date add hours javascript
- Category
- JavaScript
- Title
- how to pass props in react test cases
- Category
- JavaScript
- Title
- get page resolution jquery
- Category
- JavaScript
- Title
- change title react
- Category
- JavaScript
- Title
- how to open bash_profile
- Category
- JavaScript
- Title
- call javascript function from html
- Category
- JavaScript
- Title
- how to add an array to another array in javascript
- Category
- JavaScript
- Title
- default props react
- Category
- JavaScript
- Title
- Failed to load module script: The server responded with a non-JavaScript MIME type of "application/json". Strict MIME type checking is enforced for module scripts per HTML spec.
- Category
- JavaScript
- Title
- copy one array to another javascript
- Category
- JavaScript
- Title
- discord js get badge user
- Category
- JavaScript
- Title
- error Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class.
- Category
- JavaScript
- Title
- function range() as range js
- Category
- JavaScript
- Title
- define maxmum size of schema field in nodejs
- Category
- JavaScript
- Title
- bq show pretty json
- Category
- JavaScript
- Title
- cannot add a child that doesn't have a yoganode touchablehighlight
- Category
- JavaScript
- Title
- get keys wher value is true in object in javascript
- Category
- JavaScript
- Title
- add all elements in array javascript
- Category
- JavaScript
- Title
- For-each over an array in JavaScript
- Category
- JavaScript
- Title
- if object is array javascript
- Category
- JavaScript
- Title
- how to add object to array javascript
- Category
- JavaScript
- Title
- how to scroll to an element javascript react
- Category
- JavaScript
- Title
- express validator always return error
- Category
- JavaScript
- Title
- how to create a global function in javascript and access local ?
- Category
- JavaScript
- Title
- how to make a grocery list in javascript
- Category
- JavaScript
- Title
- functions in map javascript
- Category
- JavaScript
- Title
- apache react deploy "conf"
- Category
- JavaScript
- Title
- cypress backspace
- Category
- JavaScript
- Title
- install react native
- Category
- JavaScript
- Title
- base64 decode javascript
- Category
- JavaScript
- Title
- get iso date javascript
- Category
- JavaScript
- Title
- How to append to a file in Node?
- Category
- JavaScript
- Title
- angularjs interceptor
- Category
- JavaScript
- Title
- get erquest jquery
- Category
- JavaScript
- Title
- callback in response node.js
- Category
- JavaScript