SeeSaw
How do I make an seesaw?
What is a seesaw? How do you make a seesaw? This script and codes were developed by Anwesh Mishra on 08 January 2023, Sunday.
SeeSaw - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>SeeSaw</title>
</head>
<body> <canvas id="c1" width="500px" height="500px">
</canvas> <script src="js/index.js"></script>
</body>
</html>
SeeSaw - Script Codes JS Codes
var canvas = document.getElementById('c1')
var context = canvas.getContext('2d')
var setDimension = () => { canvas.width = window.innerWidth canvas.height = window.innerHeight
}
setDimension()
window.onresize = ()=>{ setDimension() init()
}
class Bar { constructor(x,y,w,h) { this.x = x this.y = y this.w = w this.h = h this.deg = 0 this.dir = 1 } draw() { context.fillStyle = "#FFC107" context.save() context.translate(this.x,this.y) context.rotate(this.deg*Math.PI/180) for(var i=0;i<2;i++) { context.save() context.scale((i*2-1),1) context.fillRect(0,-this.h,this.w,this.h) this.drawHandler() context.restore() } context.restore() } drawHandler() { context.fillStyle="#FFC107" context.fillRect(4*this.w/5,-2*this.h,this.w/10,this.h) } update() { this.deg+=this.dir*6 if(this.deg<=-30) { this.dir = 1 } if(this.deg>=30) { this.dir = -1 } } handleTap(x,y) { var handler1XL = this.x-(4*this.w)/5-this.w/10 ,handler1XH = handler1XL+(this.w/10) var handler2XL = this.x+(4*this.w)/5,handler2XH = handler2XL +(this.w/10) var handlerYL = this.y-(2*this.h),handlerYH = handlerYL+this.h if(y>=handlerYL && y<=handlerYH && this.deg == 0) { if(x>=handler1XL && x<=handler1XH) { this.dir = -1; } else if(x>=handler2XL && x<=handler2XH) { this.dir = 1; } } }
}
class Pivot { constructor(x,y,size) { this.x = x this.y = y this.size = size } draw() { var x = this.x,y = this.y,size = this.size context.fillStyle="#FFC107" context.beginPath() context.moveTo(x,y) context.lineTo(x+size/2,y+size/2) context.lineTo(x-size/2,y+size/2) context.fill() }
}
var t = 0,frames = 5
var rotatingBar
var pivot
var init = ()=>{ pivot = new Pivot(canvas.width/2,canvas.height/2,canvas.width/40) rotatingBar = new Bar(canvas.width/2,canvas.height/2,canvas.width/10,canvas.height/20) t = 0
}
init()
canvas.onmousedown = (event) => { console.log(event) var x = event.offsetX,y = event.offsetY rotatingBar.handleTap(x,y)
}
function draw() { context.clearRect(0,0,canvas.width,canvas.height) context.fillStyle="#00BCD4" context.fillRect(0,0,canvas.width,canvas.height) rotatingBar.draw() pivot.draw() if(t%5 == 0) { rotatingBar.update() } t++ window.requestAnimationFrame(draw)
}
window.requestAnimationFrame(draw)
Developer | Anwesh Mishra |
Username | Anwesh43 |
Uploaded | January 08, 2023 |
Rating | 3 |
Size | 2,195 Kb |
Views | 6,072 |
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 |
MovingBall | 2,105 Kb |
Material Boxes Animation | 2,257 Kb |
TumblingPins | 2,187 Kb |
Fractal Spirograph | 2,501 Kb |
SettingButton | 2,255 Kb |
EllipticalSwitch | 2,077 Kb |
A Pen by Anwesh Mishra | 1,524 Kb |
Html5CanvasPingPong | 2,033 Kb |
Clapperboard | 2,540 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 |
Dragonball Dragon Radar | DouglasGlover | 2,157 Kb |
Board Site | IndianaLuft | 10,542 Kb |
Single element checkbox | Ivijaygupta | 1,996 Kb |
Cool audio | Bigliam | 1,868 Kb |
Sticky footer testing | 75th | 1,649 Kb |
CSS3 Form | Tusharbandal | 1,836 Kb |
CSS3 Media Queries demo | Machal | 1,824 Kb |
Webkit decolorize | Fivera | 1,675 Kb |
Addthis_button | Esambino | 1,691 Kb |
Caputre Cam with JS | KimmoCommit | 2,795 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!