さいきんスケッチしてないので

ちょっと時間ができたのでひさびさの写生.とはいっても元ネタはOpenProcessingからですが.

http://www.openprocessing.org/visuals/?visualID=9315

もちょっとヒマになったらいろいろ考えてるのでやりたいです.

http://dl.dropbox.com/u/264798/100512.jpg

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

class Line extends PApplet{ 
  App app
  Float alpha
  Float delta
  Float period
  Float phase
  Float radius 
  def x = []
  def y = []

  Line(App a, Integer i){
	app = a 
	alpha = random(360f)
	period = random(-10.0f,10.0f)
	radius = ((app.width/app.columns) / 3) as Float
	delta = random(0.5f, 4.0f)
	phase = random(360f)
  }

  def update(){ 
	alpha += delta
	app.divisions.times{i-> m
	  float angle = radians((phase + alpha + (period * i)) as Float)
	  x[i] = radius * sin(angle)
	  y[i] = app.offset + i * app.line_height()
	}
  }

  def getX = { Integer i->
	return (x[i] as Float)
  }

  def getY = { Integer i->
	return (y[i] as Float)
  }
}

class App extends PApplet{
  def lines = []
  def columns = 20
  def divisions = 100
  def offset = 20
  
  def line_height = { (height / divisions) as Float}
  def line_width = { (width / columns) as Float}

  void setup(){
	smooth()
    size(1020, 400)
  	columns.times{ 
	  lines[it] = new Line(this, it)
	}
  }

  void draw(){
    before()
    doing()
    after()
  }

  def before = {
	background(100,100,100)
  }

  def doing = {
	stroke(200,40,115)
	fill(200,40,115)
	
	columns.times{i->
	  lines[i].update()
	  
	  (divisions-2).times{j->
		def x0 = ((i + 0.5) * line_width() + lines[i].getX(j)) as Float
		def y0 = lines[i].getY(j)
		def x1 = ((i + 0.5) * line_width() + lines[i].getX(j+1)) as Float
		def y1 = lines[i].getY(j+1)
		
		if((j&1)==0){ 
		  quad(i*line_width() as Float, j*line_height() as Float, x0, y0, x1, y1, i*line_width() as Float, (j+1)*line_height() as Float)
		  quad(x0, y0, (i+1)*line_width() as Float, j*line_height() as Float, (i+1)*line_width() as Float, (j+1)*line_height() as Float, x1, y1)
		}
	  }
	}
  }

  def after = {}

  def update(String name, Closure clo){
    clo.delegate = this
    this."${name}" = clo
  }
}

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