Skip to content

Instantly share code, notes, and snippets.

@mjard
Created April 25, 2010 20:30
Show Gist options
  • Save mjard/378697 to your computer and use it in GitHub Desktop.
Save mjard/378697 to your computer and use it in GitHub Desktop.
size(500, 425, P3D)
frameRate(30)
background(0)
noStroke()
val heart = {
val l = createGraphics(50,50,P3D)
l.beginDraw
l.noStroke
l.fill(255,0,0)
l.beginShape
l.vertex(25, 15)
l.bezierVertex(25, -5, 75, 5, 25, 40)
l.endShape
l.beginShape
l.vertex(25, 15)
l.bezierVertex(25, -5, -25, 5, 25, 40)
l.endShape
l.endDraw
l.loadPixels
l
}
val sceneMask = None :: Some(loadImage("meenuh.png")) :: None ::
Some(loadImage("x_x.png")) :: Nil
val red = color(255,0,0)
val black = color(0,0,0)
val sceneLength = 5 * frameRate.toInt // display each scene 5 seconds
def drawBlock(x: Int, y: Int, scene: Int, frame: Int, alpha: Float) {
sceneMask(scene) match {
case Some(mask) => {
if ((heart.pixels(y*heart.width+x) == red) &&
mask.pixels(y*mask.width+x) != black) {
fill(random(215,255),0,0)
} else {
fill(0,0,0,alpha)
}
}
case None => {
if (heart.pixels(y*heart.width+x)==red) {
fill(random(215,255),0,0)
} else {
fill(0,0,0)
}
}
}
rect(x*10,y*10,8,8)
}
def draw() {
// find scene number
val scene = (frameCount / sceneLength) % sceneMask.length
// find frame number in scene loop
val frame = (frameCount % (sceneLength * sceneMask.length))
// scale alpha based on time to end of scene
val alpha = ((frame % sceneLength) / sceneLength.toFloat) * 255
for (x <- 0 until 50) {
for (y <- 0 until 50) {
drawBlock(x,y,scene,frame,alpha)
}
}
}
@mjard
Copy link
Author

mjard commented Apr 26, 2010

More processing and scala

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment