TumblingPins

Developer
Size
2,187 Kb
Views
6,072

How do I make an tumblingpins?

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

TumblingPins Previews

TumblingPins - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>TumblingPins</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>

TumblingPins - Script Codes CSS Codes

#c1 { border:1px solid #9E9E9E;
}

TumblingPins - Script Codes JS Codes

var canvas = document.getElementById('c1')
var context = canvas.getContext('2d')
class Pin { constructor(x,size) { this.x = x this.y = canvas.height/2 this.deg = 0 this.dir = 0 this.size = size } stop () { return this.dir == 0 } render() { var size = this.size context.strokeStyle = "#4CAF50" context.save() context.translate(this.x,this.y) context.rotate(this.deg*Math.PI/180) context.beginPath() context.moveTo(0,0) context.lineTo(0,-size) context.stroke() context.fillStyle = "#4CAF50" context.beginPath() context.arc(0,-size-size/18,size/9,0,2*Math.PI) context.fill() context.restore() } startUpdating() { this.dir = 1 } reset() { this.deg = 0 } update() { this.deg+=this.dir*15 if(this.deg == 90) { this.dir = 0 } }
}
var pins = []
var n = 6
var currentIndex = 0
var setDimensions = ()=>{ canvas.width = window.innerWidth/2 canvas.height = window.innerHeight context = canvas.getContext('2d') var gap = (canvas.width)/(n+1),x=gap/2 for(i=0;i<n;i++) { pins.push(new Pin(x,gap)) x+=gap } pins[currentIndex].startUpdating()
}
var reset = ()=> { setTimeout(()=>{ currentIndex = 0 pins.forEach((pin)=>{ pin.reset() }) if(pins.length>0) { pins[currentIndex].startUpdating() } },1000)
}
setDimensions()
setInterval(()=>{ context.clearRect(0,0,canvas.width,canvas.height) context.fillStyle="#FBC02D" context.fillRect(0,0,canvas.width,canvas.height) pins.forEach((pin)=>{ pin.render() pin.update() }) if(pins[currentIndex].stop()) { if(currentIndex < pins.length -1) { currentIndex++ pins[currentIndex].startUpdating() } else { reset() } }
},100)
TumblingPins - Script Codes
TumblingPins - Script Codes
Home Page Home
Developer Anwesh Mishra
Username Anwesh43
Uploaded January 08, 2023
Rating 3
Size 2,187 Kb
Views 6,072
Do you need developer help for TumblingPins?

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!