jpgグリッチさせてパラパラまんが仕立てに

Glitch TV from nbqx on Vimeo.

インスタンスつくる時点でグリッチさせて,30fpsでランダムに置きかえていく的な.なので結果としてパラパラまんが風になります.動画自体はprocessing.orgのMovieMakerクラスでmov吐き出しました.

なにも考えずにかいたのでロジック的に画像が増えればたぶん破綻するはず… はじめ画像はSafariが勝手につくるウェブページのキャッシュ画像(osxだとホームのLibrary/Caches/com.apple.Safari/Webpage Previewsの中にあるやつ)をネタにして,10秒間ぐらいで大量のウェブサイトが閲覧できるものにしようとおもったけど,途中で破綻するのに気づいたのでやめました.

import processing.core.*
import javax.swing.JFrame

class GlitchTV extends PApplet{
	Integer img_num = 10
	List imgs = []
	def idx

	public GlitchTV(){
		collectImgs(~/[^0-9]{3}.*\.jpg$/){f->
			img_num.times{i->
				glitch("00${i}", f.name)}}
	}

	void setup(){
		frameRate(30)
		size(640,480)
		background(0)
		smooth()
		
		collectImgs(~/.*\.jpg$/){f-> loadImage(f.name)}
	}

	void draw(){
		idx = Math.round((imgs.size()-1)*Math.random()) as Integer
		imageMode(CENTER)
		try{
		image(imgs[idx], width/2 as Float,height/2 as Float, width, height)
		}catch(e){println idx}
	}

	void collectImgs(p, Closure clo){
		new File("data").eachFileMatch(p){f->
			def ret = clo(f)
			if(ret!=null){
				imgs.push(ret)}
		}
	}

	def glitch(String id, String filename){
		def file = new File("data/${id}_"+filename)
		file.withOutputStream{f->
			def r = {Math.round(Math.random()*10)}
			f.write((new File("data/"+filename).readBytes()).collect{("${it}"=="9"&&r()%2==0)?Byte.parseByte("${r()}"):it}as Byte[])
		}
	}
}

app = new GlitchTV()
app.init()
jframe = new JFrame(title:"GlitchTV",resizable:true).with{
	add(app)
	pack()
	defaultCloseOperation = JFrame.EXIT_ON_CLOSE
	resizable = true
	visible = true
}