Guest User

Untitled

a guest
Feb 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.47 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 18,
  6. "metadata": {
  7. "collapsed": true
  8. },
  9. "outputs": [],
  10. "source": [
  11. "vsh = \"\"\"\n",
  12. "#version 330\n",
  13. "\n",
  14. "uniform vec2 resolution;\n",
  15. "uniform float time;\n",
  16. "\n",
  17. "out float vPartsID;\n",
  18. "out float vGroupID;\n",
  19. "out vec3 vEye;\n",
  20. "out vec3 vPos;\n",
  21. "out mat3 vMat;\n",
  22. "out vec3 vLight;\n",
  23. "out float vLen;\n",
  24. "out vec2 vResolution;\n",
  25. "\n",
  26. "#define SLICE_NUM 30.0\n",
  27. "#define X vec3(1,0,0)\n",
  28. "#define Y vec3(0,1,0)\n",
  29. "#define Z vec3(0,0,1)\n",
  30. "#define PI\t3.1415\n",
  31. "#define PI2 6.2832\n",
  32. "#define PIH 1.5708\n",
  33. "\n",
  34. "float TIME,ID;\n",
  35. "\n",
  36. "mat2 rotate(in float a)\n",
  37. "{\n",
  38. "\treturn mat2(cos(a), sin(a), -sin(a), cos(a));\n",
  39. "}\n",
  40. "\n",
  41. "mat4 moveTo(in vec3 p)\n",
  42. "{\n",
  43. " mat4 m = mat4(1);\n",
  44. " m[3].xyz = p;\n",
  45. " return m;\n",
  46. "}\n",
  47. "\n",
  48. "mat4 moveX(in float x)\n",
  49. "{\n",
  50. " return moveTo(vec3(x,0,0));\n",
  51. "}\n",
  52. "\n",
  53. "mat4 moveY(in float y)\n",
  54. "{\n",
  55. " return moveTo(vec3(0,y,0));\n",
  56. "}\n",
  57. "\n",
  58. "mat4 rotate4(in vec3 axis, in float theta)\n",
  59. "{\n",
  60. " axis = normalize(axis);\n",
  61. " float x = axis.x, y = axis.y, z = axis.z, s = sin(theta), c = cos(theta), o = 1.0-c;\n",
  62. " return mat4(\n",
  63. " o*x*x+c,o*x*y+z*s,o*z*x-y*s,0,\n",
  64. " o*x*y-z*s,o*y*y+c,o*y*z+x*s,0,\n",
  65. " o*z*x+y*s,o*y*z-x*s,o*z*z+c,0,\n",
  66. " 0,0,0,1);\n",
  67. "}\n",
  68. "\n",
  69. "mat4 rotate4X(float a)\n",
  70. "{\n",
  71. " return mat4(1,0,0,0,0,cos(a),sin(a),0,0,-sin(a),cos(a),0,0,0,0,1);\n",
  72. "}\n",
  73. "\n",
  74. "mat4 rotate4Y(float a)\n",
  75. "{\n",
  76. " return mat4(cos(a),0,-sin(a),0,0,1,0,0,sin(a),0,cos(a),0,0,0,0,1);\n",
  77. "}\n",
  78. "\n",
  79. "mat3 rotate3(in vec3 axis, in float theta)\n",
  80. "{\n",
  81. " mat4 m4 = rotate4(axis, theta);\n",
  82. " return mat3(m4[0].xyz,m4[1].xyz,m4[2].xyz);\n",
  83. "}\n",
  84. "\n",
  85. "mat3 rotate3X(in float theta)\n",
  86. "{\n",
  87. " return rotate3(X, theta);\n",
  88. "}\n",
  89. "\n",
  90. "mat3 matchTo(in vec3 a, in vec3 b)\n",
  91. "{\n",
  92. " a = normalize(a);\n",
  93. " b = normalize(b);\n",
  94. " return rotate3(cross(b,a), acos(dot(a,b)));\n",
  95. "}\n",
  96. "\n",
  97. "mat4 matchTo4(in vec3 a, in vec3 b)\n",
  98. "{\n",
  99. " a = normalize(a);\n",
  100. " b = normalize(b);\n",
  101. " return rotate4(cross(b,a), acos(dot(a,b)));\n",
  102. "}\n",
  103. "\n",
  104. "float hash(float n)\n",
  105. "{\n",
  106. " return fract(sin(n) * 43758.5453123);\n",
  107. "}\n",
  108. "\n",
  109. "vec2 hashVector(in float n) \n",
  110. "{\n",
  111. " float a =sin(mod(n,PI2))*PI2;\n",
  112. " return vec2(cos(a),sin(a)); \n",
  113. "} \n",
  114. "\n",
  115. "float scene(in float t1, in float t2)\n",
  116. "{\n",
  117. " return smoothstep(t1,t2,time); \n",
  118. "}\n",
  119. "\n",
  120. "float ezing(in float t)\n",
  121. "{\n",
  122. " return pow(sin(t * PIH), 0.3);\n",
  123. "}\n",
  124. "\n",
  125. "vec2 randomWalk(float t)\n",
  126. "{\n",
  127. " vec2 p = vec2(0);\n",
  128. " float n = 23532.682;\n",
  129. " t *= 0.15;\n",
  130. " for (int i=0; i<6; i++)\n",
  131. " {\n",
  132. " p += hashVector(n) * cos(t)+ hashVector(n*2.356) * sin(t);\n",
  133. " n +=12.78; t *= 1.36456;\n",
  134. " }\n",
  135. " return p;\n",
  136. "}\n",
  137. "\n",
  138. "vec3 sphere(in float n, in float r)\n",
  139. "{\n",
  140. " float id = floor(n/49.0);\n",
  141. " n = mod(n,49.0);\n",
  142. " vec3 p = vec3(floor(n/7.0), mod(n, 7.0), 0)/7.0*2.0-1.0;\n",
  143. " p.z = (mod(id,2.0)<0.5)?1.0:-1.0;\n",
  144. " p = (id>3.5)?p.yzx:(id>1.5)?p.zxy:p;\n",
  145. " return r * normalize(p);\n",
  146. "}\n",
  147. "\n",
  148. "vec3 torusSpin(in float n, in float rH, in float rV, in float spinV, in float spinH)\n",
  149. "{\n",
  150. " float t = PI2 * n / 294.0;\n",
  151. " float vi = floor(spinV);\n",
  152. " vec3 p = rV*mix(\n",
  153. " vec3(rotate(t*vi)* vec2(1,0), 0.0),\n",
  154. " vec3(rotate(t*(vi+1.0))* vec2(1,0), 0.0),\n",
  155. " fract(spinV)\n",
  156. " );\n",
  157. " p.x+= rH;\n",
  158. " float hi = floor(spinH);\n",
  159. " return mix(\n",
  160. " vec3(rotate(t*hi)*p.xz,p.y).xzy,\n",
  161. " vec3(rotate(t*(hi+1.0))*p.xz,p.y).xzy,\n",
  162. " fract(spinH)\n",
  163. " );\n",
  164. "}\n",
  165. "\n",
  166. "vec4 hex_star(in float modelID, in float bbID, in vec3 localPos, in vec3 eye, in vec3 light)\n",
  167. "{\n",
  168. " vec3 worldPos;\n",
  169. " mat3 localMat;\n",
  170. " float sn = (modelID-0.5)*2.0;\n",
  171. " if (time <40.0)\n",
  172. " { \n",
  173. " worldPos = sphere(bbID, 5.0);\n",
  174. " localMat = matchTo(Z, worldPos);\n",
  175. " float n = hash((atan(worldPos.x,worldPos.z)+5.)*(worldPos.y+3.));\n",
  176. " float s0 = scene(43.0,26.0);\n",
  177. " worldPos *= mix(\n",
  178. " vec3(1),\n",
  179. " vec3(\n",
  180. " sin(3.*time+sin(time*2.0)),\n",
  181. " sin(time*3.2),\n",
  182. " cos(3.0*time)\n",
  183. " )*0.3+1.0,\n",
  184. " s0\n",
  185. " );\n",
  186. " worldPos.x += sn * 25.0 * scene(25.0,0.0);\n",
  187. " worldPos *= max(1.0,\n",
  188. " sn * 10.0*n*sin(time + 2.0*n*sin(3.0*n*time)) *\n",
  189. " s0\n",
  190. " );\n",
  191. " worldPos.x +=\n",
  192. " sn*3.0*\n",
  193. " sin(time + 2.0*sin(time*3.0 + 5.0*sin(time*5.0)))*\n",
  194. " pow(sin(time),3.5)*\n",
  195. " s0;\n",
  196. " sn *= 2.0;\n",
  197. " } \n",
  198. " else if (time <55.0)\n",
  199. " {\n",
  200. " vec3 spherePos = sphere(bbID, 5.0);\n",
  201. " vec3 torusPos =\n",
  202. " torusSpin(\n",
  203. " bbID, \n",
  204. " mix(0.0, 6.0 + 2.0*sin(time*3.0),scene(60.0, 65.0)),\n",
  205. " 6.0,\n",
  206. " sin(time*0.2)*8.0,\n",
  207. " 1.0\n",
  208. " );\n",
  209. " float s0 = scene(47.0, 55.0);\n",
  210. " localMat = matchTo(Z, mix(spherePos, torusPos, s0));\n",
  211. " worldPos = mix(\n",
  212. " spherePos +\n",
  213. " sn* vec3(15,0,0) * ezing(scene(40.0, 41.0)) +\n",
  214. " spherePos * 15.0 * ezing(scene(44.0, 50.0)),\n",
  215. " torusPos + sn * vec3(8,0,0),\n",
  216. " s0\n",
  217. " );\n",
  218. " sn *= mix(1.0, 3.0,scene(52.0,55.0));\n",
  219. " }\n",
  220. " else if (time <72.0)\n",
  221. " { \n",
  222. " worldPos = \n",
  223. " torusSpin(\n",
  224. " bbID,\n",
  225. " mix(0.0, 6.0 + 2.0*sin(time*3.0),scene(60.0, 65.0)),\n",
  226. " 6.0,\n",
  227. " sin(time*0.2)*8.0,\n",
  228. " 1.0\n",
  229. " );\n",
  230. " localMat = matchTo(Z, worldPos);\n",
  231. " worldPos.x += sn * mix(8.0,10.0*sin(time),scene(58.0,65.0));\n",
  232. " sn *= 3.0;\n",
  233. " }\n",
  234. " else if (time <100.0)\n",
  235. " { \n",
  236. " worldPos = 12.0 * mix(\n",
  237. " vec3(randomWalk((bbID+time*10.)*0.3),randomWalk(0.2*(bbID+time*10.)+50.).x)*0.5,\n",
  238. " torusSpin(bbID,0.8,0.5,sin(time*0.5)*8.0, 3.),\n",
  239. " sin(time*0.3)*0.5 +0.5\n",
  240. " );\n",
  241. " localMat = matchTo(Z, worldPos);\n",
  242. " worldPos.x += sn * 10.0 * sin(time*0.5 + 3.0 * sin(time * 0.5));\n",
  243. " sn *= 2.0;\n",
  244. " }\n",
  245. " else\n",
  246. " {\n",
  247. " worldPos = 12.0 *\n",
  248. " torusSpin(\n",
  249. " bbID,\n",
  250. " 1.0,\n",
  251. " 0.8,\n",
  252. " sin(time*0.2+2.0*sin(time*0.5))*8.0,\n",
  253. " 3.+1.5*sin(time*0.2+2.0*sin(time*0.5))\n",
  254. " );\n",
  255. " localMat = matchTo(Z, worldPos);\n",
  256. " worldPos.x += sn;\n",
  257. " sn=2.0;\n",
  258. " } \n",
  259. " \n",
  260. " if(time> 120.0)\n",
  261. " {\n",
  262. " worldPos *= \n",
  263. " mix(1.0, 0.3, scene(130.0,139.0)) *\n",
  264. " mix(1.0, 0.1, ezing(scene(140.0,141.0))) *\n",
  265. " mix(1.0, 500.0, ezing(scene(141.2,143.0)));\n",
  266. " }\n",
  267. " worldPos *= rotate3X(sn * sin(time*0.2+2.0*sin(time*0.5)));\n",
  268. " mat3 worldMat = rotate3(Y, 5.0*sin(time*0.02 + 3.5* sin(time*0.06)));\n",
  269. " worldPos = worldMat*worldPos;\n",
  270. " vPos = localMat*(localPos*worldMat);\n",
  271. " vLight = localMat*(light*worldMat);\n",
  272. " return vec4(matchTo(eye-worldPos, Z)*localPos + worldPos, 1.0); \n",
  273. "}\n",
  274. "\n",
  275. "mat4 rootMat()\n",
  276. "{\n",
  277. " return moveTo(vec3(0));\n",
  278. "}\n",
  279. "\n",
  280. "mat4 waistMat(in mat4 m)\n",
  281. "{\n",
  282. " return m *rotate4Y(0.3*sin(TIME))* moveTo(vec3(0,0.8,0.2));\n",
  283. "}\n",
  284. "\n",
  285. "mat4 breastMat(in mat4 m)\n",
  286. "{\n",
  287. " return m * moveTo(vec3(0,0.8,0.2));\n",
  288. "}\n",
  289. "\n",
  290. "mat4 neckMat(in mat4 m)\n",
  291. "{\n",
  292. " return m * rotate4Y(-0.3*sin(TIME)) * moveY(0.7);\n",
  293. "}\n",
  294. "\n",
  295. "mat4 headMat(in mat4 m)\n",
  296. "{\n",
  297. " return m * moveTo(vec3(0,0.25,0.05));\n",
  298. "}\n",
  299. "\n",
  300. "mat4 hipMat(in mat4 m)\n",
  301. "{\n",
  302. " return m * rotate4Y(-0.1*sin(TIME))*moveY(-0.4);\n",
  303. "}\n",
  304. "\n",
  305. "mat4 leftShoulderMat(in mat4 m)\n",
  306. "{\n",
  307. " return m * moveTo(vec3(-0.6,-0.1,0));\n",
  308. "}\n",
  309. "\n",
  310. "mat4 rightShoulderMat(in mat4 m)\n",
  311. "{\n",
  312. " return m * moveTo(vec3(0.6,-0.1,0));\n",
  313. "}\n",
  314. "\n",
  315. "mat4 leftUpperArmMat(in mat4 m)\n",
  316. "{\n",
  317. " vec3 p = normalize(vec3(1,-1,0));\n",
  318. " p *= (hash(ID)<0.2)?rotate3X(TIME):rotate3X(sin(TIME));\n",
  319. " return m * matchTo4(X,p) * moveX(-1.2);\n",
  320. "}\n",
  321. "\n",
  322. "mat4 rightUpperArmMat(in mat4 m)\n",
  323. "{\n",
  324. " vec3 p = normalize(vec3(1,0.2,0));\n",
  325. " p *= (hash(ID)>0.8)?rotate3X(-TIME):rotate3X(sin(-TIME));\n",
  326. " return m * rotate4(cross(p,X),dot(X,p)) * moveX(1.2);\n",
  327. "}\n",
  328. "\n",
  329. "mat4 leftLowerArmMat(in mat4 m)\n",
  330. "{\n",
  331. " return m * rotate4Y(1.0) * moveX(-1.0);\n",
  332. "}\n",
  333. "\n",
  334. "mat4 rightLowerArmMat(in mat4 m)\n",
  335. "{\n",
  336. " return m * rotate4Y(-1.0) * moveX(1.0);\n",
  337. "}\n",
  338. "\n",
  339. "mat4 leftCrotchMat(in mat4 m)\n",
  340. "{\n",
  341. " return m * moveX(-0.5);\n",
  342. "}\n",
  343. "\n",
  344. "mat4 rightCrotchMat(in mat4 m)\n",
  345. "{\n",
  346. " return m * moveX(0.5);\n",
  347. "}\n",
  348. "\n",
  349. "mat4 leftUpperLegMat(in mat4 m)\n",
  350. "{\n",
  351. " return m * rotate4X(sin(TIME)) * moveY(-1.5);\n",
  352. "}\n",
  353. "\n",
  354. "mat4 rightUpperLegMat(in mat4 m)\n",
  355. "{\n",
  356. " return m * rotate4X(-sin(TIME)) * moveY(-1.5);\n",
  357. "}\n",
  358. "\n",
  359. "mat4 leftLowerLegMat(in mat4 m)\n",
  360. "{\n",
  361. " return m * rotate4X(0.3*sin(TIME*2.0)+0.8) * moveY(-1.6);\n",
  362. "}\n",
  363. "\n",
  364. "mat4 rightLowerLegMat(in mat4 m)\n",
  365. "{\n",
  366. " return m * rotate4X(0.3*sin(TIME*2.0)+0.8) * moveY(-1.6);\n",
  367. "}\n",
  368. "\n",
  369. "mat4 waistMat(){return waistMat(rootMat());}\n",
  370. "mat4 breastMat(){return breastMat(waistMat());}\n",
  371. "mat4 neckMat(){return neckMat(breastMat());}\n",
  372. "mat4 headMat(){return headMat(neckMat());}\n",
  373. "mat4 hipMat(){return hipMat(rootMat());}\n",
  374. "mat4 leftShoulderMat(){return leftShoulderMat(breastMat());}\n",
  375. "mat4 rightShoulderMat(){return rightShoulderMat(breastMat());}\n",
  376. "mat4 leftUpperArmMat(){return leftUpperArmMat(leftShoulderMat());}\n",
  377. "mat4 rightUpperArmMat(){return rightUpperArmMat(rightShoulderMat());}\n",
  378. "mat4 leftLowerArmMat(){return leftLowerArmMat(leftUpperArmMat());}\n",
  379. "mat4 rightLowerArmMat(){return rightLowerArmMat(rightUpperArmMat());}\n",
  380. "mat4 leftCrotchMat(){return leftCrotchMat(hipMat());}\n",
  381. "mat4 rightCrotchMat(){return rightCrotchMat(hipMat());}\n",
  382. "mat4 leftUpperLegMat(){return leftUpperLegMat(leftCrotchMat());}\n",
  383. "mat4 rightUpperLegMat(){return rightUpperLegMat(rightCrotchMat());}\n",
  384. "mat4 leftLowerLegMat(){return leftLowerLegMat(leftUpperLegMat());}\n",
  385. "mat4 rightLowerLegMat(){return rightLowerLegMat(rightUpperLegMat());}\n",
  386. "\n",
  387. "vec4 ragdoll(in float modelID, in float bbID, in vec3 localPos, in vec3 eye, in vec3 light)\n",
  388. "{\n",
  389. " ID = modelID + 123.456;\n",
  390. " TIME = time*4.0+hash(ID*12.34)*3.0;\n",
  391. " \n",
  392. " int partsID = 0;\n",
  393. " for (int i = 0; i < 13; i++) \n",
  394. " {\n",
  395. " float num = step(5.0, float(i))+1.0;\n",
  396. " if (num > bbID) break;\n",
  397. " bbID -= num ;\n",
  398. " partsID++;\n",
  399. " }\n",
  400. " mat4 a,b;\n",
  401. " if (partsID == 0) {a = rootMat(); b = waistMat(a);}\n",
  402. " else if (partsID == 1) {a = waistMat(); b = breastMat(a);}\n",
  403. " else if (partsID == 2) {a = breastMat(); b = neckMat(a);}\n",
  404. " else if (partsID == 3) {a = neckMat(); b = headMat(a);}\n",
  405. " else if (partsID == 4) {a = rootMat(); b = hipMat(a);}\n",
  406. " else if (partsID == 5) {a = leftShoulderMat(); b = leftUpperArmMat(a);}\n",
  407. " else if (partsID == 6) {a = rightShoulderMat(); b = rightUpperArmMat(a);}\n",
  408. " else if (partsID == 7) {a = leftUpperArmMat(); b = leftLowerArmMat(a);}\n",
  409. " else if (partsID == 8) {a = rightUpperArmMat(); b = rightLowerArmMat(a);}\n",
  410. " else if (partsID == 9) {a = leftCrotchMat(); b = leftUpperLegMat(a);}\n",
  411. " else if (partsID == 10) {a = rightCrotchMat(); b = rightUpperLegMat(a);}\n",
  412. " else if (partsID == 11) {a = leftUpperLegMat(); b = leftLowerLegMat(a);}\n",
  413. " else if (partsID == 12) {a = rightUpperLegMat(); b = rightLowerLegMat(a);}\n",
  414. " float t = time + float(modelID)*0.4;\n",
  415. " vec3 worldPos = vec3(randomWalk(t)*10.0,0).xzy;\n",
  416. " worldPos.z += (scene(15.0,0.0)+scene(135.0,155.0))*100.0;\n",
  417. " worldPos.y = max(5.0-pow(length(worldPos.xz)*0.3,2.0),0.0);\n",
  418. " vec2 delta = normalize(randomWalk(t+0.001) - randomWalk(t-0.001));\n",
  419. " mat4 worldMat = moveTo(worldPos) * rotate4Y(acos(dot(vec2(0,1),delta)) * sign(cross(vec3(delta,0),Y).z));\n",
  420. " a = worldMat *a;\n",
  421. " b = worldMat *b;\n",
  422. " vec3 p1 = (a*vec4(0,0,0,1)).xyz;\n",
  423. " vec3 p2 = (b*vec4(0,0,0,1)).xyz;\n",
  424. " vec3 p12 = (p2-p1);\n",
  425. " worldPos = mix(p1, p2, (bbID+0.5)/ (step(9., float(partsID))+1.));\n",
  426. " localPos = matchTo(eye-worldPos, Z) * localPos + worldPos;\n",
  427. " vLight = (vec4(light,1)*a).xyz;\n",
  428. " vLen = length(p12)/2.0;\n",
  429. " vMat = matchTo(Z,(vec4(p12,1)*a).xyz);\n",
  430. " vPos = (vec4(localPos-mix(p1, p2, 0.5),1)*a).xyz;\n",
  431. " vPartsID =float(partsID);\n",
  432. " return vec4(localPos, 1.0); \n",
  433. "}\n",
  434. "\n",
  435. "void main()\n",
  436. "{\n",
  437. " float vertexID=abs(3.0-mod(float(gl_VertexID),6.0)),polyID=floor(float(gl_VertexID)/6.0);\n",
  438. " vec2 coord = vec2(mod(vertexID,2.0), floor(vertexID/2.0))*2.0-1.0;\n",
  439. " vec3 eye = vec3(0,10,35),light = normalize(vec3(1)),w = normalize(eye),u=normalize(cross(Y,w)),v=normalize(cross(w,u));\n",
  440. " mat4 pvMat = \n",
  441. " mat4(2.5/(resolution.x/resolution.y),0,0,0,0,2.5,0,0,0,0,-99.1/98.9,-1,0,0,-19.8/98.9,1)*\n",
  442. " transpose(mat4(u,-dot(u,eye),v,-dot(v,eye),w,-dot(w,eye),0,0,0,1));\n",
  443. "\n",
  444. " int groupFaceNum[4] = int[](1,8820,8820,9450);\n",
  445. " float groupID = 0.0;\n",
  446. " for (int i = 0; i < 4; i++) \n",
  447. " {\n",
  448. " if (groupFaceNum[i] > int(polyID)) break;\n",
  449. " polyID -= float(groupFaceNum[i]);\n",
  450. " groupID++;\n",
  451. " }\n",
  452. " vGroupID = groupID; \n",
  453. "\n",
  454. " if (groupID<0.5) \n",
  455. " { \n",
  456. " gl_Position = vec4(coord, 0.999, 1);\n",
  457. " } \n",
  458. " else if (groupID<2.5) \n",
  459. " {\n",
  460. " gl_Position = pvMat * \n",
  461. " hex_star(\n",
  462. " groupID-1.0, \n",
  463. " floor(polyID/SLICE_NUM), \n",
  464. " vec3(coord, 1.0 - 2.0 * fract(polyID/SLICE_NUM)),\n",
  465. " eye, light\n",
  466. " );\n",
  467. " }\n",
  468. " else \n",
  469. " {\n",
  470. " gl_Position = pvMat * \n",
  471. " ragdoll(\n",
  472. " floor(polyID/(SLICE_NUM*21.)), \n",
  473. " mod(floor(polyID/SLICE_NUM), 21.),\n",
  474. " vec3(coord, 1.0 - 2.0 * fract(polyID/SLICE_NUM)) * 0.8, \n",
  475. " eye, light\n",
  476. " );\n",
  477. " } \n",
  478. " vEye = eye;\n",
  479. " vResolution = resolution;\n",
  480. "}\n",
  481. "\n",
  482. "\"\"\""
  483. ]
  484. },
  485. {
  486. "cell_type": "code",
  487. "execution_count": 19,
  488. "metadata": {
  489. "collapsed": true
  490. },
  491. "outputs": [],
  492. "source": [
  493. "fsh = \"\"\"\n",
  494. "#version 330\n",
  495. "\n",
  496. "in vec2 vResolution;\n",
  497. "in float vPartsID;\n",
  498. "in float vGroupID;\n",
  499. "in vec3 vPos;\n",
  500. "in vec3 vEye;\n",
  501. "in mat3 vMat;\n",
  502. "in vec3 vLight;\n",
  503. "in float vLen;\n",
  504. "out vec4 fragColor;\n",
  505. "\n",
  506. "#define rad37 0.64577\n",
  507. "#define rad60 1.0472\n",
  508. "\n",
  509. "float smin(float a, float b, float k)\n",
  510. "{\n",
  511. " return -log(exp(-k*a )+exp(-k*b))/k;\n",
  512. "}\n",
  513. "\n",
  514. "float smax(in float a, in float b, in float k)\n",
  515. "{\n",
  516. " return log(exp(a/k)+exp(b/k))*k;\n",
  517. "}\n",
  518. "\n",
  519. "float sabs(in float n, in float k)\n",
  520. "{\n",
  521. " return n-2.0*smin(0.0,n,k); \n",
  522. "}\n",
  523. "\n",
  524. "vec2 sfold(in vec2 p, in float a)\n",
  525. "{\n",
  526. " p.x = abs(p.x);\n",
  527. " vec2 v = vec2(cos(a), sin(a));\n",
  528. " for(int i = 0; i < 3; i++) \n",
  529. " {\t\n",
  530. " \tp -= 2.0 * smin(0.0, dot(p, v),45.) * v;\n",
  531. " \tv = normalize(vec2(v.x - 1.0, v.y));\n",
  532. " }\n",
  533. " \treturn p; \n",
  534. "}\n",
  535. "\n",
  536. "float deStar(in vec3 p)\n",
  537. "{\n",
  538. " p.xy =sfold(p.xy, rad37);\n",
  539. " return smax(dot(vec2(sabs(p.x,25.),p.y), \n",
  540. " normalize(vec2(1.8, 1)))-0.5,abs(p.z)-0.3,0.05)\n",
  541. " +0.05 * smoothstep(0.45, 0.25, length(p));\n",
  542. "}\n",
  543. "\n",
  544. "float deHex(in vec3 p)\n",
  545. "{\n",
  546. " p.xy =sfold(p.xy, rad60);\n",
  547. " return smax(p.y-0.7,abs(p.z)-0.3,0.05)\n",
  548. " +0.05 * smoothstep(0.35, 0.15, p.y);\n",
  549. "}\n",
  550. "\n",
  551. "float deRagdoll(in vec3 p)\n",
  552. "{\n",
  553. " p = vMat*p;\n",
  554. " float x=clamp(p.z,-vLen,vLen);\n",
  555. " float t = x/vLen;\n",
  556. " vec2 sec =\n",
  557. " (vPartsID < 0.5)? vec2(0.02):\n",
  558. " (vPartsID < 1.5)? vec2(0.15,0.35+0.1*t):\n",
  559. " (vPartsID < 2.5)? vec2(0):\n",
  560. " (vPartsID < 3.5)? vec2(0.15):\n",
  561. " (vPartsID < 4.5)? vec2(0.15,0.2):\n",
  562. " (vPartsID < 6.5)? vec2(0.12-t*0.02):\n",
  563. " (vPartsID < 8.5)? vec2(0.1):\n",
  564. " (vPartsID < 10.5)? vec2(0.12-t*0.05):\n",
  565. " vec2(0.1);\n",
  566. " return length(max(abs(vec2(length(p.zy-vec2(x,0)),p.x))-sec,0.0))-0.2;\n",
  567. "}\n",
  568. "\n",
  569. "float map(in vec3 p)\n",
  570. "{\n",
  571. " return (vGroupID<1.5)? deHex(p):\n",
  572. " (vGroupID<2.5)? deStar(p):\n",
  573. " deRagdoll(p);\n",
  574. "}\n",
  575. "\n",
  576. "vec3 calcNormal(in vec3 pos)\n",
  577. "{\n",
  578. " vec2 e = vec2(1.0,-1.0)*0.002;\n",
  579. " return normalize(\n",
  580. " e.xyy*map(pos+e.xyy)+e.yyx*map(pos+e.yyx)+ \n",
  581. " e.yxy*map(pos+e.yxy)+e.xxx*map(pos+e.xxx)\n",
  582. " );\n",
  583. "}\n",
  584. "\n",
  585. "void main() \n",
  586. "{\n",
  587. " vec2 uv = gl_FragCoord.xy / vResolution;\n",
  588. " vec3 col = \n",
  589. " clamp(\n",
  590. " mix(\n",
  591. " mix(\n",
  592. " vec3(0.5, 1, 0.5),\n",
  593. " vec3(1,0,0),\n",
  594. " 0.8-uv.y\n",
  595. " ),\n",
  596. " vec3(0.9-length(uv-0.4)),\n",
  597. " length(uv-0.9)\n",
  598. " )*1.3,\n",
  599. " 0.0,1.0\n",
  600. " );\n",
  601. " \n",
  602. "\tif (vGroupID>0.5) \n",
  603. "\t{\n",
  604. " if( map(vPos)< 0.001) \n",
  605. " {\n",
  606. " vec3 normal = calcNormal(vPos);\n",
  607. " col = \n",
  608. " mix(\n",
  609. " col,\n",
  610. " clamp(\n",
  611. " ((vGroupID<1.5)?vec3(0.1,0.5,0.9):\n",
  612. " (vGroupID<2.5)?vec3(0.1,0.9,0.5):\n",
  613. " vec3(1,0.3,0.3)) *\n",
  614. " clamp((dot(normal, vLight)+0.5)*0.7, 0.3, 1.0) *\n",
  615. " max(0.0, 0.7+0.3*normal.y) +\n",
  616. " pow(\n",
  617. " clamp(\n",
  618. " dot(reflect(normalize(vPos - vEye), normal), vLight),\n",
  619. " 0.0, 1.0\n",
  620. " ),\n",
  621. " 50.0\n",
  622. " ) * step(0.5,dot(normal, vLight)),\n",
  623. " 0.0,1.0\n",
  624. " ),\n",
  625. " exp(-pow(length(vPos - vEye),2.0)*0.0002)\n",
  626. " );\n",
  627. " } \n",
  628. " else \n",
  629. " {\n",
  630. " discard;\n",
  631. " }\n",
  632. " }\n",
  633. " fragColor = vec4(col, 1); \n",
  634. "}\n",
  635. "\n",
  636. "\"\"\""
  637. ]
  638. },
  639. {
  640. "cell_type": "code",
  641. "execution_count": 20,
  642. "metadata": {
  643. "collapsed": true
  644. },
  645. "outputs": [],
  646. "source": [
  647. "msh = \"\"\"\n",
  648. "#version 330\n",
  649. "\n",
  650. "out vec2 gain; \n",
  651. "uniform float sampleRate; \n",
  652. "\n",
  653. "float TIME;\n",
  654. "\n",
  655. "float hash(float n){return fract(sin(n) * 4379.5453);}\n",
  656. "\n",
  657. "float tone(float t)\n",
  658. "{\n",
  659. " t *= 3.;\n",
  660. " float ti = floor(t);\n",
  661. " float scale[7] = float[](0.0, 3.0, 5.0, 7.0, 10.0, 12.0, -10000.0);\n",
  662. " int id = int(7.*(hash(ti*126.89 + fract(ti*0.964) + floor(ti*1723.23))));\n",
  663. " float f = 6.2831 * fract(440.0*pow(2.0,(scale[id]-10.0)/12.0)*TIME);\n",
  664. " return sin(f+ 2.0*sin(2.0*f + sin(2.0*f))) * exp(-3.0*fract(t));\n",
  665. "}\n",
  666. "\n",
  667. "float sound(float time)\n",
  668. "{\n",
  669. " TIME = time;\n",
  670. " time *= 1.5;\n",
  671. " float a = \n",
  672. " tone(time)+ \n",
  673. " tone(time*0.5)+\n",
  674. " tone(time*0.25);\n",
  675. " return clamp(a*0.3,-1.0,1.0);\n",
  676. "}\n",
  677. "\n",
  678. "void main() {\n",
  679. " float time = float(gl_VertexID) / sampleRate;\n",
  680. " gain = vec2(sound(time+0.01*cos(time*0.05)),sound(time+0.01*sin(time*0.05))) * \n",
  681. " smoothstep(147.0,140.0,time); \n",
  682. "}\n",
  683. "\n",
  684. "\"\"\""
  685. ]
  686. },
  687. {
  688. "cell_type": "code",
  689. "execution_count": 21,
  690. "metadata": {
  691. "collapsed": true
  692. },
  693. "outputs": [],
  694. "source": [
  695. "gccPath = r\"C:\\mingw-w64\\x86_64-6.1.0-posix-seh-rt_v5-rev0\\mingw64\\bin\"\n",
  696. "crinklerPath = r\"C:\\Users\\haru\\Dropbox\\demoscene\\tools\"\n",
  697. "libPath = r\"C:\\Users\\haru\\Dropbox\\demoscene\\lib\""
  698. ]
  699. },
  700. {
  701. "cell_type": "code",
  702. "execution_count": 22,
  703. "metadata": {
  704. "collapsed": true
  705. },
  706. "outputs": [],
  707. "source": [
  708. "playTime =148\n",
  709. "polySize = 1 + 30*6*7*7*2 + 30*21*15"
  710. ]
  711. },
  712. {
  713. "cell_type": "code",
  714. "execution_count": 23,
  715. "metadata": {
  716. "collapsed": true
  717. },
  718. "outputs": [],
  719. "source": [
  720. "var = {\n",
  721. " \"U_RESOLUTION\" : \"resolution\",\n",
  722. " \"U_TIME\" : \"time\",\n",
  723. " \"U_SAMPLERATE\" : \"sampleRate\",\n",
  724. " \"O_GAIN\" : \"gain\"\n",
  725. "}\n",
  726. "\n",
  727. "gfx_init = \"\"\"\n",
  728. " glEnable(GL_DEPTH_TEST);\n",
  729. " \n",
  730. " GLint program = glCreateProgram();\n",
  731. " compile(program, vsh, GL_VERTEX_SHADER);\n",
  732. " compile(program, fsh, GL_FRAGMENT_SHADER);\n",
  733. " glLinkProgram(program);\n",
  734. " glUseProgram(program);\n",
  735. " //glUniform1f(glGetUniformLocation(program, U_ASPECT), (float)XRES/(float)YRES);\n",
  736. " glUniform2f(glGetUniformLocation(program, U_RESOLUTION), (float)XRES, (float)YRES);\n",
  737. "\"\"\"\n",
  738. "\n",
  739. "gfx_do = \"\"\"\n",
  740. " glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);\n",
  741. " glUniform1f(glGetUniformLocation(program, U_TIME), time);\n",
  742. " glDrawArrays(GL_TRIANGLES, 0, 6*{0});\n",
  743. "\"\"\".format(polySize)"
  744. ]
  745. },
  746. {
  747. "cell_type": "code",
  748. "execution_count": 24,
  749. "metadata": {
  750. "collapsed": true
  751. },
  752. "outputs": [],
  753. "source": [
  754. "import re\n",
  755. "import string\n",
  756. "import subprocess\n",
  757. "import os\n",
  758. "\n",
  759. "def fRead(fn):\n",
  760. " f = open(fn, 'r')\n",
  761. " str = f.read()\n",
  762. " f.close()\n",
  763. " return str\n",
  764. " \n",
  765. "def fWrite(fn, src):\n",
  766. " f = open(fn, 'w')\n",
  767. " f.write(src)\n",
  768. " f.close()\n",
  769. " \n",
  770. "def batch(cmd):\n",
  771. " fn = \"command.bat\"\n",
  772. " fWrite(fn, cmd)\n",
  773. " subprocess.call(\"start \" + fn, shell=True) \n",
  774. "\n",
  775. "def dic2code(d):\n",
  776. " s = \"\"\n",
  777. " for k, v in d.items():\n",
  778. " if isinstance(v, str):\n",
  779. " s = s + '#define {0} \"{1}\" \\n'.format(k, v)\n",
  780. " else: # int, float\n",
  781. " s = s + '#define {0} {1} \\n'.format(k, v)\n",
  782. " return s\n",
  783. " \n",
  784. "def glRename(src):\n",
  785. " for m in re.finditer(\"(gl\\w+)\\(\" , src):\n",
  786. " s = m.group(1)\n",
  787. " f = False\n",
  788. " if re.search(\"Program\", s) != None: f = True\n",
  789. " if re.search(\"Shader\", s) != None: f = True\n",
  790. " if re.search(\"TransformFeedback\", s) != None: f = True\n",
  791. " if re.search(\"Buffer\", s) != None: f = True\n",
  792. " if re.search(\"Uniform\", s) != None: f = True\n",
  793. " if s == \"glReadBuffer\": f = False\n",
  794. " if f: \n",
  795. " src = src.replace(s + \"(\", '((PFN' + s.upper() + 'PROC)wglGetProcAddress(\"' + s + '\"))(')\n",
  796. " return src"
  797. ]
  798. },
  799. {
  800. "cell_type": "code",
  801. "execution_count": 25,
  802. "metadata": {
  803. "collapsed": false
  804. },
  805. "outputs": [],
  806. "source": [
  807. "def makeCSrc4debug(gfx_init, gfx_do, vsh, fsh, msh, var):\n",
  808. " conf = {\n",
  809. " \"SND_DURATION\" : playTime,\n",
  810. " \"SAMPLE_RATE\" : 48000,\n",
  811. " \"SND_NUMCHANNELS\" : 2,\n",
  812. " \"XPOS\" : 500,\n",
  813. " \"YPOS\" : 200,\n",
  814. " \"XRES\" : 640,\n",
  815. " \"YRES\" : 480,\n",
  816. " }\n",
  817. " src = \"\"\"\n",
  818. "#include <windows.h>\n",
  819. "#include <GL/gl.h>\n",
  820. "#include <GL/glext.h>\n",
  821. "#include <mmreg.h>\n",
  822. "#include <stdio.h> \n",
  823. "\n",
  824. "\"\"\" + \"\"\"\n",
  825. "static const char *vsh = \"{0}\";\n",
  826. "static const char *fsh = \"{1}\";\n",
  827. "static const char *msh = \"{2}\";\n",
  828. "\n",
  829. "\"\"\".format(\n",
  830. " vsh.replace(\"\\n\",r\"\\n\"),\n",
  831. " fsh.replace(\"\\n\",r\"\\n\"),\n",
  832. " msh.replace(\"\\n\",r\"\\n\")\n",
  833. " ) + \"\"\"\n",
  834. " \n",
  835. "\"\"\" + dic2code(var) + dic2code(conf) + \"\"\"\n",
  836. "\n",
  837. "#define SND_NUMSAMPLES (SND_DURATION*SAMPLE_RATE)\n",
  838. "#define SND_NUMSAMPLESC (SND_NUMSAMPLES*SND_NUMCHANNELS)\n",
  839. "\n",
  840. "void checkShader(GLuint shader){\n",
  841. " GLint compile_status = 0;\n",
  842. " glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_status);\n",
  843. " if(compile_status != GL_TRUE){\n",
  844. " GLint info_length;\n",
  845. " GLsizei buffer_size;\n",
  846. " glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_length);\n",
  847. " GLchar message[info_length];\n",
  848. " glGetShaderInfoLog(shader, info_length, &buffer_size, message);\n",
  849. " printf( message);\n",
  850. " }\n",
  851. "}\n",
  852. "\n",
  853. "void compile(GLuint program, const char *source, GLenum type){\n",
  854. " GLuint shader = glCreateShader(type);\n",
  855. " glShaderSource(shader, 1, &source, 0);\n",
  856. " glCompileShader(shader);\n",
  857. " checkShader(shader);\n",
  858. " glAttachShader(program, shader);\n",
  859. "}\n",
  860. "\n",
  861. "float samples[SND_NUMSAMPLESC];\n",
  862. "\n",
  863. "int main(){\n",
  864. " HWND hWnd = CreateWindow((LPCSTR)0xC018,\"demoscene\",WS_OVERLAPPEDWINDOW|WS_VISIBLE,XPOS,YPOS,XRES,YRES,0,0,0,0);\n",
  865. " HDC hDC = GetDC(hWnd);\n",
  866. " PIXELFORMATDESCRIPTOR pfd={0,1,PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER,32,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0};\n",
  867. " SetPixelFormat(hDC, ChoosePixelFormat(hDC, &pfd) , &pfd);\n",
  868. " HGLRC hGLrc = wglCreateContext(hDC);\n",
  869. " wglMakeCurrent(hDC, hGLrc);\n",
  870. " \n",
  871. " GLuint programMzk = glCreateProgram();\n",
  872. " compile(programMzk, msh, GL_VERTEX_SHADER);\n",
  873. " const GLchar* outs[] = {O_GAIN};\n",
  874. " glTransformFeedbackVaryings(programMzk, 1, outs, GL_INTERLEAVED_ATTRIBS);\n",
  875. " glLinkProgram(programMzk);\n",
  876. " glUseProgram(programMzk);\n",
  877. " GLuint tmp;\n",
  878. " glGenBuffers(1, &tmp);\n",
  879. " glBindBuffer(GL_ARRAY_BUFFER, tmp);\n",
  880. " glBufferData(GL_ARRAY_BUFFER, SND_NUMSAMPLESC*sizeof(float), 0, GL_STATIC_READ);\n",
  881. " glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tmp);\n",
  882. " tmp = glGetUniformLocation(programMzk, U_SAMPLERATE);\n",
  883. " glUniform1f(tmp, (float)SAMPLE_RATE);\n",
  884. " glEnable(GL_RASTERIZER_DISCARD);\n",
  885. " glBeginTransformFeedback(GL_POINTS);\n",
  886. " glDrawArrays(GL_POINTS, 0, SND_NUMSAMPLES);\n",
  887. " glEndTransformFeedback();\n",
  888. " glDisable(GL_RASTERIZER_DISCARD);\n",
  889. " glGetBufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, sizeof(samples), samples);\n",
  890. "\n",
  891. "\"\"\" + gfx_init + \"\"\"\n",
  892. "\n",
  893. " WAVEFORMATEX wave_format = {\n",
  894. " WAVE_FORMAT_IEEE_FLOAT,\n",
  895. " SND_NUMCHANNELS,\n",
  896. " SAMPLE_RATE,\n",
  897. " SAMPLE_RATE*sizeof(float)*SND_NUMCHANNELS,\n",
  898. " sizeof(float)*SND_NUMCHANNELS,\n",
  899. " sizeof(float)*8,\n",
  900. " 0\n",
  901. " };\n",
  902. " WAVEHDR wave_hdr = {(LPSTR)samples, sizeof(samples)};\n",
  903. " HWAVEOUT hWaveOut;\n",
  904. " waveOutOpen(&hWaveOut, WAVE_MAPPER, &wave_format, (DWORD_PTR)hWnd, 0, CALLBACK_WINDOW);\n",
  905. " waveOutPrepareHeader(hWaveOut, &wave_hdr, sizeof(wave_hdr));\n",
  906. " waveOutWrite(hWaveOut, &wave_hdr, sizeof(wave_hdr));\n",
  907. " static MMTIME mmt = { TIME_SAMPLES }; \n",
  908. " MSG msg;\n",
  909. " int done=0;\n",
  910. " int fps = 0;\n",
  911. " int cnt = 0;\n",
  912. " float t0 = 0.0;\n",
  913. " while (!done) {\n",
  914. " while (PeekMessage(&msg, 0, 0, 0, TRUE)) {\n",
  915. " if (msg.message == WM_NCLBUTTONDOWN && msg.wParam == HTCLOSE) done=1;\n",
  916. " DispatchMessage(&msg);\n",
  917. " }\n",
  918. " if (GetAsyncKeyState(VK_ESCAPE)) done = 1;\n",
  919. " if (mmt.u.sample == SND_NUMSAMPLES) done = 1;\n",
  920. " waveOutGetPosition(hWaveOut, &mmt, sizeof(mmt));\n",
  921. " float time = (float)mmt.u.sample / (float)SAMPLE_RATE;\n",
  922. " \n",
  923. "\"\"\" + gfx_do + \"\"\"\n",
  924. "\n",
  925. " SwapBuffers(hDC);\n",
  926. " if (time - t0 > 1.0) {\n",
  927. " fps = cnt;\n",
  928. " cnt = -1;\n",
  929. " t0 = time;\n",
  930. " }\n",
  931. " cnt++;\n",
  932. " printf(\"\\\\r FPS : %d Time : %5.1f\", fps, time);\n",
  933. " }\n",
  934. " \n",
  935. " waveOutReset(hWaveOut);\n",
  936. " waveOutUnprepareHeader(hWaveOut,&wave_hdr,sizeof(WAVEHDR));\n",
  937. " waveOutClose(hWaveOut);\n",
  938. "\n",
  939. " wglMakeCurrent(NULL, NULL);\n",
  940. " wglDeleteContext(hGLrc);\n",
  941. " ReleaseDC(hWnd, hDC);\n",
  942. " PostQuitMessage(0);\n",
  943. " ExitProcess(0);\n",
  944. " return 0;\n",
  945. "}\n",
  946. "\"\"\"\n",
  947. " return glRename(src)"
  948. ]
  949. },
  950. {
  951. "cell_type": "code",
  952. "execution_count": 26,
  953. "metadata": {
  954. "collapsed": false
  955. },
  956. "outputs": [],
  957. "source": [
  958. "# Debug and Compile and Run\n",
  959. "\n",
  960. "src = makeCSrc4debug(gfx_init, gfx_do, vsh, fsh, msh, var)\n",
  961. "fWrite(\"demo.c\", src)\n",
  962. "batch(r\"\"\"\n",
  963. " echo off\n",
  964. " set PATH={0};%PATH%\n",
  965. " gcc demo.c -O3 -Wall -lopengl32 -lgdi32 -lwinmm -o demo.exe\n",
  966. " demo.exe\n",
  967. "\"\"\".format(gccPath))"
  968. ]
  969. },
  970. {
  971. "cell_type": "markdown",
  972. "metadata": {},
  973. "source": [
  974. "## --------------------------------------------------------------------------------"
  975. ]
  976. },
  977. {
  978. "cell_type": "code",
  979. "execution_count": 27,
  980. "metadata": {
  981. "collapsed": false
  982. },
  983. "outputs": [],
  984. "source": [
  985. "import re\n",
  986. "import string\n",
  987. "\n",
  988. "def glslTrim(src):\n",
  989. " src = re.compile(r'/\\*.*?\\*/', re.DOTALL).sub(\"\", src)\n",
  990. " src = re.sub(r\"//.*\", \"\", src)\n",
  991. " src = re.sub(r\"\\t\", \" \", src)\n",
  992. " src = re.sub(r\" +\", \" \", src)\n",
  993. " src = re.sub(r\" *\\n *\", \"\\n\", src)\n",
  994. " src = re.sub(r\"\\n+\", \"\\n\", src) \n",
  995. " src = re.sub(r\"^\\n\", \"\", src)\n",
  996. " L = src.split(\"\\n\")\n",
  997. " for i in range(len(L)):\n",
  998. " s = L[i]\n",
  999. " if re.search(\"#\", s) != None:\n",
  1000. " L[i] = \"\\n\" + L[i] + \"\\n\"\n",
  1001. " else:\n",
  1002. " s = re.sub(r\" *\\+ *\" ,\"+\", s)\n",
  1003. " s = re.sub(r\" *\\- *\" ,\"-\", s)\n",
  1004. " s = re.sub(r\" *\\* *\" ,\"*\", s)\n",
  1005. " s = re.sub(r\" */ *\" ,\"/\", s)\n",
  1006. " s = re.sub(r\" *= *\" ,\"=\", s)\n",
  1007. " s = re.sub(r\" *< *\" ,\"<\", s)\n",
  1008. " s = re.sub(r\" *> *\" ,\">\", s)\n",
  1009. " s = re.sub(r\" *& *\" ,\"&\", s)\n",
  1010. " s = re.sub(r\" *\\| *\" ,\"|\", s)\n",
  1011. " s = re.sub(r\" *\\( *\" ,\"(\", s)\n",
  1012. " s = re.sub(r\" *\\) *\" ,\")\", s)\n",
  1013. " s = re.sub(r\" *\\[ *\" ,\"[\", s)\n",
  1014. " s = re.sub(r\" *\\] *\" ,\"]\", s)\n",
  1015. " s = re.sub(r\" *{ *\" ,\"{\", s)\n",
  1016. " s = re.sub(r\" *} *\" ,\"}\", s)\n",
  1017. " s = re.sub(r\" *; *\" ,\";\", s)\n",
  1018. " s = re.sub(r\" *, *\" ,\",\", s)\n",
  1019. " L[i] = s\n",
  1020. " src = \"\".join(L)\n",
  1021. " for i in range(2):\n",
  1022. " for m in re.finditer(r\"(\\W)(\\d+\\.)0(\\W)\" , src):\n",
  1023. " src = src.replace(m.group(0), m.group(1)+m.group(2)+m.group(3))\n",
  1024. " for m in re.finditer(r\"(\\W)0(\\.\\d+)(\\W)\" , src):\n",
  1025. " src = src.replace(m.group(0), m.group(1)+m.group(2)+m.group(3))\n",
  1026. " src = src.replace(\"(in \", \"(\")\n",
  1027. " src = src.replace(\",in \", \",\")\n",
  1028. " src = src.replace(\"(void)\", \"()\")\n",
  1029. " src = re.sub(r\"\\n+\", \"\\n\", src)\n",
  1030. " src = re.sub(r\"^\\n\", \"\", src)\n",
  1031. " return src\n",
  1032. "\n",
  1033. "def usedChar(src):\n",
  1034. " L = []\n",
  1035. " for m in re.finditer(r\"(\\W)([a-zA-z]\\w*)\", src):\n",
  1036. " if m.group(1) != \".\" and len(m.group(2)) < 3:\n",
  1037. " L.append(m.group(2))\n",
  1038. " return list(set(L))\n",
  1039. "\n",
  1040. "def virginChar(L):\n",
  1041. " L1 = []\n",
  1042. " L2 = []\n",
  1043. " for s in L:\n",
  1044. " if len(s) == 1:\n",
  1045. " L1.append(s)\n",
  1046. " else:\n",
  1047. " L2.append(s)\n",
  1048. " c = string.ascii_lowercase + string.ascii_uppercase\n",
  1049. " nameL = [c[i] for i in range(len(c))]\n",
  1050. " for s in L1:\n",
  1051. " while s in nameL: nameL.remove(s)\n",
  1052. " if len(nameL) > 0:\n",
  1053. " return nameL[0]\n",
  1054. " else:\n",
  1055. " c = string.ascii_uppercase\n",
  1056. " c = [c[i] for i in range(len(c))]\n",
  1057. " s = c[0] + c[0]\n",
  1058. " n = 0\n",
  1059. " while s in L2:\n",
  1060. " n += 1\n",
  1061. " s = c[n // len(c)] + c[n % len(c)]\n",
  1062. " return s\n",
  1063. "\n",
  1064. "def replaceChar(fr0m, t0, src):\n",
  1065. " for _ in range(2):\n",
  1066. " for m in re.finditer(r\"(\\W)\" + fr0m + \"(\\W)\", src):\n",
  1067. " if m.group(1) != \".\":\n",
  1068. " src = src.replace(m.group(1) + fr0m + m.group(2), m.group(1) + t0 + m.group(2))\n",
  1069. " return src\n",
  1070. " \n",
  1071. "def glslMinify(src, oneCharD={}):\n",
  1072. " src = glslTrim(src)\n",
  1073. " # 関数、構造体の宣言部分の取得\n",
  1074. " headL = []\n",
  1075. " for m in re.finditer(r\"(\\w+ \\w+.*?){\", re.sub(r\"[;}]\", \"\\n\", src)):\n",
  1076. " if len(list(re.finditer(\"if\" , m.group(1)))) == 0:\n",
  1077. " headL.append(m.group(1))\n",
  1078. " \n",
  1079. " # 関数、構造体のスクリプト部分の取得する為の正規表現を作成\n",
  1080. " regL = []\n",
  1081. " code = {\"{\" : 1, \"}\" : -1}\n",
  1082. " pool = \"\"\n",
  1083. " lv = 0\n",
  1084. " for m in re.finditer(r\"[{}]\" , src):\n",
  1085. " lv += code[m.group()]\n",
  1086. " pool = pool + m.group()\n",
  1087. " if lv == 0:\n",
  1088. " regL.append(\".*?\".join([pool[x] for x in range(len(pool))]))\n",
  1089. " pool = \"\"\n",
  1090. " \n",
  1091. " # 関数、構造体ブロックのリストを作成\n",
  1092. " funcBlockL = []\n",
  1093. " structBlockL = []\n",
  1094. " for (head, reg) in zip(headL, regL):\n",
  1095. " if head[0:6] == \"struct\":\n",
  1096. " structBlockL.append(re.search(head.replace(\"(\", \"\\(\").replace(\")\", \"\\)\") + reg, src, re.DOTALL).group())\n",
  1097. " else:\n",
  1098. " funcBlockL.append(re.search(head.replace(\"(\", \"\\(\").replace(\")\", \"\\)\") + reg, src, re.DOTALL).group())\n",
  1099. " \n",
  1100. " # 関数、構造体の名前を取得\n",
  1101. " funcL = []\n",
  1102. " structL = []\n",
  1103. " for s in headL:\n",
  1104. " for m in re.finditer(r\"(\\w+) (\\w+).*\", s):\n",
  1105. " if m.group(1) == \"struct\":\n",
  1106. " structL.append(m.group(2))\n",
  1107. " else:\n",
  1108. " funcL.append(m.group(2))\n",
  1109. " funcL = list(set(funcL))\n",
  1110. " funcL.remove(\"main\")\n",
  1111. " \n",
  1112. " # グローバル変数の名前を取得\n",
  1113. " globalVarL = []\n",
  1114. " defineL = []\n",
  1115. " uniformL = []\n",
  1116. " outL = []\n",
  1117. " temp = src\n",
  1118. " for s in funcBlockL:\n",
  1119. " temp = temp.replace(s, \"\")\n",
  1120. " for s in structBlockL:\n",
  1121. " temp = temp.replace(s, \"\")\n",
  1122. " globalLineL = re.split('[\\n;]', temp)\n",
  1123. " while \"\" in globalLineL: globalLineL.remove(\"\")\n",
  1124. " for s in globalLineL:\n",
  1125. " if s.startswith(\"#version\"):\n",
  1126. " while s in globalLineL: globalLineL.remove(s)\n",
  1127. " for s in globalLineL:\n",
  1128. " if s.startswith(\"#define\"):\n",
  1129. " for m in re.finditer(r\"#define (\\w+) (.*)\", s):\n",
  1130. " defineL.append((s, m.group(1), m.group(2)))\n",
  1131. " else:\n",
  1132. " s = re.sub(r\".*?in \", \"in \", s)\n",
  1133. " if s.startswith(\"uniform\"):\n",
  1134. " s = re.sub(r\"^\\w+ \\w+ \", \"\", s)\n",
  1135. " uniformL = uniformL + re.split(r\",\", s)\n",
  1136. " elif s.startswith(\"out\"):\n",
  1137. " s = re.sub(r\"^\\w+ \\w+ \", \"\", s)\n",
  1138. " outL = outL + re.split(r\",\", s)\n",
  1139. " elif s.startswith(\"in\"):\n",
  1140. " s = re.sub(r\"^\\w+ \\w+ \", \"\", s)\n",
  1141. " else:\n",
  1142. " s = re.sub(r\"^\\w+ \", \"\", s)\n",
  1143. " globalVarL = globalVarL + re.split(r\",\", s)\n",
  1144. " \n",
  1145. " # 関数、構造体、グローバル変数をキーにした1文字Dicの作成\n",
  1146. " oneCharL = list(oneCharD.values())\n",
  1147. " for x,y,z in defineL:\n",
  1148. " if len(y) == 1:\n",
  1149. " oneCharL.append(y)\n",
  1150. " for s in globalVarL + structL + funcL:\n",
  1151. " if len(s) == 1:\n",
  1152. " oneCharL.append(s)\n",
  1153. " else:\n",
  1154. " if s not in oneCharD:\n",
  1155. " char = virginChar(oneCharL)\n",
  1156. " oneCharD[s] = char\n",
  1157. " oneCharL.append(char)\n",
  1158. " uniformD = {}\n",
  1159. " outD = {}\n",
  1160. " for s in uniformL:\n",
  1161. " uniformD[s] = oneCharD[s]\n",
  1162. " for s in outL:\n",
  1163. " outD[s] = oneCharD[s]\n",
  1164. " \n",
  1165. " # ブロック毎に置換 \n",
  1166. " for s in funcBlockL:\n",
  1167. " \n",
  1168. " # ローカル変数取得 \n",
  1169. " temp = s\n",
  1170. " varL = []\n",
  1171. " f = s.split(\"{\", 1)\n",
  1172. " f[0] = re.sub(r\"^\\w+ \\w+\", \"\", f[0])\n",
  1173. " f[0] = f[0].replace(\",\", \",,\")\n",
  1174. " for m in re.finditer(\"\\w+ (\\w+)\", f[0]):\n",
  1175. " varL.append(m.group(1))\n",
  1176. " f[1] = re.sub(r\"return.*?;\", \"\", f[1])\n",
  1177. " f[1] = re.sub(r\"const \", \"\", f[1])\n",
  1178. " f[1] = re.sub(r\"else if\", \"\", f[1])\n",
  1179. " for a in re.split(r'[{};]', f[1]):\n",
  1180. " for m in re.finditer(r\"^\\w+ (\\w+)\" , a): \n",
  1181. " for i in range(5):\n",
  1182. " a = re.sub(r\"\\([^\\(\\)]+\\)\", \"\", a)\n",
  1183. " for i in re.sub(r\"^\\w+ \", \"\", a).split(\",\"):\n",
  1184. " for m in re.finditer(r\"^\\w+\" , i):\n",
  1185. " varL.append(m.group())\n",
  1186. " for m in re.finditer(r\"for\\(\\w+ (\\w+)\" , a):\n",
  1187. " varL.append(m.group(1))\n",
  1188. " varL = list(set(varL))\n",
  1189. " \n",
  1190. " # ローカル変数の一時的置換\n",
  1191. " for i in range(len(varL)):\n",
  1192. " temp = replaceChar(varL[i], \"dummy%03d\" % i, temp)\n",
  1193. "\n",
  1194. " # 関数、構造体、グローバル変数の置換\n",
  1195. " for k,v in oneCharD.items():\n",
  1196. " temp = replaceChar(k, v, temp)\n",
  1197. "\n",
  1198. " # 1文字 関数、構造体、グローバル変数、defineの取得\n",
  1199. " oneCharL = usedChar(temp)\n",
  1200. " for x,y,z in defineL:\n",
  1201. " if len(y) == 1:\n",
  1202. " oneCharL.append(y)\n",
  1203. " \n",
  1204. " # ローカル変数の置換\n",
  1205. " sz = -1\n",
  1206. " for m in re.finditer(r\"dummy(\\d+)\", temp): \n",
  1207. " sz = max(int(m.group(1)), sz)\n",
  1208. " for i in range(sz + 1):\n",
  1209. " char = virginChar(oneCharL)\n",
  1210. " temp = replaceChar(\"dummy%03d\" % i, char, temp)\n",
  1211. " oneCharL.append(char)\n",
  1212. " \n",
  1213. " # ソースの置換\n",
  1214. " src = src.replace(s, temp) \n",
  1215. " for k,v in oneCharD.items():\n",
  1216. " src = replaceChar(k, v, src)\n",
  1217. " for s,fr0m,t0 in defineL:\n",
  1218. " src = src.replace(s, \"\")\n",
  1219. " src = replaceChar(fr0m, t0, src)\n",
  1220. " src = re.sub(r\"\\n\\n+\", \"\", src)\n",
  1221. " return (src, uniformD, outD) "
  1222. ]
  1223. },
  1224. {
  1225. "cell_type": "code",
  1226. "execution_count": 28,
  1227. "metadata": {
  1228. "collapsed": false,
  1229. "scrolled": false
  1230. },
  1231. "outputs": [],
  1232. "source": [
  1233. "vsh, uniformD, outD = glslMinify(vsh,{})\n",
  1234. "var[\"U_RESOLUTION\"] = uniformD[var[\"U_RESOLUTION\"]]\n",
  1235. "var[\"U_TIME\"] = uniformD[var[\"U_TIME\"]]\n",
  1236. "fsh, dummy0, dummy1 = glslMinify(fsh, outD)\n",
  1237. "\n",
  1238. "msh = glslTrim(msh)\n",
  1239. "\n",
  1240. "msh, uniformD, outD = glslMinify(msh,{})\n",
  1241. "var[\"U_SAMPLERATE\"] = uniformD[var[\"U_SAMPLERATE\"]]\n",
  1242. "var[\"O_GAIN\"] = outD[var[\"O_GAIN\"]]"
  1243. ]
  1244. },
  1245. {
  1246. "cell_type": "code",
  1247. "execution_count": 29,
  1248. "metadata": {
  1249. "collapsed": true
  1250. },
  1251. "outputs": [],
  1252. "source": [
  1253. "# Debug and Compile and Run\n",
  1254. "\n",
  1255. "src = makeCSrc4debug(gfx_init, gfx_do, vsh, fsh, msh, var)\n",
  1256. "fWrite(\"demo.c\", src)\n",
  1257. "batch(r\"\"\"\n",
  1258. " echo off\n",
  1259. " set PATH={0};%PATH%\n",
  1260. " gcc demo.c -O3 -Wall -lopengl32 -lgdi32 -lwinmm -o demo.exe\n",
  1261. " demo.exe\n",
  1262. " rem exit\n",
  1263. "\"\"\".format(gccPath))"
  1264. ]
  1265. },
  1266. {
  1267. "cell_type": "code",
  1268. "execution_count": 30,
  1269. "metadata": {
  1270. "collapsed": false
  1271. },
  1272. "outputs": [],
  1273. "source": [
  1274. "def makeCSrc4release(gfx_init, gfx_do, vsh, fsh, msh, var):\n",
  1275. " conf = {\n",
  1276. " \"SND_DURATION\" : playTime,\n",
  1277. " \"SAMPLE_RATE\" : 48000,\n",
  1278. " \"SND_NUMCHANNELS\" : 2,\n",
  1279. " \"XRES\" : 1920,\n",
  1280. " \"YRES\" : 1080,\n",
  1281. " }\n",
  1282. " def inlineCompileFunc(src):\n",
  1283. " for m in re.finditer(\"compile\\((\\w+), (\\w+), (\\w+)\\);\" , src):\n",
  1284. " s = m.group()\n",
  1285. " dst = \"\"\"\n",
  1286. " tmp = glCreateShader({2});\n",
  1287. " glShaderSource(tmp, 1, &{1}, 0);\n",
  1288. " glCompileShader(tmp);\n",
  1289. " glAttachShader({0}, tmp); \n",
  1290. "\"\"\".format(m.group(1),m.group(2),m.group(3))\n",
  1291. " src = src.replace(s, dst)\n",
  1292. " return src\n",
  1293. "\n",
  1294. " src =\"\"\"\n",
  1295. "#include <windows.h>\n",
  1296. "#include <GL/gl.h>\n",
  1297. "#include <GL/glext.h>\n",
  1298. "#include <mmreg.h>\n",
  1299. "\n",
  1300. "\"\"\" + \"\"\"\n",
  1301. "static const char *vsh = \"{0}\";\n",
  1302. "static const char *fsh = \"{1}\";\n",
  1303. "static const char *msh = \"{2}\";\n",
  1304. "\n",
  1305. "\"\"\".format(\n",
  1306. " vsh.replace(\"\\n\",r\"\\n\"),\n",
  1307. " fsh.replace(\"\\n\",r\"\\n\"),\n",
  1308. " msh.replace(\"\\n\",r\"\\n\")\n",
  1309. " ) + \"\"\"\n",
  1310. " \n",
  1311. "\"\"\" + dic2code(var) + dic2code(conf) + \"\"\"\n",
  1312. "\n",
  1313. "#define SND_NUMSAMPLES (SND_DURATION*SAMPLE_RATE)\n",
  1314. "#define SND_NUMSAMPLESC (SND_NUMSAMPLES*SND_NUMCHANNELS)\n",
  1315. "\n",
  1316. "float samples[SND_NUMSAMPLESC];\n",
  1317. "\n",
  1318. "void entrypoint(){\n",
  1319. " DEVMODE dmScreenSettings={{0},0,0,sizeof(DEVMODE),0,DM_PELSWIDTH|DM_PELSHEIGHT,{0},0,0,0,0,0,{0},0,0,XRES,YRES,{0},0};\n",
  1320. " ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN);\n",
  1321. " HWND hWnd = CreateWindow((LPCSTR)0xC018,0,WS_POPUP|WS_VISIBLE|WS_MAXIMIZE,0,0,0,0,0,0,0,0);\n",
  1322. " ShowCursor(0);\n",
  1323. " HDC hDC = GetDC(hWnd);\n",
  1324. " PIXELFORMATDESCRIPTOR pfd={0,1,PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER,32,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0};\n",
  1325. " SetPixelFormat(hDC, ChoosePixelFormat(hDC, &pfd) , &pfd);\n",
  1326. " HGLRC hGLrc = wglCreateContext(hDC);\n",
  1327. " wglMakeCurrent(hDC, hGLrc);\n",
  1328. " \n",
  1329. " GLuint tmp;\n",
  1330. " GLuint programMzk = glCreateProgram();\n",
  1331. " compile(programMzk, msh, GL_VERTEX_SHADER);\n",
  1332. " const GLchar* outs[] = {O_GAIN};\n",
  1333. " glTransformFeedbackVaryings(programMzk, 1, outs, GL_INTERLEAVED_ATTRIBS);\n",
  1334. " glLinkProgram(programMzk);\n",
  1335. " glUseProgram(programMzk);\n",
  1336. " glGenBuffers(1, &tmp);\n",
  1337. " glBindBuffer(GL_ARRAY_BUFFER, tmp);\n",
  1338. " glBufferData(GL_ARRAY_BUFFER, SND_NUMSAMPLESC*sizeof(float), 0, GL_STATIC_READ);\n",
  1339. " glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tmp);\n",
  1340. " glUniform1f(glGetUniformLocation(programMzk, U_SAMPLERATE), (float)SAMPLE_RATE);\n",
  1341. " glEnable(GL_RASTERIZER_DISCARD);\n",
  1342. " glBeginTransformFeedback(GL_POINTS);\n",
  1343. " glDrawArrays(GL_POINTS, 0, SND_NUMSAMPLES);\n",
  1344. " glEndTransformFeedback();\n",
  1345. " glDisable(GL_RASTERIZER_DISCARD);\n",
  1346. " glGetBufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, sizeof(samples), samples);\n",
  1347. " \n",
  1348. "\"\"\" + gfx_init + \"\"\"\n",
  1349. "\n",
  1350. " WAVEFORMATEX wave_format = {\n",
  1351. " WAVE_FORMAT_IEEE_FLOAT,\n",
  1352. " SND_NUMCHANNELS,\n",
  1353. " SAMPLE_RATE,\n",
  1354. " SAMPLE_RATE*sizeof(float)*SND_NUMCHANNELS,\n",
  1355. " sizeof(float)*SND_NUMCHANNELS,\n",
  1356. " sizeof(float)*8,\n",
  1357. " 0\n",
  1358. " };\n",
  1359. " WAVEHDR wave_hdr = {(LPSTR)samples, sizeof(samples)};\n",
  1360. " HWAVEOUT hWaveOut;\n",
  1361. " waveOutOpen(&hWaveOut, WAVE_MAPPER, &wave_format, (DWORD_PTR)hWnd, 0, CALLBACK_WINDOW);\n",
  1362. " waveOutPrepareHeader(hWaveOut, &wave_hdr, sizeof(wave_hdr));\n",
  1363. " waveOutWrite(hWaveOut, &wave_hdr, sizeof(wave_hdr));\n",
  1364. " MMTIME mmt = { TIME_SAMPLES };\n",
  1365. " MSG msg;\n",
  1366. " do {\n",
  1367. " PeekMessage(&msg, 0, 0, 0, TRUE);\n",
  1368. " waveOutGetPosition(hWaveOut, &mmt, sizeof(mmt));\n",
  1369. " float time = (float)mmt.u.sample / (float)SAMPLE_RATE;\n",
  1370. "\"\"\" + gfx_do + \"\"\"\n",
  1371. " SwapBuffers(hDC);\n",
  1372. " } while (!GetAsyncKeyState(VK_ESCAPE) && (mmt.u.sample < SND_NUMSAMPLES));\n",
  1373. "\n",
  1374. " ExitProcess(0);\n",
  1375. "} \n",
  1376. "\"\"\"\n",
  1377. " src = inlineCompileFunc(src)\n",
  1378. " return glRename(src)\n"
  1379. ]
  1380. },
  1381. {
  1382. "cell_type": "code",
  1383. "execution_count": 31,
  1384. "metadata": {
  1385. "collapsed": false
  1386. },
  1387. "outputs": [],
  1388. "source": [
  1389. "src = makeCSrc4release(gfx_init, gfx_do, vsh, fsh, msh, var)\n",
  1390. "fWrite(\"demo.c\", src)\n",
  1391. "cmd = \"echo off\\n\"\n",
  1392. "cmd = cmd + \"set PATH={0};{1};%PATH%\\n\".format(gccPath, crinklerPath)\n",
  1393. "cmd = cmd + \"gcc -m32 -c demo.c -o demo.o\\n\"\n",
  1394. "cmd = cmd + \"crinkler /OUT:demo.exe /LIBPATH:{0} \".format(libPath)\n",
  1395. "cmd = cmd +\"/COMPMODE:FAST /ENTRY:entrypoint /RANGE:opengl32 /SUBSYSTEM:WINDOWS /ORDERTRIES:1000 \"\n",
  1396. "#cmd = cmd +\"/COMPMODE:SLOW /ENTRY:entrypoint /RANGE:opengl32 /SUBSYSTEM:WINDOWS /ORDERTRIES:1000 \"\n",
  1397. "cmd = cmd +\"/PRINT:IMPORTS /PRINT:LABELS kernel32.lib user32.lib gdi32.lib opengl32.lib winmm.lib demo.o \\n\"\n",
  1398. "cmd = cmd + \"rem exit\\n\"\n",
  1399. "batch(cmd)"
  1400. ]
  1401. },
  1402. {
  1403. "cell_type": "code",
  1404. "execution_count": null,
  1405. "metadata": {
  1406. "collapsed": true
  1407. },
  1408. "outputs": [],
  1409. "source": []
  1410. },
  1411. {
  1412. "cell_type": "code",
  1413. "execution_count": 32,
  1414. "metadata": {
  1415. "collapsed": false
  1416. },
  1417. "outputs": [
  1418. {
  1419. "name": "stdout",
  1420. "output_type": "stream",
  1421. "text": [
  1422. "6219\n",
  1423. "1625\n",
  1424. "551\n"
  1425. ]
  1426. }
  1427. ],
  1428. "source": [
  1429. "print(len(vsh))\n",
  1430. "print(len(fsh))\n",
  1431. "print(len(msh))"
  1432. ]
  1433. },
  1434. {
  1435. "cell_type": "code",
  1436. "execution_count": 33,
  1437. "metadata": {
  1438. "collapsed": false
  1439. },
  1440. "outputs": [],
  1441. "source": [
  1442. " batch(r\"\"\"\n",
  1443. " demo.exe\n",
  1444. " exit\n",
  1445. " \"\"\")"
  1446. ]
  1447. },
  1448. {
  1449. "cell_type": "code",
  1450. "execution_count": 34,
  1451. "metadata": {
  1452. "collapsed": false
  1453. },
  1454. "outputs": [
  1455. {
  1456. "name": "stdout",
  1457. "output_type": "stream",
  1458. "text": [
  1459. "File Size : 3.8k 3882byte\n"
  1460. ]
  1461. }
  1462. ],
  1463. "source": [
  1464. "s = os.path.getsize(\"demo.exe\")\n",
  1465. "print(\"File Size : {0:.1f}k {1}byte\".format(s/1024, s))\n"
  1466. ]
  1467. },
  1468. {
  1469. "cell_type": "code",
  1470. "execution_count": null,
  1471. "metadata": {
  1472. "collapsed": true
  1473. },
  1474. "outputs": [],
  1475. "source": []
  1476. },
  1477. {
  1478. "cell_type": "markdown",
  1479. "metadata": {},
  1480. "source": [
  1481. "実行ファイルサイズが4096バイトを超えないこと"
  1482. ]
  1483. },
  1484. {
  1485. "cell_type": "code",
  1486. "execution_count": null,
  1487. "metadata": {
  1488. "collapsed": true
  1489. },
  1490. "outputs": [],
  1491. "source": []
  1492. }
  1493. ],
  1494. "metadata": {
  1495. "kernelspec": {
  1496. "display_name": "Python 3",
  1497. "language": "python",
  1498. "name": "python3"
  1499. },
  1500. "language_info": {
  1501. "codemirror_mode": {
  1502. "name": "ipython",
  1503. "version": 3
  1504. },
  1505. "file_extension": ".py",
  1506. "mimetype": "text/x-python",
  1507. "name": "python",
  1508. "nbconvert_exporter": "python",
  1509. "pygments_lexer": "ipython3",
  1510. "version": "3.4.3"
  1511. }
  1512. },
  1513. "nbformat": 4,
  1514. "nbformat_minor": 0
  1515. }
Add Comment
Please, Sign In to add comment