diff --git a/linux/templates/epitrochoid_c.txt b/linux/templates/epitrochoid_c.txt index 608ce42e..340b4ef7 100644 --- a/linux/templates/epitrochoid_c.txt +++ b/linux/templates/epitrochoid_c.txt @@ -5,8 +5,12 @@ #define RAYGUI_IMPLEMENTATION #include -void updateRadius(int baseL, int outerL, int *pBaseR, int *pOuterR) { - int totalL=baseL+outerL+outerL; +void updateRadius(int baseL, int outerL, int pointL, int *pBaseR, int *pOuterR, int *pPointR) { + int totalL=baseL+outerL; + if (pointL>outerL) + totalL+=pointL; + else + totalL+=outerL; int totalR = 420; int remainder = totalR % totalL; if (remainder!=0) { @@ -18,17 +22,19 @@ void updateRadius(int baseL, int outerL, int *pBaseR, int *pOuterR) { } *pBaseR = (totalR) / totalL * baseL; *pOuterR = (totalR) / totalL * outerL; + *pPointR = (totalR) / totalL * pointL; } int main() { int baseL=2; int outerL=13; - int baseR,outerR; + int pointL=3; + int baseR,outerR,pointR; int cx=450,cy=450; int speed = 1; Color trackColor = BLUE; - updateRadius(baseL, outerL, &baseR, &outerR); + updateRadius(baseL, outerL, pointL, &baseR, &outerR, & pointR); InitWindow(1300,900,"Epitrochoid"); SetTraceLogLevel(LOG_WARNING); SetTargetFPS(60); @@ -43,22 +49,27 @@ int main() { float r=0; int lastx,lasty; lasty=cy; - lastx=cx+(baseR+outerR+outerR); + lastx=cx+(baseR+outerR-pointR); int frameCount = 0; while(!WindowShouldClose()) { //GUI int newOuterL = GuiSliderBar((Rectangle){ 70, 20, 200, 30 },"Outer",TextFormat("%i", (int)outerL), outerL, 1, 50); int newBaseL = GuiSliderBar((Rectangle){ 70, 60, 200, 30 },"Base",TextFormat("%i", (int)baseL), baseL, 1, 50); - speed = GuiSliderBar((Rectangle){ 70, 120, 200, 30 },"Speed",TextFormat("%i", (int)speed), speed, 1, 50); + int newPointL = GuiSliderBar((Rectangle){ 70, 100, 200, 30 },"Point",TextFormat("%i", (int)pointL), pointL, 1, 50); + speed = GuiSliderBar((Rectangle){ 70, 150, 200, 30 },"Speed",TextFormat("%i", (int)speed), speed, 1, 50); GuiLabel((Rectangle){ 20, 220, 80, 30 },TextFormat("Color: 0x%X%X%X ",(int)(trackColor.r), (int)(trackColor.g),(int)(trackColor.b))); trackColor= GuiColorPicker((Rectangle){ 50, 250, 196, 192 }, NULL, trackColor); int doClear = GuiButton((Rectangle){ 120, 700, 80, 30 },"Clear"); - if (newOuterL!=outerL || newBaseL!=baseL) { + if (newOuterL!=outerL || newBaseL!=baseL || newPointL!=pointL) { + if (newInnerL!=innerL) + pointL=newInnerL; + else + pointL=newPointL; outerL=newOuterL; baseL=newBaseL; - updateRadius(baseL, outerL, &baseR, &outerR); + updateRadius(baseL, outerL, pointL, &baseR, &outerR, & pointR); lasty=cy; - lastx=cx+(baseR+outerR+outerR); + lastx=cx+(baseR+outerR-pointR); r=0; ImageClearBackground(&trackImage,WHITE); ImageFillRectangleEx(&trackImage,0,0,900,900,LIGHTGRAY); @@ -72,9 +83,9 @@ int main() { r+=0.01; float outerCX=cx+ (baseR+outerR)*cos(r); float outerCY=cy+ (baseR+outerR)*sin(r); - float theta = r * baseL / outerL; - int x=round(outerCX + outerR * cos(theta)); - int y=round(outerCY + outerR * sin(theta)); + float theta = r * (baseL+outerL) / outerL; + int x=round(outerCX - pointR * cos(theta)); + int y=round(outerCY - pointR * sin(theta)); //update image (in CPU) //ImageClearBackground(&trackImage,WHITE); @@ -86,6 +97,8 @@ int main() { //base circle ImageDrawCircleEx(&circlesImage,cx,cy,baseR,1,LIGHTRED); ImageDrawCircleEx(&circlesImage,outerCX,outerCY,outerR,1,LIGHTSLATEGRAY); + ImageDrawLineEx(&circlesImage,cx,cy,outerCX,outerCY,1,LIGHTRED); + ImageDrawLineEx(&circlesImage,x,y,outerCX,outerCY,1,LIGHTSLATEGRAY); ImageDrawPointEx(&circlesImage,x,y,7,RED); //Drawing in GPU @@ -109,4 +122,4 @@ int main() { UnloadImage(circlesImage); UnloadImage(trackImage); CloseWindow(); -} +} \ No newline at end of file diff --git a/linux/templates/hypotrochoid_c.txt b/linux/templates/hypotrochoid_c.txt index b847ea2c..e24b1467 100644 --- a/linux/templates/hypotrochoid_c.txt +++ b/linux/templates/hypotrochoid_c.txt @@ -5,10 +5,18 @@ #define RAYGUI_IMPLEMENTATION #include -void updateRadius(int baseL, int innerL, int *pBaseR, int *pInnerR) { +void updateRadius(int baseL, int innerL,int pointL, int *pBaseR, int *pInnerR, int *pPointR) { int totalL=baseL; - if (innerL>baseL) - totalL = (2*innerL-baseL); + if (innerL>baseL) { + if (innerL>pointL) + totalL = (2*innerL-baseL); + else { + totalL = (innerL+pointL-baseL); + } + } else { + if (pointL>innerL) + totalL = baseL-innerL+pointL; + } int totalR = 420; int remainder = totalR % totalL; if (remainder!=0) { @@ -18,24 +26,21 @@ void updateRadius(int baseL, int innerL, int *pBaseR, int *pInnerR) { totalR += ( totalL - remainder); } } - if (innerL=speed) { ImageClearBackground(&circlesImage,BLANK); //base circle ImageDrawCircleEx(&circlesImage,cx,cy,baseR,1,LIGHTRED); - ImageDrawCircleEx(&circlesImage,innerCX,innerCY,innerR,1,LIGHTSLATEGRAY); + ImageDrawCircleEx(&circlesImage,innerCX,innerCY,innerR,1,LIGHTGRAY); + ImageDrawLineEx(&circlesImage,innerCX,innerCY,cx,cy,1,LIGHTRED); + ImageDrawLineEx(&circlesImage,innerCX,innerCY,x,y,1,LIGHTGRAY); ImageDrawPointEx(&circlesImage,x,y,7,RED); //Drawing in GPU @@ -107,13 +127,14 @@ int main() { UnloadTexture(trackTexture); frameCount=0; } - lastx=x; lasty=y; + skip=false; + r+=0.01; } //Clean up UnloadImage(circlesImage); UnloadImage(trackImage); CloseWindow(); -} +} \ No newline at end of file diff --git a/windows/templates/epitrochoid_c.txt b/windows/templates/epitrochoid_c.txt index 608ce42e..340b4ef7 100644 --- a/windows/templates/epitrochoid_c.txt +++ b/windows/templates/epitrochoid_c.txt @@ -5,8 +5,12 @@ #define RAYGUI_IMPLEMENTATION #include -void updateRadius(int baseL, int outerL, int *pBaseR, int *pOuterR) { - int totalL=baseL+outerL+outerL; +void updateRadius(int baseL, int outerL, int pointL, int *pBaseR, int *pOuterR, int *pPointR) { + int totalL=baseL+outerL; + if (pointL>outerL) + totalL+=pointL; + else + totalL+=outerL; int totalR = 420; int remainder = totalR % totalL; if (remainder!=0) { @@ -18,17 +22,19 @@ void updateRadius(int baseL, int outerL, int *pBaseR, int *pOuterR) { } *pBaseR = (totalR) / totalL * baseL; *pOuterR = (totalR) / totalL * outerL; + *pPointR = (totalR) / totalL * pointL; } int main() { int baseL=2; int outerL=13; - int baseR,outerR; + int pointL=3; + int baseR,outerR,pointR; int cx=450,cy=450; int speed = 1; Color trackColor = BLUE; - updateRadius(baseL, outerL, &baseR, &outerR); + updateRadius(baseL, outerL, pointL, &baseR, &outerR, & pointR); InitWindow(1300,900,"Epitrochoid"); SetTraceLogLevel(LOG_WARNING); SetTargetFPS(60); @@ -43,22 +49,27 @@ int main() { float r=0; int lastx,lasty; lasty=cy; - lastx=cx+(baseR+outerR+outerR); + lastx=cx+(baseR+outerR-pointR); int frameCount = 0; while(!WindowShouldClose()) { //GUI int newOuterL = GuiSliderBar((Rectangle){ 70, 20, 200, 30 },"Outer",TextFormat("%i", (int)outerL), outerL, 1, 50); int newBaseL = GuiSliderBar((Rectangle){ 70, 60, 200, 30 },"Base",TextFormat("%i", (int)baseL), baseL, 1, 50); - speed = GuiSliderBar((Rectangle){ 70, 120, 200, 30 },"Speed",TextFormat("%i", (int)speed), speed, 1, 50); + int newPointL = GuiSliderBar((Rectangle){ 70, 100, 200, 30 },"Point",TextFormat("%i", (int)pointL), pointL, 1, 50); + speed = GuiSliderBar((Rectangle){ 70, 150, 200, 30 },"Speed",TextFormat("%i", (int)speed), speed, 1, 50); GuiLabel((Rectangle){ 20, 220, 80, 30 },TextFormat("Color: 0x%X%X%X ",(int)(trackColor.r), (int)(trackColor.g),(int)(trackColor.b))); trackColor= GuiColorPicker((Rectangle){ 50, 250, 196, 192 }, NULL, trackColor); int doClear = GuiButton((Rectangle){ 120, 700, 80, 30 },"Clear"); - if (newOuterL!=outerL || newBaseL!=baseL) { + if (newOuterL!=outerL || newBaseL!=baseL || newPointL!=pointL) { + if (newInnerL!=innerL) + pointL=newInnerL; + else + pointL=newPointL; outerL=newOuterL; baseL=newBaseL; - updateRadius(baseL, outerL, &baseR, &outerR); + updateRadius(baseL, outerL, pointL, &baseR, &outerR, & pointR); lasty=cy; - lastx=cx+(baseR+outerR+outerR); + lastx=cx+(baseR+outerR-pointR); r=0; ImageClearBackground(&trackImage,WHITE); ImageFillRectangleEx(&trackImage,0,0,900,900,LIGHTGRAY); @@ -72,9 +83,9 @@ int main() { r+=0.01; float outerCX=cx+ (baseR+outerR)*cos(r); float outerCY=cy+ (baseR+outerR)*sin(r); - float theta = r * baseL / outerL; - int x=round(outerCX + outerR * cos(theta)); - int y=round(outerCY + outerR * sin(theta)); + float theta = r * (baseL+outerL) / outerL; + int x=round(outerCX - pointR * cos(theta)); + int y=round(outerCY - pointR * sin(theta)); //update image (in CPU) //ImageClearBackground(&trackImage,WHITE); @@ -86,6 +97,8 @@ int main() { //base circle ImageDrawCircleEx(&circlesImage,cx,cy,baseR,1,LIGHTRED); ImageDrawCircleEx(&circlesImage,outerCX,outerCY,outerR,1,LIGHTSLATEGRAY); + ImageDrawLineEx(&circlesImage,cx,cy,outerCX,outerCY,1,LIGHTRED); + ImageDrawLineEx(&circlesImage,x,y,outerCX,outerCY,1,LIGHTSLATEGRAY); ImageDrawPointEx(&circlesImage,x,y,7,RED); //Drawing in GPU @@ -109,4 +122,4 @@ int main() { UnloadImage(circlesImage); UnloadImage(trackImage); CloseWindow(); -} +} \ No newline at end of file diff --git a/windows/templates/hypotrochoid_c.txt b/windows/templates/hypotrochoid_c.txt index b847ea2c..e24b1467 100644 --- a/windows/templates/hypotrochoid_c.txt +++ b/windows/templates/hypotrochoid_c.txt @@ -5,10 +5,18 @@ #define RAYGUI_IMPLEMENTATION #include -void updateRadius(int baseL, int innerL, int *pBaseR, int *pInnerR) { +void updateRadius(int baseL, int innerL,int pointL, int *pBaseR, int *pInnerR, int *pPointR) { int totalL=baseL; - if (innerL>baseL) - totalL = (2*innerL-baseL); + if (innerL>baseL) { + if (innerL>pointL) + totalL = (2*innerL-baseL); + else { + totalL = (innerL+pointL-baseL); + } + } else { + if (pointL>innerL) + totalL = baseL-innerL+pointL; + } int totalR = 420; int remainder = totalR % totalL; if (remainder!=0) { @@ -18,24 +26,21 @@ void updateRadius(int baseL, int innerL, int *pBaseR, int *pInnerR) { totalR += ( totalL - remainder); } } - if (innerL=speed) { ImageClearBackground(&circlesImage,BLANK); //base circle ImageDrawCircleEx(&circlesImage,cx,cy,baseR,1,LIGHTRED); - ImageDrawCircleEx(&circlesImage,innerCX,innerCY,innerR,1,LIGHTSLATEGRAY); + ImageDrawCircleEx(&circlesImage,innerCX,innerCY,innerR,1,LIGHTGRAY); + ImageDrawLineEx(&circlesImage,innerCX,innerCY,cx,cy,1,LIGHTRED); + ImageDrawLineEx(&circlesImage,innerCX,innerCY,x,y,1,LIGHTGRAY); ImageDrawPointEx(&circlesImage,x,y,7,RED); //Drawing in GPU @@ -107,13 +127,14 @@ int main() { UnloadTexture(trackTexture); frameCount=0; } - lastx=x; lasty=y; + skip=false; + r+=0.01; } //Clean up UnloadImage(circlesImage); UnloadImage(trackImage); CloseWindow(); -} +} \ No newline at end of file