Skip to content

Instantly share code, notes, and snippets.

@davepagurek
Created August 18, 2020 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davepagurek/490c53f02f8039d6000ea0367900817e to your computer and use it in GitHub Desktop.
Save davepagurek/490c53f02f8039d6000ea0367900817e to your computer and use it in GitHub Desktop.
diff --git a/oldsketch.txt b/newsketch.txt
index 96a0e16..a45a764 100755
--- a/oldsketch.txt
+++ b/newsketch.txt
@@ -113,6 +113,13 @@ class Shape {
this.img = random(imgs);
}
this.scale = random(0.2,1.0);
+ this.opacity = random(100, 255)
+
+ this.canvas = createGraphics(this.img.width * this.scale, this.img.height * this.scale)
+ this.canvas.scale(this.scale)
+ this.canvas.tint(255,255,255,this.opacity)
+ this.canvas.image(this.img, 0, 0)
+
let startingPosition = randomOffscreen(this.img,this.scale) //look at image and its
//size
let endingPosition = randomOffscreen(this.img,this.scale)
@@ -127,8 +134,6 @@ class Shape {
this.exitx = endingPosition.x;
this.exity = endingPosition.y;
-
- this.opacity = random(100, 255)
this.dead = false
if (useStagger) { //if useStagger==true
this.stagger = random(0,2000)
@@ -154,6 +159,7 @@ class Shape {
// if current time is after time of death
if (millis() > this.endExitTime) {
this.dead = true
+ this.canvas.remove()
} else if (millis() > this.beginExitTime) { //when shapes are in process of leaving
//we set where they're leaving from and where they're moving to
fromx = this.targetx
@@ -180,12 +186,12 @@ class Shape {
}
display() {
- push()
- imageMode(CENTER);
- translate(this.x,this.y)
- scale(this.scale)
- tint(255,255,255,this.opacity)
- image(this.img,0,0)
- pop()
+ if (!this.dead) {
+ push()
+ imageMode(CENTER);
+ translate(this.x,this.y)
+ image(this.canvas,0,0)
+ pop()
+ }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment