Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
105
Task/Draw-a-rotating-cube/Ada/draw-a-rotating-cube.adb
Normal file
105
Task/Draw-a-rotating-cube/Ada/draw-a-rotating-cube.adb
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
with Ada.Numerics.Elementary_Functions;
|
||||
|
||||
with SDL.Video.Windows.Makers;
|
||||
with SDL.Video.Renderers.Makers;
|
||||
with SDL.Events.Events;
|
||||
|
||||
procedure Rotating_Cube is
|
||||
|
||||
Width : constant := 500;
|
||||
Height : constant := 500;
|
||||
Offset : constant := 500.0 / 2.0;
|
||||
|
||||
Window : SDL.Video.Windows.Window;
|
||||
Renderer : SDL.Video.Renderers.Renderer;
|
||||
Event : SDL.Events.Events.Events;
|
||||
Quit : Boolean := False;
|
||||
|
||||
type Node_Id is new Natural;
|
||||
type Point_3D is record X, Y, Z : Float; end record;
|
||||
type Edge_Type is record A, B : Node_Id; end record;
|
||||
|
||||
Nodes : array (Node_Id range <>) of Point_3D :=
|
||||
((-100.0, -100.0, -100.0), (-100.0, -100.0, 100.0), (-100.0, 100.0, -100.0),
|
||||
(-100.0, 100.0, 100.0), (100.0, -100.0, -100.0), (100.0, -100.0, 100.0),
|
||||
(100.0, 100.0, -100.0), (100.0, 100.0, 100.0));
|
||||
Edges : constant array (Positive range <>) of Edge_Type :=
|
||||
((0, 1), (1, 3), (3, 2), (2, 0), (4, 5), (5, 7),
|
||||
(7, 6), (6, 4), (0, 4), (1, 5), (2, 6), (3, 7));
|
||||
|
||||
use Ada.Numerics.Elementary_Functions;
|
||||
|
||||
procedure Rotate_Cube (AngleX, AngleY : in Float) is
|
||||
SinX : constant Float := Sin (AngleX);
|
||||
CosX : constant Float := Cos (AngleX);
|
||||
SinY : constant Float := Sin (AngleY);
|
||||
CosY : constant Float := Cos (AngleY);
|
||||
X, Y, Z : Float;
|
||||
begin
|
||||
for Node of Nodes loop
|
||||
X := Node.X;
|
||||
Y := Node.Y;
|
||||
Z := Node.Z;
|
||||
Node.X := X * CosX - Z * SinX;
|
||||
Node.Z := Z * CosX + X * SinX;
|
||||
Z := Node.Z;
|
||||
Node.Y := Y * CosY - Z * SinY;
|
||||
Node.Z := Z * CosY + Y * SinY;
|
||||
end loop;
|
||||
end Rotate_Cube;
|
||||
|
||||
function Poll_Quit return Boolean is
|
||||
use type SDL.Events.Event_Types;
|
||||
begin
|
||||
while SDL.Events.Events.Poll (Event) loop
|
||||
if Event.Common.Event_Type = SDL.Events.Quit then
|
||||
return True;
|
||||
end if;
|
||||
end loop;
|
||||
return False;
|
||||
end Poll_Quit;
|
||||
|
||||
procedure Draw_Cube (Quit : out Boolean) is
|
||||
use SDL.C;
|
||||
Pi : constant := Ada.Numerics.Pi;
|
||||
Xy1, Xy2 : Point_3D;
|
||||
begin
|
||||
Rotate_Cube (Pi / 4.0, Arctan (Sqrt (2.0)));
|
||||
for Frame in 0 .. 359 loop
|
||||
Renderer.Set_Draw_Colour ((0, 0, 0, 255));
|
||||
Renderer.Fill (Rectangle => (0, 0, Width, Height));
|
||||
|
||||
Renderer.Set_Draw_Colour ((0, 220, 0, 255));
|
||||
for Edge of Edges loop
|
||||
Xy1 := Nodes (Edge.A);
|
||||
Xy2 := Nodes (Edge.B);
|
||||
Renderer.Draw (Line => ((int (Xy1.X + Offset), int (Xy1.Y + Offset)),
|
||||
(int (Xy2.X + Offset), int (Xy2.Y + Offset))));
|
||||
end loop;
|
||||
Rotate_Cube (Pi / 180.0, 0.0);
|
||||
Window.Update_Surface;
|
||||
Quit := Poll_Quit;
|
||||
exit when Quit;
|
||||
delay 0.020;
|
||||
end loop;
|
||||
end Draw_Cube;
|
||||
|
||||
begin
|
||||
if not SDL.Initialise (Flags => SDL.Enable_Screen) then
|
||||
return;
|
||||
end if;
|
||||
|
||||
SDL.Video.Windows.Makers.Create (Win => Window,
|
||||
Title => "Rotating cube",
|
||||
Position => SDL.Natural_Coordinates'(X => 10, Y => 10),
|
||||
Size => SDL.Positive_Sizes'(Width, Height),
|
||||
Flags => 0);
|
||||
SDL.Video.Renderers.Makers.Create (Renderer, Window.Get_Surface);
|
||||
|
||||
while not Quit loop
|
||||
Draw_Cube (Quit);
|
||||
end loop;
|
||||
|
||||
Window.Finalize;
|
||||
SDL.Finalise;
|
||||
end Rotating_Cube;
|
||||
14
Task/Draw-a-rotating-cube/Python/draw-a-rotating-cube-2.py
Normal file
14
Task/Draw-a-rotating-cube/Python/draw-a-rotating-cube-2.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import bpy
|
||||
import math
|
||||
bpy.context.preferences.edit.keyframe_new_interpolation_type="LINEAR"
|
||||
bpy.ops.object.select_all(action="SELECT")
|
||||
bpy.ops.object.delete()
|
||||
bpy.ops.mesh.primitive_cube_add()
|
||||
bpy.context.active_object.name="spinningcube"
|
||||
spinningcube=bpy.data.objects["spinningcube"]
|
||||
spinningcube.rotation_euler=(math.radians(45),math.radians(35.264),math.radians(0))
|
||||
spinningcube.keyframe_insert(data_path="rotation_euler",frame=1)
|
||||
spinningcube.rotation_euler=(math.radians(45),math.radians(35.264),math.radians(2700))
|
||||
spinningcube.keyframe_insert(data_path="rotation_euler",frame=250)
|
||||
bpy.context.scene.frame_set(1)
|
||||
bpy.ops.screen.animation_play()
|
||||
122
Task/Draw-a-rotating-cube/V-(Vlang)/draw-a-rotating-cube.v
Normal file
122
Task/Draw-a-rotating-cube/V-(Vlang)/draw-a-rotating-cube.v
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
import gg
|
||||
import gx
|
||||
import math
|
||||
|
||||
struct RotatingCube {
|
||||
mut:
|
||||
width int
|
||||
height int
|
||||
fore gx.Color
|
||||
nodes [][]f64
|
||||
edges [][]int
|
||||
scale_f f64
|
||||
}
|
||||
|
||||
fn new_rotating_cube(width int, height int) RotatingCube {
|
||||
mut nodes := [
|
||||
[f64(-1.0), -1, -1],
|
||||
[f64(-1.0), -1, 1],
|
||||
[f64(-1.0), 1, -1],
|
||||
[f64(-1.0), 1, 1],
|
||||
[f64(1.0), -1, -1],
|
||||
[f64(1.0), -1, 1],
|
||||
[f64(1.0), 1, -1],
|
||||
[f64(1.0), 1, 1],
|
||||
]
|
||||
mut edges := [
|
||||
[0, 1],
|
||||
[1, 3],
|
||||
[3, 2],
|
||||
[2, 0],
|
||||
[4, 5],
|
||||
[5, 7],
|
||||
[7, 6],
|
||||
[6, 4],
|
||||
[0, 4],
|
||||
[1, 5],
|
||||
[2, 6],
|
||||
[3, 7],
|
||||
]
|
||||
mut cube := RotatingCube{
|
||||
width: width
|
||||
height: height
|
||||
fore: gx.blue
|
||||
nodes: nodes
|
||||
edges: edges
|
||||
scale_f: 100.0
|
||||
}
|
||||
cube.scale(cube.scale_f)
|
||||
cube.rotate_cube(math.pi / 4, math.sqrt(math.atan(2.0)))
|
||||
return cube
|
||||
}
|
||||
|
||||
fn (mut rc RotatingCube) scale(s f64) {
|
||||
for i in 0 .. rc.nodes.len {
|
||||
for j in 0 .. 3 {
|
||||
rc.nodes[i][j] = rc.nodes[i][j] * s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut rc RotatingCube) rotate_cube(angle_x f64, angle_y f64) {
|
||||
sin_x := math.sin(angle_x)
|
||||
cos_x := math.cos(angle_x)
|
||||
sin_y := math.sin(angle_y)
|
||||
cos_y := math.cos(angle_y)
|
||||
for i in 0 .. rc.nodes.len {
|
||||
x := rc.nodes[i][0]
|
||||
y := rc.nodes[i][1]
|
||||
z := rc.nodes[i][2]
|
||||
rc.nodes[i][0] = x * cos_x - z * sin_x
|
||||
rc.nodes[i][2] = z * cos_x + x * sin_x
|
||||
z_new := rc.nodes[i][2]
|
||||
rc.nodes[i][1] = y * cos_y - z_new * sin_y
|
||||
rc.nodes[i][2] = z_new * cos_y + y * sin_y
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut rc RotatingCube) draw_cube(mut ctx gg.Context) {
|
||||
ctx.begin()
|
||||
cx := f32(rc.width / 2)
|
||||
cy := f32(rc.height / 2)
|
||||
for edge in rc.edges {
|
||||
n1 := rc.nodes[edge[0]]
|
||||
n2 := rc.nodes[edge[1]]
|
||||
x1 := f32(n1[0]) + cx
|
||||
y1 := f32(n1[1]) + cy
|
||||
x2 := f32(n2[0]) + cx
|
||||
y2 := f32(n2[1]) + cy
|
||||
ctx.draw_line(x1, y1, x2, y2, rc.fore)
|
||||
}
|
||||
for node in rc.nodes {
|
||||
x := f32(node[0]) + cx - 4
|
||||
y := f32(node[1]) + cy - 4
|
||||
ctx.draw_rect_filled(x, y, 8, 8, rc.fore)
|
||||
}
|
||||
ctx.end()
|
||||
}
|
||||
|
||||
fn (mut rc RotatingCube) update() {
|
||||
rc.rotate_cube(math.pi / 180, 0)
|
||||
}
|
||||
|
||||
fn frame(mut cube RotatingCube) {
|
||||
mut ctx := gg.Context{}
|
||||
cube.update()
|
||||
cube.draw_cube(mut ctx)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
width := 640
|
||||
height := 640
|
||||
mut cube := new_rotating_cube(width, height)
|
||||
mut context := gg.new_context(
|
||||
width: width
|
||||
height: height
|
||||
window_title: "Rotating cube"
|
||||
bg_color: gx.white
|
||||
frame_fn: frame
|
||||
user_data: &cube
|
||||
)
|
||||
context.run()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue