Skip to content

Instantly share code, notes, and snippets.

@Akiyah
Created December 16, 2014 01:02
Show Gist options
  • Save Akiyah/4ed7cde5425d28f99097 to your computer and use it in GitHub Desktop.
Save Akiyah/4ed7cde5425d28f99097 to your computer and use it in GitHub Desktop.
jibanyan_equation_edit
# plus
"%+%" <- function(f, g) {
return(paste0("(", f, ") * (", g,")"))
}
# minus
m <- function(f) {
paste0( "-(", f, ")" )
}
# intersection
"%I%" <- function(f, g) {
paste0( "min(", f, ",", g, ")" )
}
# cut
"%C%" <- function(f, g) {
f %I% m(g)
}
mirror <- function(f) {
gsub("x", "abs(x)", f)
}
union <- function(...) {
paste0("MAX(", paste0(c(...), collapse=","), ")")
}
ellipse <- function(ox,oy,rx,ry) {
xpart <- ifelse (ox == 0, "x", paste0("(x-",ox,")"))
ypart <- ifelse (oy == 0, "y", paste0("(y-",oy,")"))
paste0("1-(",xpart,"/",rx,")^2-(",ypart,"/",ry,")^2")
}
library(rgl)
draw <- function(f_str, name="") {
f_str <- gsub("MAX", "max", f_str)
f_str <- gsub("--", "+", f_str)
print(f_str)
f <- parse(text=f_str)
n <- 400
#n <- 200
xx <- seq(-150, 150, length = n)
yy <- seq(-150, 150, length = n)
zz <- outer(xx, yy, Vectorize(function(x, y) { eval(f) }))
png(filename=paste0("png/graph_", name, ".png"), width=480, height=480)
contour(xx, yy, zz, drawlabels=FALSE, levels=0, lwd=1)
dev.off()
logz <- -log(-pmin(zz,0)+1)
clear3d(type = "all")
par3d(windowRect=c(65, 52, 65+480, 52+480))
light3d(diffuse="gray90", specular="gray90")
bg3d("gray10")
surface3d(xx, yy, logz, color = "#FFFFFF")
#aspect3d(1,1,0.5)
aspect3d(1,1,1)
view3d(20, 10, zoom = 1)
rgl.snapshot(paste0("png/snapshot_", name, ".png"))
}
rm(list=ls())
source('function_dsl.r')
source('function_viewer.r')
upside <- "y"
out_bottomline <- paste0(53+2, "+y")
in_bottomline <- "53+y"
center <- "51-x"
face_width <- "92-x"
ear_cut <- "2*(x-75)-3*abs(y-100)"
hairline <- paste0("1-(abs(x/51+10/51*sin(abs(y/", (1.2*51), ")^(1.2)*pi*(7/2)))^(2/3))-(abs(y/", (1.2*51), ")^(2/3))")
out_face <- ellipse(0,0,106+2,92+2)
out_ear_top <- ellipse(119,56,101+2,84+2)
out_ear_bottom <- ellipse(15,119,75+2,98+2)
in_face <- ellipse(0,0,106,92)
in_ear_top <- ellipse(119,56,101,84)
in_ear_bottom <- ellipse(15,119,75,98)
in_ear_middle <- ellipse(86+10+3,46+5+3,40,86)
out_eye <- ellipse(51,0,11+2,11+2)
in_eye <- ellipse(51,0,11,11)
out_cheek <- ellipse(42,0,64+2,53+2)
in_cheek <- ellipse(42,0,64,53)
cheek_inline <- ellipse(55-3,-28,24+2,24+2)
nose <- ellipse(0,-30,32,32)
nose_bottom <- ellipse(-5,18,22,22)
mouse_top <- ellipse(18, -10, 20, 20)
mouse_bottom <- ellipse(20, -7, 22, 20)
jibanyan <- (
mirror(
union(
(out_face %I% upside),
(out_ear_top %I% out_ear_bottom),
out_cheek,
(out_bottomline %I% center %C% upside)
)
)
%C% ear_cut
%+% (
mirror(
union(
(in_face %I% upside),
(in_ear_top %C% in_ear_middle %I% face_width),
in_cheek
)
%C% (
union(
cheek_inline,
out_eye,
(center %C% upside)
)
)
)
%C% hairline
)
%+%
mirror(
(nose %I% nose_bottom)
%+% (mouse_top %C% mouse_bottom)
%+% in_eye
)
)
draw(jibanyan, "jibanyan")
# 説明用
f1 <- (
out_ear_top
)
draw(f1, "f1")
f2 <- (
out_ear_bottom
)
draw(f2, "f2")
f3 <- (
(out_ear_top %I% out_ear_bottom)
)
draw(f3, "f3")
f4 <- (
mirror(
union(
(out_ear_top %I% out_ear_bottom)
)
)
)
draw(f4, "f4")
f5 <- (
mirror(
union(
(out_ear_top %I% out_ear_bottom),
out_face
)
)
)
draw(f5, "f5")
f6 <- (
mirror(
union(
(out_ear_top %I% out_ear_bottom),
(out_face %I% upside)
)
)
)
draw(f6, "f6")
f7 <- (
mirror(
union(
(out_ear_top %I% out_ear_bottom),
(out_face %I% upside),
out_cheek,
(out_bottomline %I% center %C% upside)
)
)
)
draw(f7, "f7")
f8 <- (
mirror(
union(
(out_ear_top %I% out_ear_bottom),
(out_face %I% upside),
out_cheek,
(out_bottomline %I% center %C% upside)
)
)
%C% ear_cut
)
draw(f8, "f8")
g5 <- (
mirror(
union(
(in_face %I% upside),
(in_ear_top %C% in_ear_middle %I% face_width),
in_cheek
)
%C% (
union(
cheek_inline,
out_eye,
(center %C% upside)
)
)
)
)
draw(g5, "g5")
h6 <- (
hairline
)
draw(h6, "h6")
g6 <- (
mirror(
union(
(in_face %I% upside),
(in_ear_top %C% in_ear_middle %I% face_width),
in_cheek
)
%C% (
union(
cheek_inline,
out_eye,
(center %C% upside)
)
)
)
%C% hairline
)
draw(g6, "g6")
fg <- (
f8 %C% g6
# %+%
# mirror(
# (nose %I% nose_bottom)
# %+% (mouse_top %C% mouse_bottom)
# #%+% in_eye
# )
)
draw(fg, "fg")
fg2 <- (
(f8 %C% g6)
%C%
mirror(
(nose %I% nose_bottom)
%+% (mouse_top %C% mouse_bottom)
%+% in_eye
)
)
draw(fg2, "fg2")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment