MovingBall
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 - 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)
Developer | Anwesh Mishra |
Username | Anwesh43 |
Uploaded | January 08, 2023 |
Rating | 3 |
Size | 2,105 Kb |
Views | 14,168 |
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!
Name | Size |
Clapperboard | 2,540 Kb |
Fractal Spirograph | 2,501 Kb |
SettingButton | 2,255 Kb |
A Pen by Anwesh Mishra | 1,524 Kb |
SeeSaw | 2,195 Kb |
Html5CanvasPingPong | 2,033 Kb |
EllipticalSwitch | 2,077 Kb |
Material Boxes Animation | 2,257 Kb |
TumblingPins | 2,187 Kb |
Jumping Triangles | 2,350 Kb |
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!
Name | Username | Size |
Sticky footer testing | 75th | 1,649 Kb |
CMP5-Opdracht15 | SannevanGastel | 2,733 Kb |
Canvas snow | Win7killer | 2,572 Kb |
Toggle Time | Petebot | 5,345 Kb |
Canvas stripes | Adrianparr | 1,948 Kb |
Boxes | H3l1um | 2,563 Kb |
Box-sizing | Elad2412 | 1,572 Kb |
A Different Type of Gallery | DonPage | 2,950 Kb |
Perspective Origin Demo | Agelber | 3,614 Kb |
My Starter Kit For Codepen | Dkdesign | 2,012 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!