转到内容

GCC 调试/g++/警告/已弃用从字符串常量转换

从维基教科书,面向开放世界的开放书籍

//此代码由 SOBAN 开发 //!!! 你必须添加 graphics.h 库才能运行此代码 //教程请访问我的频道:soban can code //如需进一步查询,请 WA 我:0325-4300011 //订阅以获得支持:soban can code

  1. include <stdio.h>
  2. include <conio.h>
  3. include <iostream>
  4. include <graphics.h>

using namespace std;

// 使用中点椭圆绘制算法绘制椭圆的函数 void drawEllipseMidpoint(int xCenter, int yCenter, int radiusX, int radiusY) {

   int x = 0;
   int y = radiusY;
   int p;
   int px = 0;
   int py = 2 * radiusX * radiusX * y;
   // Region 1
   p = radiusY * radiusY - (radiusX * radiusX * radiusY) + (0.25 * radiusX * radiusX);
   while (px < py)
   {
       putpixel(xCenter + x, yCenter - y, GREEN);
       putpixel(xCenter - x, yCenter - y, GREEN);
       putpixel(xCenter + x, yCenter + y, GREEN);
       putpixel(xCenter - x, yCenter + y, GREEN);
       x++;
       px += 2 * radiusY * radiusY;
       if (p < 0)
           p += radiusY * radiusY + px;
       else
       {
           y--;
           py -= 2 * radiusX * radiusX;
           p += radiusY * radiusY + px - py;
       }
   }
   // Region 2
   p = radiusY * radiusY * (x + 0.5) * (x + 0.5) +
       radiusX * radiusX * (y - 1) * (y - 1) -
       radiusX * radiusX * radiusY * radiusY;
   while (y >= 0)
   {
       putpixel(xCenter + x, yCenter - y, GREEN);
       putpixel(xCenter - x, yCenter - y, GREEN);
       putpixel(xCenter + x, yCenter + y, GREEN);
       putpixel(xCenter - x, yCenter + y, GREEN);
       y--;
       py -= 2 * radiusX * radiusX;
       if (p > 0)
           p += radiusX * radiusX - py;
       else
       {
           x++;
           px += 2 * radiusY * radiusY;
           p += radiusX * radiusX - py + px;
       }
   }

}

int main() {

   int gd = DETECT, gm;
   initgraph(&gd, &gm, "");
   
   outtextxy(180, 180, "ID: BC200400812 ");
   
   // Set fill style to custom pattern fill
   setfillstyle(USER_FILL, GREEN);
   // Create a custom pattern
   char pattern[8] = {
       0b11000011,
       0b11111111,
       0b11111111,
       0b11000011,
       0b00000000,
       0b00000000,
       0b11000011,
       0b11111111};
   // Set the custom pattern
   setfillpattern(pattern, GREEN);
   // Draw and fill the ellipse with a design
   drawEllipseMidpoint(250, 250, 100, 50);
   floodfill(250, 250, GREEN);
   // Pause the screen
   getch();
   // Close the graphics window
   closegraph();
   return 0;

}

华夏公益教科书