fork download
  1.  
  2. // Basic animation variables
  3. static float time = 0.0f;
  4. static float trainPosition = 0.0f;
  5. const float TRAIN_SPEED = 150.0f;
  6. static float moonGlow = 0.0f;
  7. static float moonY = 0.0f;
  8.  
  9. void RenderScene(); {
  10. time += ImGui::GetIO().DeltaTime;
  11. trainPosition += TRAIN_SPEED * ImGui::GetIO().DeltaTime;
  12.  
  13. // Update moon animations
  14. moonGlow = 0.5f + 0.5f * sinf(time * 0.5f);
  15. moonY = 5.0f * sinf(time * 0.2f);
  16.  
  17. // Reset train position
  18. if (trainPosition > ImGui::GetWindowSize().x + 400.0f) {
  19. trainPosition = -800.0f; // Increased negative value to account for bogies
  20. }
  21.  
  22. ImDrawList* pDrawList = ImGui::GetWindowDrawList();
  23. ImVec2 windowPos = ImGui::GetWindowPos();
  24. ImVec2 windowSize = ImGui::GetWindowSize();
  25.  
  26. // Draw moon
  27. float moonRadius = 40.0f;
  28. ImVec2 moonCenter(
  29. windowPos.x + windowSize.x * 0.8f,
  30. windowPos.y + windowSize.y * 0.2f + moonY
  31. );
  32.  
  33. // Moon glow effect
  34. for (float r = moonRadius + 30.0f; r >= moonRadius; r -= 1.0f) {
  35. float alpha = moonGlow * (1.0f - (r - moonRadius) / 30.0f) * 0.3f;
  36. pDrawList->AddCircleFilled(
  37. moonCenter,
  38. r,
  39. ImGui::GetColorU32(ImVec4(0.9f, 0.9f, 0.7f, alpha))
  40. );
  41. }
  42.  
  43. // Main moon
  44. pDrawList->AddCircleFilled(
  45. moonCenter,
  46. moonRadius,
  47. ImGui::GetColorU32(ImVec4(0.95f, 0.95f, 0.8f, 1.0f))
  48. );
  49.  
  50. // Moon craters
  51. const ImVec2 craters[] = {
  52. ImVec2(-15, -10), ImVec2(10, -15), ImVec2(5, 5),
  53. ImVec2(-5, 15), ImVec2(15, 10), ImVec2(-20, 5)
  54. };
  55.  
  56. for (const auto& crater : craters) {
  57. pDrawList->AddCircleFilled(
  58. ImVec2(moonCenter.x + crater.x, moonCenter.y + crater.y),
  59. 4.0f,
  60. ImGui::GetColorU32(ImVec4(0.85f, 0.85f, 0.7f, 1.0f))
  61. );
  62. }
  63.  
  64. // Add stars around moon
  65. const int NUM_STARS = 50;
  66. static std::vector<ImVec2> stars;
  67. static bool starsInitialized = false;
  68.  
  69. // Initialize star positions once
  70. if (!starsInitialized) {
  71. stars.clear();
  72. for (int i = 0; i < NUM_STARS; i++) {
  73. float angle = (float)i / NUM_STARS * 2 * 3.14159f;
  74. float distance = 100.0f + rand() % 200;
  75. stars.push_back(ImVec2(
  76. moonCenter.x + cosf(angle) * distance,
  77. moonCenter.y + sinf(angle) * distance
  78. ));
  79. }
  80. starsInitialized = true;
  81. }
  82.  
  83. // Draw stars with twinkling effect
  84. for (size_t i = 0; i < stars.size(); i++) {
  85. float starGlow = 0.3f + 0.7f * sinf(time * 2.0f + i * 1.5f);
  86. float starSize = 2.0f + sinf(time * 3.0f + i) * 0.5f;
  87.  
  88. pDrawList->AddCircleFilled(
  89. stars[i],
  90. starSize,
  91. ImGui::GetColorU32(ImVec4(1.0f, 1.0f, 1.0f, starGlow))
  92. );
  93. }
  94.  
  95. // Draw railway tracks
  96. float trackY = windowPos.y + windowSize.y * 0.7f;
  97.  
  98. // Draw track base
  99. pDrawList->AddRectFilled(
  100. ImVec2(windowPos.x, trackY - 5),
  101. ImVec2(windowPos.x + windowSize.x, trackY + 15),
  102. ImGui::GetColorU32(ImVec4(0.3f, 0.3f, 0.3f, 1.0f))
  103. );
  104.  
  105. // Draw railroad ties
  106. float tieSpacing = 50.0f;
  107. float tieOffset = fmodf(time * TRAIN_SPEED, tieSpacing);
  108.  
  109. for (float x = -tieSpacing + tieOffset; x < windowSize.x; x += tieSpacing) {
  110. pDrawList->AddRectFilled(
  111. ImVec2(windowPos.x + x, trackY - 10),
  112. ImVec2(windowPos.x + x + 30, trackY + 20),
  113. ImGui::GetColorU32(ImVec4(0.4f, 0.2f, 0.1f, 1.0f))
  114. );
  115. }
  116.  
  117. // Draw rails
  118. pDrawList->AddRectFilled(
  119. ImVec2(windowPos.x, trackY - 2),
  120. ImVec2(windowPos.x + windowSize.x, trackY),
  121. ImGui::GetColorU32(ImVec4(0.7f, 0.7f, 0.7f, 1.0f))
  122. );
  123.  
  124. pDrawList->AddRectFilled(
  125. ImVec2(windowPos.x, trackY + 10),
  126. ImVec2(windowPos.x + windowSize.x, trackY + 12),
  127. ImGui::GetColorU32(ImVec4(0.7f, 0.7f, 0.7f, 1.0f))
  128. );
  129.  
  130. // Draw Train
  131. ImVec2 trainPos(windowPos.x + trainPosition, trackY - 60);
  132.  
  133.  
  134. // Add train bogies (compartments) BEHIND the locomotive
  135. const int NUM_BOGIES = 3;
  136. float bogieWidth = 180.0f;
  137. float bogieGap = 20.0f;
  138. float bogieStartX = trainPos.x - bogieWidth - bogieGap;
  139.  
  140. for (int i = 0; i < NUM_BOGIES; i++) {
  141. float bogieX = bogieStartX - (bogieWidth + bogieGap) * i;
  142.  
  143. // Bogie body
  144. pDrawList->AddRectFilled(
  145. ImVec2(bogieX, trainPos.y),
  146. ImVec2(bogieX + bogieWidth, trainPos.y + 60),
  147. ImGui::GetColorU32(ImVec4(0.7f, 0.2f, 0.2f, 1.0f))
  148. );
  149.  
  150. // Glowing windows
  151. float windowGlow = 0.5f + 0.5f * sinf(time * 2.0f + i * 1.5f);
  152. for (float wx = bogieX + 20; wx < bogieX + bogieWidth - 20; wx += 40) {
  153. // Window glow effect
  154. for (float r = 20.0f; r >= 0.0f; r -= 1.0f) {
  155. float alpha = windowGlow * (1.0f - r / 20.0f) * 0.3f;
  156. pDrawList->AddRectFilled(
  157. ImVec2(wx - r, trainPos.y + 10 - r),
  158. ImVec2(wx + 30 + r, trainPos.y + 40 + r),
  159. ImGui::GetColorU32(ImVec4(1.0f, 1.0f, 0.8f, alpha))
  160. );
  161. }
  162.  
  163. // Actual window
  164. pDrawList->AddRectFilled(
  165. ImVec2(wx, trainPos.y + 10),
  166. ImVec2(wx + 30, trainPos.y + 40),
  167. ImGui::GetColorU32(ImVec4(1.0f, 1.0f, 0.8f, 1.0f))
  168. );
  169. }
  170.  
  171. // Wheels for each bogie
  172. float wheelRadius = 15.0f;
  173. float wheelSpacing = 50.0f;
  174.  
  175. for (float x = bogieX + 30; x < bogieX + bogieWidth - 30; x += wheelSpacing) {
  176. pDrawList->AddCircleFilled(
  177. ImVec2(x, trainPos.y + 55),
  178. wheelRadius,
  179. ImGui::GetColorU32(ImVec4(0.1f, 0.1f, 0.1f, 1.0f))
  180. );
  181. }
  182. }
  183.  
  184. // Locomotive body
  185. pDrawList->AddRectFilled(
  186. ImVec2(trainPos.x, trainPos.y),
  187. ImVec2(trainPos.x + 200, trainPos.y + 60),
  188. ImGui::GetColorU32(ImVec4(0.2f, 0.3f, 0.8f, 1.0f))
  189. );
  190.  
  191. // Locomotive front
  192. pDrawList->AddRectFilled(
  193. ImVec2(trainPos.x + 200, trainPos.y + 10),
  194. ImVec2(trainPos.x + 240, trainPos.y + 60),
  195. ImGui::GetColorU32(ImVec4(0.2f, 0.2f, 0.7f, 1.0f))
  196. );
  197.  
  198. // Cabin
  199. pDrawList->AddRectFilled(
  200. ImVec2(trainPos.x + 140, trainPos.y - 30),
  201. ImVec2(trainPos.x + 200, trainPos.y),
  202. ImGui::GetColorU32(ImVec4(0.2f, 0.2f, 0.7f, 1.0f))
  203. );
  204.  
  205. // Windows
  206. for (float x = trainPos.x + 20; x < trainPos.x + 120; x += 40) {
  207. pDrawList->AddRectFilled(
  208. ImVec2(x, trainPos.y + 10),
  209. ImVec2(x + 30, trainPos.y + 40),
  210. ImGui::GetColorU32(ImVec4(0.8f, 0.8f, 1.0f, 1.0f))
  211. );
  212. }
  213.  
  214. // Chimney
  215. pDrawList->AddRectFilled(
  216. ImVec2(trainPos.x + 180, trainPos.y - 50),
  217. ImVec2(trainPos.x + 195, trainPos.y),
  218. ImGui::GetColorU32(ImVec4(0.2f, 0.2f, 0.2f, 1.0f))
  219. );
  220.  
  221. // Locomotive wheels
  222. float wheelRadius = 15.0f;
  223. float wheelSpacing = 50.0f;
  224.  
  225. for (float x = trainPos.x + 30; x < trainPos.x + 220; x += wheelSpacing) {
  226. pDrawList->AddCircleFilled(
  227. ImVec2(x, trainPos.y + 55),
  228. wheelRadius,
  229. ImGui::GetColorU32(ImVec4(0.1f, 0.1f, 0.1f, 1.0f))
  230. );
  231. }
  232.  
  233. // Smoke animation
  234. for (int i = 0; i < 5; i++) {
  235. float smokeOffset = sinf(time * 2.0f + i) * 10.0f;
  236. float smokeSize = 10.0f + i * 5.0f;
  237. float smokeAlpha = 0.6f - (i * 0.1f);
  238.  
  239. pDrawList->AddCircleFilled(
  240. ImVec2(trainPos.x + 187 + smokeOffset, trainPos.y - 60 - (i * 20)),
  241. smokeSize,
  242. ImGui::GetColorU32(ImVec4(0.7f, 0.7f, 0.7f, smokeAlpha))
  243. );
  244. }
  245. }
Success #stdin #stdout 0.04s 25368KB
stdin
Standard input is empty
stdout
// Basic animation variables
static float time = 0.0f;
static float trainPosition = 0.0f;
const float TRAIN_SPEED = 150.0f;
static float moonGlow = 0.0f;
static float moonY = 0.0f;

void RenderScene(); {
    time += ImGui::GetIO().DeltaTime;
    trainPosition += TRAIN_SPEED * ImGui::GetIO().DeltaTime;
    
    // Update moon animations
    moonGlow = 0.5f + 0.5f * sinf(time * 0.5f);
    moonY = 5.0f * sinf(time * 0.2f);

    // Reset train position
    if (trainPosition > ImGui::GetWindowSize().x + 400.0f) {
        trainPosition = -800.0f;  // Increased negative value to account for bogies
    }

    ImDrawList* pDrawList = ImGui::GetWindowDrawList();
    ImVec2 windowPos = ImGui::GetWindowPos();
    ImVec2 windowSize = ImGui::GetWindowSize();

    // Draw moon
    float moonRadius = 40.0f;
    ImVec2 moonCenter(
        windowPos.x + windowSize.x * 0.8f,
        windowPos.y + windowSize.y * 0.2f + moonY
    );

    // Moon glow effect
    for (float r = moonRadius + 30.0f; r >= moonRadius; r -= 1.0f) {
        float alpha = moonGlow * (1.0f - (r - moonRadius) / 30.0f) * 0.3f;
        pDrawList->AddCircleFilled(
            moonCenter,
            r,
            ImGui::GetColorU32(ImVec4(0.9f, 0.9f, 0.7f, alpha))
        );
    }

    // Main moon
    pDrawList->AddCircleFilled(
        moonCenter,
        moonRadius,
        ImGui::GetColorU32(ImVec4(0.95f, 0.95f, 0.8f, 1.0f))
    );

    // Moon craters
    const ImVec2 craters[] = {
        ImVec2(-15, -10), ImVec2(10, -15), ImVec2(5, 5),
        ImVec2(-5, 15), ImVec2(15, 10), ImVec2(-20, 5)
    };

    for (const auto& crater : craters) {
        pDrawList->AddCircleFilled(
            ImVec2(moonCenter.x + crater.x, moonCenter.y + crater.y),
            4.0f,
            ImGui::GetColorU32(ImVec4(0.85f, 0.85f, 0.7f, 1.0f))
        );
    }

    // Add stars around moon
    const int NUM_STARS = 50;
    static std::vector<ImVec2> stars;
    static bool starsInitialized = false;

    // Initialize star positions once
    if (!starsInitialized) {
        stars.clear();
        for (int i = 0; i < NUM_STARS; i++) {
            float angle = (float)i / NUM_STARS * 2 * 3.14159f;
            float distance = 100.0f + rand() % 200;
            stars.push_back(ImVec2(
                moonCenter.x + cosf(angle) * distance,
                moonCenter.y + sinf(angle) * distance
            ));
        }
        starsInitialized = true;
    }

    // Draw stars with twinkling effect
    for (size_t i = 0; i < stars.size(); i++) {
        float starGlow = 0.3f + 0.7f * sinf(time * 2.0f + i * 1.5f);
        float starSize = 2.0f + sinf(time * 3.0f + i) * 0.5f;
        
        pDrawList->AddCircleFilled(
            stars[i],
            starSize,
            ImGui::GetColorU32(ImVec4(1.0f, 1.0f, 1.0f, starGlow))
        );
    }

    // Draw railway tracks
    float trackY = windowPos.y + windowSize.y * 0.7f;
    
    // Draw track base
    pDrawList->AddRectFilled(
        ImVec2(windowPos.x, trackY - 5),
        ImVec2(windowPos.x + windowSize.x, trackY + 15),
        ImGui::GetColorU32(ImVec4(0.3f, 0.3f, 0.3f, 1.0f))
    );

    // Draw railroad ties
    float tieSpacing = 50.0f;
    float tieOffset = fmodf(time * TRAIN_SPEED, tieSpacing);
    
    for (float x = -tieSpacing + tieOffset; x < windowSize.x; x += tieSpacing) {
        pDrawList->AddRectFilled(
            ImVec2(windowPos.x + x, trackY - 10),
            ImVec2(windowPos.x + x + 30, trackY + 20),
            ImGui::GetColorU32(ImVec4(0.4f, 0.2f, 0.1f, 1.0f))
        );
    }

    // Draw rails
    pDrawList->AddRectFilled(
        ImVec2(windowPos.x, trackY - 2),
        ImVec2(windowPos.x + windowSize.x, trackY),
        ImGui::GetColorU32(ImVec4(0.7f, 0.7f, 0.7f, 1.0f))
    );
    
    pDrawList->AddRectFilled(
        ImVec2(windowPos.x, trackY + 10),
        ImVec2(windowPos.x + windowSize.x, trackY + 12),
        ImGui::GetColorU32(ImVec4(0.7f, 0.7f, 0.7f, 1.0f))
    );

    // Draw Train
    ImVec2 trainPos(windowPos.x + trainPosition, trackY - 60);


// Add train bogies (compartments) BEHIND the locomotive
    const int NUM_BOGIES = 3;
    float bogieWidth = 180.0f;
    float bogieGap = 20.0f;
    float bogieStartX = trainPos.x - bogieWidth - bogieGap;

    for (int i = 0; i < NUM_BOGIES; i++) {
        float bogieX = bogieStartX - (bogieWidth + bogieGap) * i;
        
        // Bogie body
        pDrawList->AddRectFilled(
            ImVec2(bogieX, trainPos.y),
            ImVec2(bogieX + bogieWidth, trainPos.y + 60),
            ImGui::GetColorU32(ImVec4(0.7f, 0.2f, 0.2f, 1.0f))
        );

        // Glowing windows
        float windowGlow = 0.5f + 0.5f * sinf(time * 2.0f + i * 1.5f);
        for (float wx = bogieX + 20; wx < bogieX + bogieWidth - 20; wx += 40) {
            // Window glow effect
            for (float r = 20.0f; r >= 0.0f; r -= 1.0f) {
                float alpha = windowGlow * (1.0f - r / 20.0f) * 0.3f;
                pDrawList->AddRectFilled(
                    ImVec2(wx - r, trainPos.y + 10 - r),
                    ImVec2(wx + 30 + r, trainPos.y + 40 + r),
                    ImGui::GetColorU32(ImVec4(1.0f, 1.0f, 0.8f, alpha))
                );
            }

            // Actual window
            pDrawList->AddRectFilled(
                ImVec2(wx, trainPos.y + 10),
                ImVec2(wx + 30, trainPos.y + 40),
                ImGui::GetColorU32(ImVec4(1.0f, 1.0f, 0.8f, 1.0f))
            );
        }

        // Wheels for each bogie
        float wheelRadius = 15.0f;
        float wheelSpacing = 50.0f;
        
        for (float x = bogieX + 30; x < bogieX + bogieWidth - 30; x += wheelSpacing) {
            pDrawList->AddCircleFilled(
                ImVec2(x, trainPos.y + 55),
                wheelRadius,
                ImGui::GetColorU32(ImVec4(0.1f, 0.1f, 0.1f, 1.0f))
            );
        }
    }
    
    // Locomotive body
    pDrawList->AddRectFilled(
        ImVec2(trainPos.x, trainPos.y),
        ImVec2(trainPos.x + 200, trainPos.y + 60),
        ImGui::GetColorU32(ImVec4(0.2f, 0.3f, 0.8f, 1.0f))
    );

    // Locomotive front
    pDrawList->AddRectFilled(
        ImVec2(trainPos.x + 200, trainPos.y + 10),
        ImVec2(trainPos.x + 240, trainPos.y + 60),
        ImGui::GetColorU32(ImVec4(0.2f, 0.2f, 0.7f, 1.0f))
    );

    // Cabin
    pDrawList->AddRectFilled(
        ImVec2(trainPos.x + 140, trainPos.y - 30),
        ImVec2(trainPos.x + 200, trainPos.y),
        ImGui::GetColorU32(ImVec4(0.2f, 0.2f, 0.7f, 1.0f))
    );

    // Windows
    for (float x = trainPos.x + 20; x < trainPos.x + 120; x += 40) {
        pDrawList->AddRectFilled(
            ImVec2(x, trainPos.y + 10),
            ImVec2(x + 30, trainPos.y + 40),
            ImGui::GetColorU32(ImVec4(0.8f, 0.8f, 1.0f, 1.0f))
        );
    }

    // Chimney
    pDrawList->AddRectFilled(
        ImVec2(trainPos.x + 180, trainPos.y - 50),
        ImVec2(trainPos.x + 195, trainPos.y),
        ImGui::GetColorU32(ImVec4(0.2f, 0.2f, 0.2f, 1.0f))
    );

    // Locomotive wheels
    float wheelRadius = 15.0f;
    float wheelSpacing = 50.0f;
    
    for (float x = trainPos.x + 30; x < trainPos.x + 220; x += wheelSpacing) {
        pDrawList->AddCircleFilled(
            ImVec2(x, trainPos.y + 55),
            wheelRadius,
            ImGui::GetColorU32(ImVec4(0.1f, 0.1f, 0.1f, 1.0f))
        );
    }

    // Smoke animation
    for (int i = 0; i < 5; i++) {
        float smokeOffset = sinf(time * 2.0f + i) * 10.0f;
        float smokeSize = 10.0f + i * 5.0f;
        float smokeAlpha = 0.6f - (i * 0.1f);
        
        pDrawList->AddCircleFilled(
            ImVec2(trainPos.x + 187 + smokeOffset, trainPos.y - 60 - (i * 20)),
            smokeSize,
            ImGui::GetColorU32(ImVec4(0.7f, 0.7f, 0.7f, smokeAlpha))
        );
    }
}