MovingBall

Developer
Size
2,105 Kb
Views
14,168

How do I make an movingball?

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

MovingBall Previews

MovingBall - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>MovingBall</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas id="c1" width="1000px" height="600px">
</canvas> <script src="js/index.js"></script>
</body>
</html>

MovingBall - Script Codes CSS Codes

#c1 { border:1px solid black;
}

MovingBall - Script Codes JS Codes

var canvas = document.getElementById('c1')
var context = canvas.getContext('2d')
var setDimensions = ()=> { canvas.width = window.innerWidth/2 canvas.height = ((window.innerHeight)/3)+((canvas.width)/20) context = canvas.getContext('2d')
}
window.onresize = ()=>{ setDimensions()
}
class ColorFullCircle { constructor(x,y) { this.x = x; this.y = y; this.rot = 0; this.dir = 1; } draw() { var l = [1,-1] var colors = ["#f44336","#3F51B5"] var r = canvas.width/20 for(var j=0;j<2;j++) { context.fillStyle = colors[j] context.save() context.translate(this.x,this.y) context.rotate(this.rot*Math.PI/180) context.scale(1,l[j]) context.beginPath() for(var i=0;i<=180;i++) { var x = r*Math.cos(i*Math.PI/180) var y = r*Math.sin(i*Math.PI/180) if(i == 0) { context.moveTo(x,y) } else { context.lineTo(x,y) } } context.fill() context.restore() } this.rot+=this.dir*20 this.x+=this.dir*20 this.x%=canvas.width } handleTap() { this.dir = this.dir == 0?1:0 }
}
var colorCircle = new ColorFullCircle(0,window.innerHeight/3)
function draw() { context.clearRect(0,0,canvas.width,canvas.height) context.fillStyle="#FF9800" context.fillRect(0,0,canvas.width,canvas.height) colorCircle.draw()
}
canvas.onmousedown = (event)=>{ colorCircle.handleTap()
}
setInterval(draw,100)
MovingBall - Script Codes
MovingBall - Script Codes
Home Page Home
Developer Anwesh Mishra
Username Anwesh43
Uploaded January 08, 2023
Rating 3
Size 2,105 Kb
Views 14,168
Do you need developer help for MovingBall?

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 Facebook ads 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!