processing-r/Processing.R

Add more examples

gaocegege opened this issue · 5 comments

  • R package examples I think are important for the same reason that me working through importLibrary Java examples was important
  • We need some fancy, short examples to show the capability of P.R.

There is a long discussion of potential R packages to try on #17 Support packages (libraries) in R. The most recent suggestion list was:

Processing Libraries

he_mesh generally works but there is a bug or feature in Renjin: bedatadriven/renjin#347

mesh <- 0
tree <- 0
render <- 0
rnds <- 0
randomRay <- 0
bias <- 0
growing <- 0
counter <- 0

settings <- function() {
    # Please install the peasycam before you run the example.
    importLibrary("hemesh")
    fullScreen(P3D)
    smooth(as.integer(8))
}

setup <- function() {
    render <- WB_Render$new(processing)
    rnds <- WB_RandomOnSphere$new()
    creator <- HEC_Beethoven$new()
  creator$setScale(5)$setZAngle(PI/3)
  mesh <- HE_Mesh$new(creator)
  mesh$simplify(HES_TriDec$new()$setGoal(0.5))
  tree <- WB_AABBTree$new(mesh, as.integer(10))
  
  growing <- TRUE
  counter <- 0
  bias <- rnds$nextVector()
}

createMesh <- function() {
  creator <- HEC_Beethoven$new()
  creator$setScale(5)$setZAngle(PI/3)
  mesh <- HE_Mesh$new(creator)
  mesh$simplify(HES_TriDec$new()$setGoal(0.5))
  tree <- WB_AABBTree$new(mesh, as.integer(10))
  
  growing <- TRUE
  counter <- 0
  bias <- rnds$nextVector()
}


draw <- function() {
  background(20)
  directionalLight(255, 255, 255, 1, 1, -1)
  directionalLight(127, 127, 127, -1, -1, 1)
  translate(width/2, height/2, 0)
  rotateY(map(mouseX, 0, width, -PI, PI))
  rotateX(map(mouseY, 0, height, PI, -PI))

#   hint(DISABLE_DEPTH_TEST)
  noLights()
  fill(255)
  noStroke()
  pushMatrix()
  scale(1.8)
  render$drawFaces(mesh)
  popMatrix()

#   hint(ENABLE_DEPTH_TEST)
  directionalLight(255, 255, 255, 1, 1, -1)
  directionalLight(127, 127, 127, -1, -1, 1)
  scale(1.6)
  fill(255)
  noStroke()
  render$drawFaces(mesh)
  noFill()
  stroke(0, 50)
  render$drawEdges(mesh)


  if (growing) {
    for (i in 0:5) {
        grow()
        counter <- counter + 1
    }
  }
  
  if (counter == 500) {
    mesh$subdivide(HES_CatmullClark$new())
    growing <- false
    counter <- counter + 1
  }
}

grow <- function() {
  rayOrigin <- WB_Point$new(bias)$mulSelf(-500)
  rayDirection <- bias$add(random(-0.3, 0.3), random(-0.3, 0.3), random(-0.3, 0.3))
  randomRay <- WB_Ray$new(rayOrigin, rayDirection)
  fi <- HET_MeshOp$getFurthestIntersection(tree, randomRay)
  point <- 0
  if (!is.null(fi)) {
    print(fi$point)
    point <- fi$point
    point$addMulSelf(120, randomRay$getDirection())
    HEM_TriSplit$splitFaceTri(mesh, fi$face, point)
    tree <- WB_AABBTree$new(mesh, 10)
    stroke(255,0,0)
    render$drawRay(randomRay,1500)
  }
}

mousePressed <-function() {
 createMesh()  
}

It looks like your comment above added a list of Processing(Java) libraries that are related to graphing. We already have a fairly basic example with grafica:

but grafica also supports allows some pretty advanced output for flashy demos -- including animation.

Cool, I will take a look