Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Raindrops
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.js"></script>
<script src="sketch.js"></script>
</head>
<body>
</body>
</html>
class Raindrop{
constructor(){
this.xPos = Math.random() * 500 + 1
this.yPos = Math.random() * 500 + 1
this.speed = Math.random() * 10 + 1
// Size
this.size = Math.random() * 40 + 1
// Color
this.r = Math.random() * 255
this.g = Math.random() * 255
this.b = Math.random() * 255
}
display(){
fill(this.r, this.g, this.b)
ellipse(this.xPos, this.yPos, this.size, this.size)
}
move(){
this.yPos += this.xPos / 50
this.yPos = this.yPos % 500
}
}
let raindropList = []
for(var i = 0; i<100; i++){
raindropList.push(new Raindrop())
}
// Setup screen
function setup() {
createCanvas(500, 500);
background(0, 100, 200);
}
function draw() {
background(0, 100, 200)
for(let j = 0; j<100; j++){
raindropList[j].display()
raindropList[j].move()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.