MCPcopy Create free account
hub / github.com/CruiserOne/Astrolog / DrawTurtle

Function DrawTurtle

xgeneral.cpp:2000–2056  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1998// and left 10, which draws a box twice as wide as it is high.
1999
2000void DrawTurtle(CONST char *sz, int x0, int y0)
2001{
2002 int i, x, y, deltax, deltay;
2003 flag fBlank, fNoupdate;
2004 char szErr[cchSzDef], chCmd;
2005
2006 gi.xTurtle = x0; gi.yTurtle = y0;
2007 while (chCmd = ChCap(*sz)) {
2008 sz++;
2009
2010 // 'B' prefixing a command means just move the cursor, and don't draw.
2011
2012 if (fBlank = (chCmd == 'B')) {
2013 chCmd = ChCap(*sz);
2014 sz++;
2015 }
2016
2017 // 'N' prefixing a command means don't update cursor when done drawing.
2018
2019 if (fNoupdate = (chCmd == 'N')) {
2020 chCmd = ChCap(*sz);
2021 sz++;
2022 }
2023
2024 // Process the eight directional commands.
2025
2026 switch (chCmd) {
2027 case 'U': deltax = 0; deltay = -1; break; // Up
2028 case 'D': deltax = 0; deltay = 1; break; // Down
2029 case 'L': deltax = -1; deltay = 0; break; // Left
2030 case 'R': deltax = 1; deltay = 0; break; // Right
2031 case 'E': deltax = 1; deltay = -1; break; // NorthEast
2032 case 'F': deltax = 1; deltay = 1; break; // SouthEast
2033 case 'G': deltax = -1; deltay = 1; break; // SouthWest
2034 case 'H': deltax = -1; deltay = -1; break; // NorthWest
2035 default:
2036 deltax = deltay = 0;
2037 sprintf(szErr, "Bad draw turtle action character: '%c'", chCmd);
2038 PrintError(szErr);
2039 }
2040 x = gi.xTurtle;
2041 y = gi.yTurtle;
2042 i = NFromPch(&sz)*gi.nScale; // Figure out how far to draw.
2043 if (fBlank) {
2044 gi.xTurtle += deltax*i;
2045 gi.yTurtle += deltay*i;
2046 } else {
2047 gi.xTurtle += deltax*i;
2048 gi.yTurtle += deltay*i;
2049 DrawLine(x, y, gi.xTurtle, gi.yTurtle);
2050 if (fNoupdate) {
2051 gi.xTurtle = x;
2052 gi.yTurtle = y;
2053 }
2054 }
2055 }
2056}
2057

Callers 6

DrawSzFunction · 0.85
DrawSignFunction · 0.85
DrawHouseFunction · 0.85
DrawObjectFunction · 0.85
DrawAspectFunction · 0.85
DrawTurtle2Function · 0.85

Calls 2

PrintErrorFunction · 0.85
NFromPchFunction · 0.85

Tested by

no test coverage detected