SettingButton

Developer
Size
2,255 Kb
Views
6,072

How do I make an settingbutton?

What is a settingbutton? How do you make a settingbutton? This script and codes were developed by Anwesh Mishra on 08 January 2023, Sunday.

SettingButton Previews

SettingButton - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>SettingButton</title>
</head>
<body> <canvas id="canv" width ="600px" height="600px">
</canvas> <script src="js/index.js"></script>
</body>
</html>

SettingButton - Script Codes JS Codes

const canvas = document.getElementById('canv')
const context = canvas.getContext('2d')
const backgroundColor = "#FF5722"
const coordScales = [{x:1,y:1},{x:2,y:3},{x:3,y:1}]
var coords = []
var settingButtons = []
class SettingButton { constructor(x,y) { this.x = x this.y = y this.r = canvas.height/10 this.angle = 0 this.dir = 0 } draw() { context.save() context.translate(this.x,this.y) context.rotate(this.angle*Math.PI/180) context.fillStyle="#616161" context.beginPath() context.moveTo(this.r,0) for(var deg=0;deg<360;deg+=2) { if(deg%20 == 0) { var firstPoint = this.getPositionInCircle(deg+5,this.r/2) context.lineTo(firstPoint.x,firstPoint.y) var secondPoint = this.getPositionInCircle(deg+15,this.r/2) context.lineTo(secondPoint.x,secondPoint.y) if(time == 0) { console.log(`${this.x},${this.y}`) } deg+=20 } else { var point = this.getPositionInCircle(deg,0) context.lineTo(point.x,point.y) } } context.fill() context.fillStyle = backgroundColor context.beginPath() context.arc(0,0,this.r/2,0,2*Math.PI) context.fill() context.restore() } getPositionInCircle(deg,gap) { return {x:(this.r+gap)*Math.cos(deg*Math.PI/180),y:(this.r+gap)*Math.sin(deg*Math.PI/180)} } update() { this.angle+=this.dir*15 if(this.angle % 90 == 0) { this.dir = 0 } } handleTap(x,y) { if(x>=this.x-this.r && x<=this.x+this.r && y>=this.y-this.r && y<=this.y+this.r) { this.dir = this.dir == 0?1:this.dir } }
}
const initDimensions = ()=>{ canvas.width = window.innerWidth canvas.height = window.innerHeight coords = coordScales.map((coordScale)=>{ return ({x:coordScale.x*canvas.width/4,y:coordScale.y*canvas.height/4}) }) console.log(coords) settingButtons = coords.map((coord)=>new SettingButton(coord.x,coord.y))
}
initDimensions()
window.onresize = () => { initDimensions()
}
var time = 0
const render = () => { context.clearRect(0,0,canvas.width,canvas.height) context.fillStyle = backgroundColor context.fillRect(0,0,canvas.width,canvas.height) settingButtons.forEach((settingButton)=>{ settingButton.draw() if(time%8 == 0) { settingButton.update() } }) time++ window.requestAnimationFrame(render)
}
canvas.onmousedown = (event) => { settingButtons.forEach((settingButton)=>{ settingButton.handleTap(event.offsetX,event.offsetY) })
}
window.requestAnimationFrame(render)
SettingButton - Script Codes
SettingButton - Script Codes
Home Page Home
Developer Anwesh Mishra
Username Anwesh43
Uploaded January 08, 2023
Rating 3
Size 2,255 Kb
Views 6,072
Do you need developer help for SettingButton?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Anwesh Mishra (Anwesh43) Script Codes
Create amazing art & images with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!