File: flag.R

package info (click to toggle)
rgl 1.3.36-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,968 kB
  • sloc: cpp: 23,234; ansic: 7,462; javascript: 5,668; sh: 3,555; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 761 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

wave <- function(time) {
  x <- seq(0,2, len=100)
  
  wavefn <- function(x) x * sin(-5*time + 1.5 * (x/2) * 2*pi)/10
  deriv <- function(x) (wavefn(x + 0.01) - wavefn(x - 0.01))/0.02

  arclen <- cumsum(sqrt(1 + deriv(x)^2))*(x[2]-x[1])
  keep <- arclen < 2
  x <- x[keep]
  y <- matrix(wavefn(x), length(x),20)
  z <- matrix(seq(0,1, len=20), length(x), 20, byrow=TRUE)
  arclen <- arclen[keep]
  
  par3d(skipRedraw = TRUE)
  if (nrow(ids3d())) pop3d()
  surface3d(x,y,z, texture_s=matrix(arclen/2, length(x), 20), texture_t=z, col="white")
  c(list(skipRedraw = FALSE), spin(time))
}

open3d()
material3d(texture = system.file("textures","rgl2.png", package="rgl"))
spin <- spin3d(rpm=6,axis=c(0,0,1))
if (!rgl.useNULL())
  play3d(wave, 10, startTime = 5)