Created
April 25, 2010 20:30
-
-
Save mjard/378697 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More processing and scala