Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
37
Task/Draw-a-cuboid/MiniScript/draw-a-cuboid.mini
Normal file
37
Task/Draw-a-cuboid/MiniScript/draw-a-cuboid.mini
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import "mathUtil"
|
||||
scale = 20
|
||||
|
||||
img = file.loadImage("/sys/pics/shapes/SquareThin.png")
|
||||
clear; gfx.clear color.gray
|
||||
|
||||
// Rotate the given [x,y,z] point by some number of degrees
|
||||
// around the Y axis, then project to the screen.
|
||||
rotateAndProject = function(point3d, rotDegrees)
|
||||
radians = rotDegrees * pi/180
|
||||
cosAng = cos(radians); sinAng = sin(radians)
|
||||
// First, rotate around the Y axis in 3D space
|
||||
x = point3d[0] * cosAng - point3d[2] * sinAng
|
||||
y = point3d[1]
|
||||
z = point3d[0] * sinAng + point3d[2] * cosAng
|
||||
// Then, project this to the screen
|
||||
result = [480 + x * scale, 320 + y * scale]
|
||||
p = (80 - z) / 80 // (perspective factor)
|
||||
return mathUtil.lerp2d(result, [480,800], 1-p)
|
||||
end function
|
||||
|
||||
addFace = function(points3d, tint)
|
||||
sp = new Face
|
||||
sp.image = img
|
||||
corners = []
|
||||
for p in points3d
|
||||
corners.push rotateAndProject(p, -45)
|
||||
end for
|
||||
sp.setCorners corners
|
||||
sp.tint = tint
|
||||
display(4).sprites.push sp
|
||||
end function
|
||||
|
||||
w = 3; h = 2; d = 4
|
||||
addFace [[-w,-h,-d],[w,-h,-d],[w,h,-d],[-w,h,-d]], color.lime
|
||||
addFace [[w,-h,-d],[w,-h,d],[w,h,d],[w,h,-d]], color.aqua
|
||||
addFace [[-w,h,-d],[w,h,-d],[w,h,d],[-w,h,d]], color.pink
|
||||
Loading…
Add table
Add a link
Reference in a new issue