Code: Select all
;-------- http://ahkscript.org/boards/viewtopic.php?f=9&t=9308 ---
#SingleInstance, Force ; kill old instance
#NoTrayIcon ; don't show tray icon at start
#NoEnv ; don't check empty variables
f1=%a_scriptdir%\3D_Mesh.html
f2=%a_scriptdir%\3D_Mesh.js
ifnotexist,%f1%
gosub,a1
ifnotexist,%f2%
gosub,a2
;xxa=Shell.Explorer ;- Object doesn't support this property or method
xxa=Mozilla.Browser ;- OK
Menu, Tray, Icon, %A_WinDir%\System32\shell32.dll, 44
Menu, Tray, Icon ; show
Gui, -MinimizeBox
Gui, Add, ActiveX, w360 h170 E0x200 vIE, %xxa%
Gui, Show,, 3D Mesh
IE.Navigate(F1)
return
Esc::
GuiEscape:
GuiClose:
ExitApp
;------------------------------
a1:
e4x=
(
<html>
<body>
<canvas id="Cube" style="border:1px solid #d3d3d3;">
<script src="3D_Mesh.js"></script>
</body>
</html>
)
Fileappend,%e4x%,%f1%
return
;------------------------------
a2:
e5x=
(
//------------------------------------------------------------------------------
// 3D Mesh.js
// by wolf_II
//------------------------------------------------------------------------------
// draw two 3D meshes of a Rubik's Cube
// parameterized for size and order of the cube
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function draw_R(ctx, s, x, y) { // draw an angled line to the right and down
//------------------------------------------------------------------------------
// s = scaling factor / size
// start at the highest point (x, y)
//--------------------------------------------------------------------------
ctx.beginPath()
ctx.moveTo(x, y)
ctx.lineTo(x + 8 * s, y + 3 * s)
ctx.lineTo(x + 8 * s, y + 12 * s)
ctx.stroke()
}
//------------------------------------------------------------------------------
function draw_L(ctx, s, x, y) { // draw an angled line to the left and down
//------------------------------------------------------------------------------
// s = scaling factor / size
// start at the highest point (x, y)
//--------------------------------------------------------------------------
ctx.beginPath()
ctx.moveTo(x, y)
ctx.lineTo(x - 8 * s, y + 3 * s)
ctx.lineTo(x - 8 * s, y + 12 * s)
ctx.stroke()
}
//------------------------------------------------------------------------------
function draw_H(ctx, s, x, y) { // draw an angled line to connect horizontally
//------------------------------------------------------------------------------
// s = scaling factor / size
// start at the leftmost point (x, y)
//--------------------------------------------------------------------------
ctx.beginPath()
ctx.moveTo(x, y)
ctx.lineTo(x + 8 * s, y + 3 * s)
ctx.lineTo(x + 16 * s, y)
ctx.stroke()
}
//------------------------------------------------------------------------------
function draw_3Dmesh(ctx, s, d, n, x) { // draw a 3D mesh of a Rubik's Cube
//------------------------------------------------------------------------------
// s = scaling factor / size
// d = distance from edges
// n = order of cube, e.g. 3x3x3: n = 3
// x = x-coord of the highest point
//--------------------------------------------------------------------------
for (i = 0; i <= n; i++) {
if (n == 0) { // outlines only
m = 0; h = -12
} else { // n sub-divisions
m = i * s / n
h = i * 9 / n - 12
}
draw_R(ctx, s, x - 8 * m, d + m * 3)
draw_L(ctx, s, x + 8 * m, d + m * 3)
draw_H(ctx, s, x - 8 * s, d - h * s)
}
}
//------------------------------------------------------------------------------
function draw_2cubes(s, n) { // draw 2 cubes next to each other
//------------------------------------------------------------------------------
// s = scaling factor / size
// n = order of the cubes
//--------------------------------------------------------------------------
// distance from edges is hardcoded here to be equal to the scaling factor
// it is possible to have d as an additional parameter for this function
d = s
canvas = document.getElementById("Cube")
canvas.width = s * 36
canvas.height = s * 17
ctx = canvas.getContext("2d")
ctx.lineWidth = "2"
x = 8 * s + d // x-coord of the highest point
draw_3Dmesh(ctx, s, d, n, x)
draw_3Dmesh(ctx, s, d, n, 3 * x)
}
draw_2cubes(8, 3)
)
fileappend,%e5x%,%f2%
return
;------------------------------