Skip to content

Commit f90158b

Browse files
committed
misc updates
1 parent 10cd20d commit f90158b

20 files changed

+79
-46
lines changed

Project.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name = "Thebes"
22
uuid = "8b424ff8-82f5-59a4-86a6-de3761897198"
33
authors = ["cormullion <[email protected]>"]
4-
version = "0.1.0"
4+
version = "0.2.0"
55

66
[deps]
77
Luxor = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
88
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
9+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
910

1011
[extras]
1112
Luxor = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
@@ -18,5 +19,5 @@ test = ["Test", "Random", "Luxor"]
1819

1920
[compat]
2021
julia = "1"
21-
Luxor = "2"
22+
Luxor = "1, 2"
2223
Colors = "0.7, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13, 0.14"

docs/src/assets/logo.svg

+1-1
Loading

docs/src/objects.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ object = make(Cube, "cube")
256256
setscale!(object, 100, 100, 100)
257257
258258
# draw as is
259-
setposition!(object, Point3D(0, -200, 0))
259+
moveby!(object, Point3D(0, -200, 0))
260260
pin(object, gfunction = mygfunction)
261261
262262
# draw with sorted faces
263-
setposition!(object, Point3D(0, 400, 0))
263+
moveby!(object, Point3D(0, 400, 0))
264264
sortfaces!(object, eyepoint=eyepoint())
265265
pin(object, gfunction = mygfunction)
266266

docs/src/tools.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ rotateby
127127
You can change the position and scale of things:
128128

129129
```@docs
130-
setposition!
131-
setposition
130+
moveby!
131+
moveby
132132
setscale!
133133
```
134134

examples/animation-example.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function frame(scene, framenumber)
2323
n = x * y * z
2424
object = make(tetrahedron)
2525
setscale!(object, 10, 10, 10)
26-
setposition!(object, x * 25, y * 25, z * 25)
26+
moveby!(object, x * 25, y * 25, z * 25)
2727
d = distance(object.vertices[end], Point3D(0, 0, 0))
2828
if d < 1200
2929
pin(object, gfunction=mygfunction)

examples/balls.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ setopacity(1)
1818
for i in -20:10:20, j in -20:10:20, z in -20:10:20
1919
object = make(sphere2)
2020
setscale!(object, 50, 50, 50)
21-
setposition!(object, i * 15, j * 15, z * 15)
21+
moveby!(object, i * 15, j * 15, z * 15)
2222
d = distance(object.vertices[1], Point3D(0, 0, 0))
2323
if d < 300
2424
pin(object)

examples/drawevenmoreobjects.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function main()
4040
scalefactor = distance(extrema(object.vertices)...)
4141

4242
loc = Point3D(x, y, 0)
43-
setposition!(object, loc)
43+
moveby!(object, loc)
4444

4545
setscale!(object, 1/scalefactor * K, 1/scalefactor * K, 1/scalefactor * K)
4646
randomhue()

examples/rotating-geodesic.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function drawgeodesic(object, cpos, cscale, rotx, roty, rotz, eased)
1717
eyepoint(Point3D(1200, 1200, 200))
1818

1919
c = setscale!(object, cscale.x, cscale.y, cscale.z)
20-
setposition!(c, cpos)
20+
moveby!(c, cpos)
2121
theta = rescale(eased, 0, 1, 0, 2pi)
2222
rotateby!(c, Point3D(0, 0, 0), theta, theta, theta)
2323
pin(c, gfunction= mygfunction)

examples/simple-objects.jl

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ function mygfunction(vertices, faces, labels; action=:fill)
44
if !isempty(faces)
55
@layer begin
66
for (n, p) in enumerate(faces)
7-
x = mod1(n, length(cols))
8-
c = cols[mod1(labels[x], length(cols))]
9-
107
@layer begin
118
setopacity(0.5)
12-
sethue(c)
9+
randomhue()
1310
poly(p, action)
1411
end
1512

@@ -32,8 +29,6 @@ end
3229

3330
#object = make(Cube, "Cube")
3431
#object = make(Tetrahedron, "Tetrahedron")
35-
#object = make(AxesWire, "AxesWire")
36-
#object = make(Carpet, "Carpet")
3732
object = make(Pyramid, "Pyramid")
3833

3934
setscale!(object, 100, 100, 100)

examples/simple-pin.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ end
7575
for x in -200:40:200
7676
for y in -200:40:200
7777
randomhue()
78-
pin(setposition!(15makecube(), Point3D(x, y, 0)))
78+
pin(moveby!(15makecube(), Point3D(x, y, 0)))
7979
end
8080
end
8181

src/Object.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ function pin(m::Array{Object, 1};
191191
end
192192

193193
"""
194-
setposition!(m::Object, x, y, z)
195-
setposition!(m::Object, pt::Point3D)
194+
moveby!(m::Object, x, y, z)
195+
moveby!(m::Object, pt::Point3D)
196196
197197
Set the position of object to Point3D(x, y, z).
198198
"""
199-
function setposition!(m::Object, x, y, z)
199+
function moveby!(m::Object, x, y, z)
200200
for n in 1:length(m.vertices)
201201
nv = m.vertices[n]
202202
m.vertices[n] = Point3D(nv.x + x, nv.y + y, nv.z + z)
@@ -205,18 +205,18 @@ function setposition!(m::Object, x, y, z)
205205
end
206206

207207
"""
208-
setposition(m::Object, x, y, z)
209-
setposition(m::Object, pt::Point3D)
208+
moveby(m::Object, x, y, z)
209+
moveby(m::Object, pt::Point3D)
210210
211211
Set the position of a copy of the object to Point3D(x, y, z).
212212
"""
213-
function setposition(m::Object, x, y, z)
213+
function moveby(m::Object, x, y, z)
214214
mcopy = deepcopy(m)
215-
return setposition!(mcopy, x, y, z)
215+
return moveby!(mcopy, x, y, z)
216216
end
217217

218-
setposition(m::Object, pt::Point3D) = setposition(m::Object, pt.x, pt.y, pt.z)
219-
setposition!(m::Object, pt::Point3D) = setposition!(m::Object, pt.x, pt.y, pt.z)
218+
moveby(m::Object, pt::Point3D) = moveby(m::Object, pt.x, pt.y, pt.z)
219+
moveby!(m::Object, pt::Point3D) = moveby!(m::Object, pt.x, pt.y, pt.z)
220220

221221
"""
222222
setscale!(m::Object, x, y, z)

src/Point3D.jl

+43-6
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,13 @@ function rotateZ(pt3D::Point3D, rad)
195195
return Point3D(x, y, pt3D.z)
196196
end
197197

198+
# rotate around axes
199+
198200
"""
199201
rotateby(pt::Point3D, angleX, angleY, angleZ)
202+
rotateby(ptlist::Array{Point3D, 1}, angleX, angleY, angleZ)
200203
201-
Return a new point resulting from rotating the specified point
204+
Return a new point/list of points resulting from rotating
202205
around the x, y, and z axes by angleX, angleY, angleZ.
203206
"""
204207
function rotateby(pt::Point3D, angleX, angleY, angleZ)
@@ -208,10 +211,30 @@ function rotateby(pt::Point3D, angleX, angleY, angleZ)
208211
return v
209212
end
210213

214+
function rotateby(ptlist::Array{Point3D, 1}, angleX, angleY, angleZ)
215+
return rotateby.(ptlist, angleX, angleY, angleZ)
216+
end
217+
218+
"""
219+
rotateby!(ptlist::Array{Point3D, 1}, angleX, angleY, angleZ)
220+
221+
Return the list of points with each one rotated
222+
around the x, y, and z axes by angleX, angleY, angleZ.
223+
"""
224+
function rotateby!(ptlist::Array{Point3D, 1}, angleX, angleY, angleZ)
225+
for i in eachindex(ptlist)
226+
ptlist[i] = rotateby(ptlist[i], angleX, angleY, angleZ)
227+
end
228+
return ptlist
229+
end
230+
231+
# rotate around point
232+
211233
"""
212234
rotateby(newpt::Point3D, existingpt::Point3D, angleX, angleY, angleZ)
213235
214-
Return a new point resulting from rotating the point by angleX, angleY, angleZ around another point.
236+
Return a new point/list resulting from rotating each point
237+
by angleX, angleY, angleZ around another point.
215238
"""
216239
function rotateby(newpt::Point3D, existingpt::Point3D, angleX, angleY, angleZ)
217240
v = newpt - existingpt
@@ -222,15 +245,29 @@ function rotateby(newpt::Point3D, existingpt::Point3D, angleX, angleY, angleZ)
222245
end
223246

224247
"""
225-
setposition!(ptlist::Point3D, pt::Point3D)
248+
rotateby!(ptlist::Point3D, existingpt::Point3D, angleX, angleY, angleZ)
249+
250+
Rotate each point in the list by angleX, angleY, angleZ around another point.
251+
"""
252+
function rotateby!(ptlist::Array{Point3D, 1}, existingpt::Point3D, angleX, angleY, angleZ)
253+
for i in eachindex(ptlist)
254+
ptlist[i] = rotateby(ptlist[i], existingpt, angleX, angleY, angleZ)
255+
end
256+
return ptlist
257+
end
226258

227-
Move points by a vector..
259+
"""
260+
moveby!(ptlist::Point3D, x, y, z)
261+
moveby!(ptlist::Point3D, pt::Point3D)
228262
263+
Move all points in the list by a vector.
229264
"""
230-
function setposition!(ptlist::Array{Point3D, 1}, pt::Point3D)
231-
return (+).(ptlist, pt)
265+
function moveby!(ptlist::Array{Point3D, 1}, pt::Point3D)
266+
return ptlist .+= pt
232267
end
233268

269+
moveby!(ptlist::Array{Point3D, 1}, x, y, z) = moveby!(ptlist, Point3D(x, y, z))
270+
234271
"""
235272
surfacenormal(ptlist)
236273

src/Thebes.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export project, Projection, newprojection,
2626

2727
rotateX, rotateY, rotateZ, rotateby!, rotateby,
2828

29-
setposition!, setposition,
29+
moveby!, moveby,
3030

3131
objecttopoly,
3232
setscale!, sortfaces!,

test/test-1.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function main()
1919
axes3D(150)
2020
object = make(Cube)
2121
setscale!(object, 25, 25, 25)
22-
setposition!(object, 0, 0, 0)
22+
moveby!(object, 0, 0, 0)
2323
rotateby!(object, 0, n/5, 0)
2424
sortfaces!(object)
2525
pin(object, gfunction=mygfunction)

test/test-2.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ function main()
4747
setscale!(khafre, 21.6/2, 21.6/2, 14.3)
4848
setscale!(menkaure, 10.9/2, 10.9/2, 6.6)
4949

50-
setposition!(khufu, 30, 30, 0)
51-
setposition!(khafre, -0, -0, 0)
52-
setposition!(menkaure, -30, -30, 0)
50+
moveby!(khufu, 30, 30, 0)
51+
moveby!(khafre, -0, -0, 0)
52+
moveby!(menkaure, -30, -30, 0)
5353

5454
# needs depth sorting of faces
5555
sortfaces!.(pyramids, eyepoint=eyepoint())

test/test-3.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function main()
2222
objects = [object]
2323
s = rescale(k, 5, 20, 10, 20)
2424
setscale!.(objects, s, s, s)
25-
setposition!.(objects, rescale(k, 1, 20, 50, 400), 1, 0)
25+
moveby!.(objects, rescale(k, 1, 20, 50, 400), 1, 0)
2626
a = rescale(i, 1, 20, 0, 2pi)
2727
rotateby!.(objects, 0, 0, a)
2828
sortfaces!(objects, eyepoint = eyepoint)

test/test-4.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Thebes, Luxor
22

3-
include(string(@__FILE__, "../../../data/moreobjects.jl"))
3+
include(dirname(pathof(Thebes)) * "/../data/moreobjects.jl")
44

55
moreobjects = [boxcube, boxtorus, concave, cone, crossshape, cube,
66
cuboctahedron, dodecahedron , geodesic, # helix2, icosahedron,
@@ -40,7 +40,7 @@ function main()
4040
object = make(moreobjects[rand(1:length(moreobjects))])
4141

4242
setscale!(object, 30, 30, 30)
43-
setposition!(object, 1 * rand(), 1 * rand(), 10 * rand())
43+
moveby!(object, 1 * rand(), 1 * rand(), 10 * rand())
4444
rotateby!(object, #= object.vertices[1],=# 2pi * rand(), 2pi * rand(), 2pi * rand())
4545
sortfaces!(object)
4646
pin(object, gfunction= anothergfunction)

test/test-5.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Luxor, Thebes
22

3-
include(string(@__FILE__, "../../../data/moreobjects.jl"))
3+
include(dirname(pathof(Thebes)) * "/../data/moreobjects.jl")
44

55
moreobjects = [boxcube, boxtorus, concave, cone, crossshape, cube,
66
cuboctahedron, dodecahedron , geodesic, # helix2, icosahedron,

test/test-6.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Thebes
22

3-
include(string(@__FILE__, "../../../data/moreobjects.jl"))
3+
include(dirname(pathof(Thebes)) * "/../data/moreobjects.jl")
44

55
moreobjects = [boxcube, boxtorus, concave, cone, crossshape, cube, cuboctahedron, dodecahedron , geodesic, helix2,
66
icosahedron, icosidodecahedron, octahedron, octtorus, rhombicosidodecahedron,

test/test-7.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Thebes, Luxor
22

3-
include(string(@__FILE__, "../../../data/moreobjects.jl"))
3+
include(dirname(pathof(Thebes)) * "/../data/moreobjects.jl")
44

55
platonics = [:boxtorus, :concave, :cone, :crossshape, :cube, :cuboctahedron, :dodecahedron , :geodesic, :helix2,
66
:icosahedron, :icosidodecahedron, :octahedron, :octtorus, :rhombicosidodecahedron,
@@ -35,12 +35,12 @@ function main()
3535
for y in -100:50:100
3636
object = make(moreobjects[2])
3737
setscale!(object, 10, 10, 10)
38-
setposition!(object, x, y, 50rand())
38+
moveby!(object, x, y, 50rand())
3939
rotateby!(object, object.vertices[1], rand(), rand(), rand())
4040
pin(object, gfunction = anothergfunction)
4141

4242
# dark version
43-
setposition!(object, 0, 0, -object.vertices[1].z)
43+
moveby!(object, 0, 0, -object.vertices[1].z)
4444
setscale!(object, 1, 1, 0)
4545
pin(object, gfunction = anothergfunction)
4646
end

0 commit comments

Comments
 (0)