import processing.core._
import PConstants._
import processing.core.PApplet._
import scala.collection.parallel.mutable
/** * Created by martin.silberkasten on 16/07/2014. */
class sketch2 extends PApplet{
var lst= List.fill(200)((new PVector(),random(1,25)))
var g1, g2, g3, m1, m2:PGraphics = null
override def setup{
size(400,400, P2D)
background(255)
stroke(255)
noFill()
lst.foreach(x=>x._1.set(random(width),random(height)))
g1=createGraphics(width,height, P2D)
g2=createGraphics(width,height, P2D)
g3=createGraphics(width,height, P2D)
m1=createGraphics(width,height, P2D)
m2=createGraphics(width,height, P2D)
}
override def draw{
moveFigures()
drawFigures(g1,(g,t) => fill() g.rect(t._1.x,t._1.y,t._2,t._2))
drawFigures(g2, (g,t) => g.triangle(t._1.x,t._1.y+t._2, t._1.x+t._2,t._1.y+t._2, t._1.x+t._2/2,t._1.y))
drawFigures(g3, (g,t) => g.ellipse(t._1.x+t._2/2,t._1.y+t._2/2,t._2,t._2))
drawMask(m1, 0)
drawMask(m2, QUARTER_PI)
//image(m.get(),0,0)
image(g1,0,0)
val tmpG2 = g2.get()
tmpG2.mask(m1.get())
image(tmpG2,0,0)
val tmpG3 = g3.get()
tmpG3.mask(m2.get())
image(tmpG3,0,0)
if(frameCount%2==0) saveFrame(“####.png”)
}
def moveFigures(){
for((p,s)<-lst) {
p.add(PVector.fromAngle(noise(p.x * 0.01f, p.x * 0.01f) * PI - HALF_PI))
if(p.x>width) p.set(-s,random(height))
if(p.y>height) p.set(p.x,-s)
if(p.y+s<0) p.set(p.x,height)
}
}
def drawFigures(g: PGraphics,f:(PGraphics, (PVector, Float))=>Unit){
g.beginDraw()
g.background(0)
lst.foreach(x=>f(g,x))
g.endDraw()
}
def drawMask(m:PGraphics,offset:Float){
m.beginDraw()
m.background(0)
m.fill(255)
val s = abs(sin(frameCount*0.05f+offset))*550
m.ellipse(width/2, height/2, s, s)
m.endDraw()
}
}
Warehouse of coding ideas..