Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.90 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {
  7. "collapsed": true
  8. },
  9. "outputs": [],
  10. "source": [
  11. "import rebound"
  12. ]
  13. },
  14. {
  15. "cell_type": "code",
  16. "execution_count": 22,
  17. "metadata": {
  18. "collapsed": true
  19. },
  20. "outputs": [],
  21. "source": [
  22. "def f(sim,c):\n",
  23. " i,j = c.p1,c.p2\n",
  24. " print(sim.contents.t,sim.contents.particles[i],sim.contents.particles[j])\n",
  25. " return 1 # this will remove particle 1, return 0 to keep both particles."
  26. ]
  27. },
  28. {
  29. "cell_type": "code",
  30. "execution_count": 23,
  31. "metadata": {
  32. "collapsed": false
  33. },
  34. "outputs": [
  35. {
  36. "data": {
  37. "text/html": [
  38. "\n",
  39. "<script id=\"orbit_shader-vs\" type=\"x-shader/x-vertex\">\n",
  40. " uniform vec3 focus;\n",
  41. " uniform vec3 aef;\n",
  42. " uniform vec3 omegaOmegainc;\n",
  43. " attribute float lintwopi;\n",
  44. " varying float lin;\n",
  45. " uniform mat4 mvp;\n",
  46. " const float M_PI = 3.14159265359;\n",
  47. " void main() {\n",
  48. " float a = aef.x;\n",
  49. " float e = aef.y;\n",
  50. " float f = aef.z+lintwopi;\n",
  51. " lin = lintwopi/(M_PI*2.);\n",
  52. " if (e>1.){\n",
  53. " float theta_max = acos(-1./e);\n",
  54. " f = 0.0001-theta_max+1.9998*lin*theta_max;\n",
  55. " lin = sqrt(min(0.5,lin));\n",
  56. " }\n",
  57. " float omega = omegaOmegainc.x;\n",
  58. " float Omega = omegaOmegainc.y;\n",
  59. " float inc = omegaOmegainc.z;\n",
  60. " float r = a*(1.-e*e)/(1. + e*cos(f));\n",
  61. " float cO = cos(Omega);\n",
  62. " float sO = sin(Omega);\n",
  63. " float co = cos(omega);\n",
  64. " float so = sin(omega);\n",
  65. " float cf = cos(f);\n",
  66. " float sf = sin(f);\n",
  67. " float ci = cos(inc);\n",
  68. " float si = sin(inc);\n",
  69. " vec3 pos = vec3(r*(cO*(co*cf-so*sf) - sO*(so*cf+co*sf)*ci),r*(sO*(co*cf-so*sf) + cO*(so*cf+co*sf)*ci),+ r*(so*cf+co*sf)*si);\n",
  70. " gl_Position = mvp*(vec4(focus+pos, 1.0));\n",
  71. " }\n",
  72. "</script>\n",
  73. "<script id=\"orbit_shader-fs\" type=\"x-shader/x-fragment\">\n",
  74. " precision mediump float;\n",
  75. " varying float lin;\n",
  76. " void main() {\n",
  77. " float fog = max(max(0.,-1.+2.*gl_FragCoord.z),max(0.,1.-2.*gl_FragCoord.z));\n",
  78. " gl_FragColor = vec4(1.,1.,1.,sqrt(lin)*(1.-fog));\n",
  79. " }\n",
  80. "</script>\n",
  81. "<script id=\"point_shader-vs\" type=\"x-shader/x-vertex\">\n",
  82. " attribute vec3 vp;\n",
  83. " uniform mat4 mvp;\n",
  84. " //uniform vec4 vc;\n",
  85. " //varying vec4 color;\n",
  86. " void main() {\n",
  87. " gl_PointSize = 15.0;\n",
  88. " gl_Position = mvp*vec4(vp, 1.0);\n",
  89. " //color = vc;\n",
  90. " }\n",
  91. "</script>\n",
  92. "<script id=\"point_shader-fs\" type=\"x-shader/x-fragment\">\n",
  93. " precision mediump float;\n",
  94. " //varying vec4 color;\n",
  95. " void main() {\n",
  96. " vec2 rel = gl_PointCoord.st;\n",
  97. " rel.s -=0.5;\n",
  98. " rel.t -=0.5;\n",
  99. " if (length(rel)>0.25){\n",
  100. " gl_FragColor = vec4(0.,0.,0.,0.); \n",
  101. " }else{\n",
  102. " vec4 cmod = vec4(1.,1.,1.,1.);\n",
  103. " float fog = max(max(0.,-1.+2.*gl_FragCoord.z),max(0.,1.-2.*gl_FragCoord.z));\n",
  104. " cmod.a*= (1.-fog)*min(1.,1.-4.*(length(rel)/0.25-0.75));\n",
  105. " gl_FragColor = cmod;\n",
  106. " }\n",
  107. " }\n",
  108. "</script>\n",
  109. "\n",
  110. "<script>\n",
  111. "function compileShader(glr, shaderSource, shaderType) {\n",
  112. " // Create the shader object\n",
  113. " var shader = glr.createShader(shaderType);\n",
  114. " \n",
  115. " // Set the shader source code.\n",
  116. " glr.shaderSource(shader, shaderSource);\n",
  117. " \n",
  118. " // Compile the shader\n",
  119. " glr.compileShader(shader);\n",
  120. " \n",
  121. " // Check if it compiled\n",
  122. " var success = glr.getShaderParameter(shader, glr.COMPILE_STATUS);\n",
  123. " if (!success) {\n",
  124. " // Something went wrong during compilation; get the error\n",
  125. " throw \"could not compile shader:\" + glr.getShaderInfoLog(shader);\n",
  126. " }\n",
  127. " \n",
  128. " return shader;\n",
  129. "}\n",
  130. "function createShaderFromScript(glr, scriptId, opt_shaderType) {\n",
  131. " // look up the script tag by id.\n",
  132. " var shaderScript = document.getElementById(scriptId);\n",
  133. " if (!shaderScript) {\n",
  134. " throw(\"*** Error: unknown script element\" + scriptId);\n",
  135. " }\n",
  136. " \n",
  137. " // extract the contents of the script tag.\n",
  138. " var shaderSource = shaderScript.text;\n",
  139. " \n",
  140. " // If we didn't pass in a type, use the 'type' from\n",
  141. " // the script tag.\n",
  142. " if (!opt_shaderType) {\n",
  143. " if (shaderScript.type == \"x-shader/x-vertex\") {\n",
  144. " opt_shaderType = glr.VERTEX_SHADER;\n",
  145. " } else if (shaderScript.type == \"x-shader/x-fragment\") {\n",
  146. " opt_shaderType = glr.FRAGMENT_SHADER;\n",
  147. " } else if (!opt_shaderType) {\n",
  148. " throw(\"*** Error: shader type not set\");\n",
  149. " }\n",
  150. " }\n",
  151. " \n",
  152. " return compileShader(glr, shaderSource, opt_shaderType);\n",
  153. "};\n",
  154. "function createProgramFromScripts( glr, vertexShaderId, fragmentShaderId) {\n",
  155. " var vertexShader = createShaderFromScript(glr, vertexShaderId, glr.VERTEX_SHADER);\n",
  156. " var fragmentShader = createShaderFromScript(glr, fragmentShaderId, glr.FRAGMENT_SHADER);\n",
  157. " var program = glr.createProgram();\n",
  158. " \n",
  159. " // attach the shaders.\n",
  160. " glr.attachShader(program, vertexShader);\n",
  161. " glr.attachShader(program, fragmentShader);\n",
  162. " \n",
  163. " // link the program.\n",
  164. " glr.linkProgram(program);\n",
  165. " \n",
  166. " // Check if it linked.\n",
  167. " var success = glr.getProgramParameter(program, glr.LINK_STATUS);\n",
  168. " if (!success) {\n",
  169. " // something went wrong with the link\n",
  170. " throw (\"program filed to link:\" + glr.getProgramInfoLog (program));\n",
  171. " }\n",
  172. " \n",
  173. " return program;\n",
  174. "}\n",
  175. "function quat2mat(A,mat){\n",
  176. " var xx = A.x*A.x; var xy = A.x*A.y; var xz = A.x*A.z;\n",
  177. " var xw = A.x*A.w; var yy = A.y*A.y; var yz = A.y*A.z;\n",
  178. " var yw = A.y*A.w; var zz = A.z*A.z; var zw = A.z*A.w;\n",
  179. " mat[0] = 1.-2.*(yy+zz);\n",
  180. " mat[1] = 2.*(xy-zw);\n",
  181. " mat[2] = 2.*(xz+yw);\n",
  182. " mat[4] = 2.*(xy+zw);\n",
  183. " mat[5] = 1.-2.*(xx+zz);\n",
  184. " mat[6] = 2.*(yz-xw);\n",
  185. " mat[8] = 2.*(xz-yw);\n",
  186. " mat[9] = 2.*(yz+xw);\n",
  187. " mat[10]= 1.-2.*(xx+yy);\n",
  188. " mat[3] = mat[7] = mat[11] = mat[12] = mat[13] = mat[14] = 0.; mat[15]= 1.;\n",
  189. "}\n",
  190. "function multvec(A, B, vecr){\n",
  191. " var mat = [0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.];\n",
  192. " quat2mat(A,mat);\n",
  193. " vecr[0] = mat[0]*B[0] + mat[1]*B[1] + mat[2]*B[2];\n",
  194. " vecr[1] = mat[4]*B[0] + mat[5]*B[1] + mat[6]*B[2];\n",
  195. " vecr[2] = mat[8]*B[0] + mat[9]*B[1] + mat[10]*B[2];\n",
  196. "}\n",
  197. "function mattransp(mat){\n",
  198. " var matt = [\n",
  199. " mat[0], mat[4], mat[8], mat[12],\n",
  200. " mat[1], mat[5], mat[9], mat[13],\n",
  201. " mat[2], mat[6], mat[10], mat[14],\n",
  202. " mat[3], mat[7], mat[11], mat[15]];\n",
  203. " return matt;\n",
  204. "}\n",
  205. "function conjugate(quat){\n",
  206. " var cquat = {x:-quat.x, y:-quat.y, z:-quat.z, w:quat.w};\n",
  207. " return cquat;\n",
  208. "}\n",
  209. "function mult(A, B){\n",
  210. " var mquat = { x: A.w*B.x + A.x*B.w + A.y*B.z - A.z*B.y,\n",
  211. " y: A.w*B.y - A.x*B.z + A.y*B.w + A.z*B.x,\n",
  212. " z: A.w*B.z + A.x*B.y - A.y*B.x + A.z*B.w,\n",
  213. " w: A.w*B.w - A.x*B.x - A.y*B.y - A.z*B.z};\n",
  214. " return mquat;\n",
  215. "}\n",
  216. "\n",
  217. "function normalize(quat){\n",
  218. " var L = Math.sqrt(quat.x*quat.x + quat.y*quat.y + quat.z*quat.z + quat.w*quat.w);\n",
  219. " var nquat = {x:quat.x/L, y:quat.y/L, z:quat.z/L, w:quat.w/L};\n",
  220. " return nquat;\n",
  221. "}\n",
  222. "function matortho(mat, l, r, b, t, n, f){\n",
  223. " mat[0] = 2./(r-l); mat[1] = 0.; mat[2] = 0.; mat[3] = -(r+l)/(r-l);\n",
  224. " mat[4] = 0.; mat[5] = 2./(t-b); mat[6] = 0.; mat[7] = -(t+b)/(t-b);\n",
  225. " mat[8] = 0.; mat[9] = 0.; mat[10] = -2./(f-n); mat[11] = -(f+n)/(f-n);\n",
  226. " mat[12] = 0.; mat[13] = 0.; mat[14] = 0.; mat[15] = 1.;\n",
  227. "}\n",
  228. "function matmult(A,B,C){\n",
  229. " for(i=0;i<4;i++){\n",
  230. " for(j=0;j<4;j++){\n",
  231. " C[i+4*j] = 0.;\n",
  232. " for(k=0;k<4;k++){\n",
  233. " C[i+4*j] += A[k+4*j]*B[i+4*k];\n",
  234. " }}}\n",
  235. "}\n",
  236. "function startGL(reboundView) {\n",
  237. " var canvas = document.getElementById(\"reboundcanvas-\"+reboundView.id);\n",
  238. " if (!canvas){\n",
  239. " reboundView.startCount = reboundView.startCount+1;\n",
  240. " if (reboundView.startCount>1000){\n",
  241. " console.log(\"Cannot find element.\");\n",
  242. " }else{\n",
  243. " setTimeout(function(){ startGL(reboundView); }, 10);\n",
  244. " }\n",
  245. " return;\n",
  246. " }\n",
  247. " var rect = canvas.getBoundingClientRect()\n",
  248. " reboundView.ratio = rect.width/rect.height;\n",
  249. " reboundView.view = normalize({x:reboundView.orientation[0], y:reboundView.orientation[1], z:reboundView.orientation[2], w:reboundView.orientation[3]});\n",
  250. "\n",
  251. " canvas.addEventListener('mousedown', function() {\n",
  252. " reboundView.mouseDown=1;\n",
  253. " }, false);\n",
  254. " canvas.addEventListener('mouseup', function() {\n",
  255. " reboundView.mouseDown=0;\n",
  256. " }, false);\n",
  257. " canvas.addEventListener('mouseleave', function() {\n",
  258. " reboundView.mouseDown=0;\n",
  259. " }, false);\n",
  260. "\n",
  261. " canvas.addEventListener('mousemove', function(evt) {\n",
  262. " var rect = canvas.getBoundingClientRect()\n",
  263. " if (reboundView.mouseDown==1){\n",
  264. " reboundView.mouseDown = 2;\n",
  265. " reboundView.mouse_x = evt.clientX-rect.left;\n",
  266. " reboundView.mouse_y = evt.clientY-rect.top;\n",
  267. " return;\n",
  268. " }else if (reboundView.mouseDown==2){\n",
  269. " var width = rect.width;\n",
  270. " var height = rect.height;\n",
  271. " var dx = 3.*(evt.clientX-rect.left-reboundView.mouse_x)/width;\n",
  272. " var dy = 3.*(evt.clientY-rect.top-reboundView.mouse_y)/height;\n",
  273. " reboundView.mouse_x = evt.clientX-rect.left;\n",
  274. " reboundView.mouse_y = evt.clientY-rect.top;\n",
  275. " if (evt.shiftKey){\n",
  276. " reboundView.scale *= (1.+dx+dy);\n",
  277. " }else{\n",
  278. " var inv = conjugate(reboundView.view);\n",
  279. " var up = [0.,1.,0.];\n",
  280. " var right = [1.,0.,0.];\n",
  281. " var inv_up = [0.,0.,0.];\n",
  282. " var inv_right = [0.,0.,0.];\n",
  283. " multvec(inv, right, inv_right);\n",
  284. " multvec(inv, up, inv_up);\n",
  285. " \n",
  286. " var sin_dy = Math.sin(dy);\n",
  287. " var rot_dy = {x:inv_right[0]*sin_dy, y:inv_right[1]*sin_dy, z:inv_right[2]*sin_dy, w:Math.cos(dy)};\n",
  288. " reboundView.view = mult(reboundView.view, normalize(rot_dy));\n",
  289. " \n",
  290. " var sin_dx = Math.sin(dx);\n",
  291. " var rot_dx = {x:inv_up[0]*sin_dx, y:inv_up[1]*sin_dx, z:inv_up[2]*sin_dx, w:Math.cos(dx)};\n",
  292. " reboundView.view = normalize(mult(reboundView.view, normalize(rot_dx)));\n",
  293. " }\n",
  294. "\n",
  295. " drawGL(reboundView);\n",
  296. " }\n",
  297. "\n",
  298. "\n",
  299. " }, false);\n",
  300. "\n",
  301. " reboundView.gl = canvas.getContext(\"webgl\")||canvas.getContext(\"experimental-webgl\");\n",
  302. " if (!reboundView.gl) {\n",
  303. " alert(\"Unable to initialize WebGL. Your browser may not support it.\");\n",
  304. " return;\n",
  305. " }\n",
  306. " var gl = reboundView.gl\n",
  307. " gl.enable(gl.BLEND);\n",
  308. " gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);\n",
  309. " \n",
  310. " reboundView.orbit_shader_program = createProgramFromScripts(gl,\"orbit_shader-vs\",\"orbit_shader-fs\");\n",
  311. " reboundView.point_shader_program = createProgramFromScripts(gl,\"point_shader-vs\",\"point_shader-fs\");\n",
  312. " \n",
  313. " var lintwopi = new Float32Array(500);\n",
  314. " for(i=0;i<500;i++){\n",
  315. " lintwopi[i] = 2.*Math.PI/500.*i;\n",
  316. " }\n",
  317. " reboundView.orbit_lintwopi_buffer = gl.createBuffer();\n",
  318. " gl.bindBuffer(gl.ARRAY_BUFFER, reboundView.orbit_lintwopi_buffer);\n",
  319. " gl.bufferData(gl.ARRAY_BUFFER, 4*500, gl.STATIC_DRAW);\n",
  320. " gl.bufferSubData(gl.ARRAY_BUFFER, 0, lintwopi)\n",
  321. " reboundView.orbit_shader_mvp_location = gl.getUniformLocation(reboundView.orbit_shader_program,\"mvp\");\n",
  322. " reboundView.orbit_shader_focus_location = gl.getUniformLocation(reboundView.orbit_shader_program,\"focus\");\n",
  323. " reboundView.orbit_shader_aef_location = gl.getUniformLocation(reboundView.orbit_shader_program,\"aef\");\n",
  324. " reboundView.orbit_shader_omegaOmegainc_location = gl.getUniformLocation(reboundView.orbit_shader_program,\"omegaOmegainc\");\n",
  325. " \n",
  326. " reboundView.particle_data_buffer = gl.createBuffer();\n",
  327. " gl.useProgram(reboundView.point_shader_program);\n",
  328. " reboundView.point_shader_mvp_location = gl.getUniformLocation(reboundView.point_shader_program,\"mvp\");\n",
  329. " \n",
  330. " updateRenderData(reboundView);\n",
  331. " gl.clearColor(0.0, 0.0, 0.0, 1.0);\n",
  332. " gl.clear(gl.COLOR_BUFFER_BIT);\n",
  333. " drawGL(reboundView);\n",
  334. "}\n",
  335. "function updateRenderData(reboundView){\n",
  336. " var previousN = reboundView.N;\n",
  337. " reboundView.N = reboundView.model.get(\"N\");\n",
  338. " reboundView.t = reboundView.model.get(\"t\");\n",
  339. " reboundView.particle_data = reboundView.model.get('particle_data');\n",
  340. " if (reboundView.orbits){\n",
  341. " reboundView.orbit_data = reboundView.model.get('orbit_data');\n",
  342. " }\n",
  343. " var gl = reboundView.gl\n",
  344. " if (reboundView.N>0){\n",
  345. " gl.bindBuffer(gl.ARRAY_BUFFER, reboundView.particle_data_buffer);\n",
  346. " gl.bufferData(gl.ARRAY_BUFFER, reboundView.N*7*4, gl.DYNAMIC_DRAW);\n",
  347. " gl.bufferSubData(gl.ARRAY_BUFFER, 0, reboundView.particle_data)\n",
  348. " }\n",
  349. "}\n",
  350. "function drawGL(reboundView) {\n",
  351. " if (!reboundView.gl){\n",
  352. " return;\n",
  353. " }\n",
  354. " // Cleanup\n",
  355. " var gl = reboundView.gl\n",
  356. " gl.clearColor(0.0, 0.0, 0.0, 1.0);\n",
  357. " gl.clear(gl.COLOR_BUFFER_BIT);\n",
  358. " \n",
  359. " // Draw\n",
  360. " gl.useProgram(reboundView.point_shader_program);\n",
  361. " gl.bindBuffer(gl.ARRAY_BUFFER, reboundView.particle_data_buffer);\n",
  362. " var pvp = gl.getAttribLocation(reboundView.point_shader_program,\"vp\");\n",
  363. " gl.enableVertexAttribArray(pvp);\n",
  364. " gl.vertexAttribPointer(pvp, 3, gl.FLOAT, 0, 4*7,0); // 4 = size of float\n",
  365. " var projection = [0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.];\n",
  366. " if (reboundView.ratio>=1.){\n",
  367. " matortho(projection, \n",
  368. " -1.6*reboundView.scale, 1.6*reboundView.scale,\n",
  369. " -1.6/reboundView.ratio*reboundView.scale, 1.6/reboundView.ratio*reboundView.scale,\n",
  370. " -2.5*reboundView.scale, 2.5*reboundView.scale);\n",
  371. " }else{\n",
  372. " matortho(projection, \n",
  373. " -1.6*reboundView.ratio*reboundView.scale, 1.6*reboundView.ratio*reboundView.scale,\n",
  374. " -1.6*reboundView.scale, 1.6*reboundView.scale,\n",
  375. " -2.5*reboundView.scale, 2.5*reboundView.scale);\n",
  376. " }\n",
  377. " var view = [0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.];\n",
  378. " quat2mat(reboundView.view,view);\n",
  379. " var mvp = [0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.];\n",
  380. " matmult(projection,view,mvp);\n",
  381. " gl.uniformMatrix4fv(reboundView.point_shader_mvp_location,false,mattransp(mvp));\n",
  382. " gl.drawArrays(gl.POINTS,0,reboundView.N);\n",
  383. " \n",
  384. " if (reboundView.orbits){\n",
  385. " gl.useProgram(reboundView.orbit_shader_program);\n",
  386. " gl.bindBuffer(gl.ARRAY_BUFFER, reboundView.orbit_lintwopi_buffer);\n",
  387. " var ltp = gl.getAttribLocation(reboundView.orbit_shader_program,\"lintwopi\");\n",
  388. " gl.enableVertexAttribArray(ltp);\n",
  389. " gl.vertexAttribPointer(ltp, 1, gl.FLOAT, 0, 0,0); // 4 = size of float\n",
  390. " gl.uniformMatrix4fv(reboundView.orbit_shader_mvp_location,false,mattransp(mvp));\n",
  391. "\n",
  392. " // Need to do this one by one\n",
  393. " // because WebGL is not supporting\n",
  394. " // instancing:\n",
  395. " for(i=0;i<reboundView.N-1;i++){\n",
  396. " var focus = new Float32Array(reboundView.orbit_data.buffer,4*9*i,3);\n",
  397. " gl.uniform3fv(reboundView.orbit_shader_focus_location,focus);\n",
  398. " var aef = new Float32Array(reboundView.orbit_data.buffer,4*(9*i+3),3);\n",
  399. " gl.uniform3fv(reboundView.orbit_shader_aef_location,aef);\n",
  400. " var omegaOmegainc = new Float32Array(reboundView.orbit_data.buffer,4*(9*i+6),3);\n",
  401. " gl.uniform3fv(reboundView.orbit_shader_omegaOmegainc_location,omegaOmegainc);\n",
  402. "\n",
  403. " gl.drawArrays(gl.LINE_STRIP,0,500);\n",
  404. " }\n",
  405. " }\n",
  406. "}\n",
  407. "require.undef('rebound');\n",
  408. "define('rebound', [\"jupyter-js-widgets\"], function(widgets) {\n",
  409. " var ReboundView = widgets.DOMWidgetView.extend({\n",
  410. " render: function() {\n",
  411. " this.el.innerHTML = '<canvas style=\"display: inline\" id=\"reboundcanvas-'+this.id+'\" style=\"border: none;\" width=\"'+this.model.get(\"width\")+'\" height=\"'+this.model.get(\"height\")+'\"></canvas>';\n",
  412. " this.model.on('change:t', this.trigger_refresh, this);\n",
  413. " this.model.on('change:count', this.trigger_refresh, this);\n",
  414. " this.startCount = 0;\n",
  415. " this.gl = null;\n",
  416. " // Only copy those once\n",
  417. " this.scale = this.model.get(\"scale\");\n",
  418. " this.width = this.model.get(\"width\");\n",
  419. " this.height = this.model.get(\"height\");\n",
  420. " this.orbits = this.model.get(\"orbits\");\n",
  421. " this.orientation = this.model.get(\"orientation\");\n",
  422. " startGL(this);\n",
  423. " },\n",
  424. " trigger_refresh: function() {\n",
  425. " updateRenderData(this);\n",
  426. " drawGL(this);\n",
  427. " },\n",
  428. " });\n",
  429. " return {\n",
  430. " ReboundView: ReboundView\n",
  431. " };\n",
  432. "});\n",
  433. " \n",
  434. "</script>\n"
  435. ],
  436. "text/plain": [
  437. "<IPython.core.display.HTML object>"
  438. ]
  439. },
  440. "metadata": {},
  441. "output_type": "display_data"
  442. },
  443. {
  444. "data": {
  445. "application/vnd.jupyter.widget-view+json": {
  446. "model_id": "6f49a5ace54b4355b1d7d030434e303d"
  447. }
  448. },
  449. "metadata": {},
  450. "output_type": "display_data"
  451. }
  452. ],
  453. "source": [
  454. "sim = rebound.Simulation()\n",
  455. "sim.add(m=1)\n",
  456. "sim.add(m=1e-3,a=1,r=0.1)\n",
  457. "sim.add(m=1e-3,a=1.1,r=0.1,l=0.5)\n",
  458. "sim.collision = \"direct\"\n",
  459. "sim.collision_resolve = f\n",
  460. "sim.getWidget()"
  461. ]
  462. },
  463. {
  464. "cell_type": "code",
  465. "execution_count": 24,
  466. "metadata": {
  467. "collapsed": false
  468. },
  469. "outputs": [
  470. {
  471. "name": "stdout",
  472. "output_type": "stream",
  473. "text": [
  474. "2.421024373759207 <rebound.Particle object, m=0.001 x=-0.925974211129496 y=0.5620216440872584 z=0.0 vx=-0.46662537694473766 vy=-0.8244189370939644 vz=0.0> <rebound.Particle object, m=0.001 x=-0.7624398937112399 y=0.6767517889121272 z=0.0 vx=-0.6829352263194566 vy=-0.7322252231030555 vz=0.0>\n"
  475. ]
  476. }
  477. ],
  478. "source": [
  479. "sim.integrate(3)"
  480. ]
  481. },
  482. {
  483. "cell_type": "code",
  484. "execution_count": null,
  485. "metadata": {
  486. "collapsed": true
  487. },
  488. "outputs": [],
  489. "source": []
  490. }
  491. ],
  492. "metadata": {
  493. "kernelspec": {
  494. "display_name": "Python 3",
  495. "language": "python",
  496. "name": "python3"
  497. },
  498. "language_info": {
  499. "codemirror_mode": {
  500. "name": "ipython",
  501. "version": 3
  502. },
  503. "file_extension": ".py",
  504. "mimetype": "text/x-python",
  505. "name": "python",
  506. "nbconvert_exporter": "python",
  507. "pygments_lexer": "ipython3",
  508. "version": "3.5.2"
  509. }
  510. },
  511. "nbformat": 4,
  512. "nbformat_minor": 2
  513. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement