Friday, September 22, 2023

#include <windows.h>

#include <iostream>

#include <math.h>

void drawCircle(int x, int y, int radius) {

// Get the console handle.

HWND consoleHandle = GetConsoleWindow();

// Create a graphics device context for the console.

HDC deviceContext = GetDC(consoleHandle);

// Set the pen color to white.

HPEN pen = CreatePen(PS_SOLID, 1, RGB(255, 255, 255));

SelectObject(deviceContext, pen);

// Calculate the starting and ending points for the circle.

int startX = x - radius;

int startY = y - radius;

int endX = x + radius;

int endY = y + radius;

// Draw the circle.

Ellipse(deviceContext, startX, startY, endX, endY);

// Delete the pen.

DeleteObject(pen);

// Release the graphics device context.

ReleaseDC(consoleHandle, deviceContext);

}

int main() {

// Draw a circle at the center of the console.

drawCircle(400, 400, 100);

// Keep the console window open until the user presses a key.

getchar();

return 0;

}


No comments:

Post a Comment

N-point Star in Microsoft Visual Studio Console App

#include <windows.h> #include <cmath> #include <iostream> LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,...