ユーザ用ツール

サイト用ツール


cgfs:draw_lines

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

次のリビジョン
前のリビジョン
cgfs:draw_lines [2024/06/11 11:12] – 作成 freemikancgfs:draw_lines [2025/11/19 15:11] (現在) – using std::swap; freemikan
行 1: 行 1:
-<codeprism lang=cpp el=true css=full>+====== DrawPixelだけで三角形を描く (1) 線を描く ====== 
 + 
 +{{:cgfs:lines-000.png?400|}} 
 + 
 +[[https://wiki.freemikan.com/doku.php?id=cgfs:vmath|vmath.h]] 
 + 
 +<file cpp>
 #include <raylib.h> #include <raylib.h>
  
行 35: 行 41:
  
 void DrawLine(vec2 const &p0, vec2 const &p1, Color const &color) { void DrawLine(vec2 const &p0, vec2 const &p1, Color const &color) {
 + using std::swap;
 +
     auto x0 = p0.x;     auto x0 = p0.x;
     auto y0 = p0.y;     auto y0 = p0.y;
行 42: 行 50:
     if (std::abs(x1 - x0) > std::abs(y1 - y0)) {     if (std::abs(x1 - x0) > std::abs(y1 - y0)) {
         if (x0 > x1) {         if (x0 > x1) {
-            std::swap(x0, x1); +            swap(x0, x1); 
-            std::swap(y0, y1);+            swap(y0, y1);
         }         }
         auto i0 = static_cast<int>(std::floor(x0));         auto i0 = static_cast<int>(std::floor(x0));
行 56: 行 64:
     } else {     } else {
         if (y0 > y1) {         if (y0 > y1) {
-            std::swap(y0, y1); +            swap(y0, y1); 
-            std::swap(x0, x1);+            swap(x0, x1);
         }         }
  
行 73: 行 81:
  
 int main() { int main() {
-    InitWindow(Cw, Ch, "Draw Lines");+    InitWindow(Cw, Ch, "Shaded Triangles");
  
     vec2 p0{0, 0};     vec2 p0{0, 0};
行 86: 行 94:
  
         ClearBackground(RAYWHITE);         ClearBackground(RAYWHITE);
 +
         DrawLine(p0, p1, GREEN);         DrawLine(p0, p1, GREEN);
         DrawLine(p2, p3, BLUE);         DrawLine(p2, p3, BLUE);
行 93: 行 102:
     }     }
 } }
-</codeprism>+</file>
  
cgfs/draw_lines.1718071923.txt.gz · 最終更新: by freemikan

特に明示されていない限り、本Wikiの内容は次のライセンスに従います: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki