[Godot] Line2D 선 그리기

Godot 2024. 2. 21. 18:02 |
반응형

간단한 선을 그려보자.

 

Line2D 노드 두 개와 스크립트를 추가한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using Godot;
using System.Collections.Generic;
 
public partial class Control : Node2D
{
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        DrawCircle();
        DrawPentagram();
    }
 
    // 원 그리기
    public async void DrawCircle()
    {
        Line2D line = GetNode<Line2D>("Line2D");
        //line.Closed = true;
        // Closed를 여기서 변경하면 원이 그려지는 방식이 달라진다.
        line.Width = 2;
        line.DefaultColor = Colors.Red;
        line.Position = new Vector2(200200);
 
        float radius = 100;
        float angle;
 
        for (int i = 0; i < 360; i++)
        {
            angle = Mathf.DegToRad(i);
            line.AddPoint(CalcCirclePoint(radius, angle));
            await ToSignal(GetTree().CreateTimer(0.01), SceneTreeTimer.SignalName.Timeout);
        }
 
        line.Closed = true;
    }
 
    // 원 포인트 계산
    public Vector2 CalcCirclePoint(float radius, float angle)
    {
        float x = Mathf.Cos(angle);
        float y = Mathf.Sin(angle);
 
        return new Vector2(x * radius, y * radius);
    }
 
    // 별 그리기
    public async void DrawPentagram()
    {
        Line2D line = GetNode<Line2D>("Line2D2");
        line.Width = 2;
        line.DefaultColor = Colors.Blue;
        line.Position = new Vector2(200200);
 
        List<Vector2> points = new List<Vector2>();
        points.Add(new Vector2(6080));
        points.Add(new Vector2(0-100));
        points.Add(new Vector2(-6080));
        points.Add(new Vector2(95-25));
        points.Add(new Vector2(-95-25));
        //points.Add(new Vector2(60, 80));
        // 마지막에 Closed 프로퍼티에 true를 대입하기 때문에 별의 시작점을 다시 추가할
        // 필요는 없다.
 
        for (int i = 0; i < points.Count; i++)
        {
            line.AddPoint(points[i]);
            await ToSignal(GetTree().CreateTimer(1), SceneTreeTimer.SignalName.Timeout);
        }
 
        line.Closed = true;
    }
}
 

 

위와 같이 코드를 작성한다.

 

 

※ 참고

Line2D

Custom drawing in 2D

 

반응형
Posted by J-sean
:
반응형

어셈블리 언어로 작성된 프로그램 실행 시 인수를 확인해 보자.

 

소스를 입력하고 빌드한다.

 

1
2
3
4
5
6
7
8
9
10
11
12
include masm32rt.inc
 
.data
    strTitle db "Command Line Arguments",0
    strMessage db 128 dup(?)
 
.code
start:
    invoke GetCL, 1, ADDR strMessage
    invoke MessageBox, 0, ADDR strMessage, ADDR strTitle, MB_OK
    invoke ExitProcess, 0
end start
 

 

GetCL 함수의 첫 번째 인수로 1을 주면 프로그램의 첫 번째 인수가 저장된다.

 

첫 번째 인수 'abcd'가 출력된다.

 

1
2
3
4
5
6
7
8
9
10
11
12
include masm32rt.inc
 
.data
    strTitle db "Command Line Arguments",0
    strMessage db 128 dup(?)
 
.code
start:
    invoke GetCL, 0, ADDR strMessage
    invoke MessageBox, 0, ADDR strMessage, ADDR strTitle, MB_OK
    invoke ExitProcess, 0
end start
 

 

GetCL 함수의 첫 번째 인수로 0을 주면 프로그램 파일명이 저장된다.

 

파일 이름 First.exe가 출력된다.

 

반응형
Posted by J-sean
:
반응형

'Open Command Line' opens a command line at the root of the project. Support for all consoles such as CMD, PowerShell, Bash, etc. Provides syntax highlighting, Intellisense and execution of .cmd and .bat files.


This extension adds a new command to the project context menu that will open a command prompt on the project's path. If the solution node is selected in Solution Explorer, then a console will open at the root of the .sln file.


Open Command LIne은 작업 중인 Visual Studio 프로젝트 폴더에서 바로 command prompt를 열 수 있게 해주는 extension 입니다.

CMD, PowerShell, Bash등을 지원합니다.


Run Tools - Extensions and Updates...


Search 'Open Command Line' on Online tab and click Download.


Installation starts when Visual Studio closes.


Close Visual Studio and click Modify on VSIX Installer.


Install it.


Click Close.




Right-click on Solution Explorer - Open Command Line - Default(cmd) (Shortcut: Alt + Space)


Command Prompt opens on the project's path.


Right-click on Solution Explorer - Open Command Line - Settings...


You can change settings.




반응형
Posted by J-sean
: