10 条题解

  • 0
    @ 2026-2-5 15:08:16
    #include <bits/stdc++.h>
    #include <raylib.h>
    using namespace std;
    
    int main(){
    	int sw;
    	int sh;
    	cin>>sw>>sh;
    	InitWindow(sw,sh,"Interactive Rose Curve-Raylib");
    	SetTargetFPS(60);
    	float scale=200.0,a=1.0,k=5.0;
    	Vector2 center={(float)sw/2,(float)sh/2};
    	bool useCos=0,animate=0;
    	while(!WindowShouldClose()){
    		if(IsKeyPressed(KEY_UP))k+=0.5;
    		if(IsKeyPressed(KEY_DOWN)&&k>0.5)k-=0.5;
    		if(IsKeyPressed(KEY_LEFT)&&scale>10)scale-=10;
    		if(IsKeyPressed(KEY_RIGHT))scale+=10;
    		if(IsKeyPressed(KEY_SPACE))useCos=!useCos;
    		if(IsKeyPressed(KEY_A))animate=!animate;
    		if(animate){
    			float time=GetTime();
    			k=2+3*sin(time*0.5f);
    			a=1+0.3f*sin(time*2);
    		}
    		BeginDrawing();
    		ClearBackground(RAYWHITE);
    		DrawLine(0,center.y,sw,center.y,LIGHTGRAY);
    		DrawLine(center.x,0,center.x,sh,LIGHTGRAY);
    		DrawText("X",sw-20,center.y-10,16,GRAY);
    		DrawText("Y",center.x+10,10,16,GRAY);
    		Vector2 prevP={0,0};
    		bool firstP=1;
    		for(double theta=0;theta<=2*PI;theta+=0.0001){
    			float r=a*(sin(k*theta));
    			float x=r*cos(theta);
    			float y=r*sin(theta);
    			Vector2 point={center.x+x*scale,center.y-y*scale};
    			if(!firstP){
    				DrawLineEx(prevP,point,2.0,RED);
    			}
    			prevP=point;
    			firstP=false;
    		}
    		EndDrawing();
    	}
    	CloseWindow();
    }
    

    信息

    ID
    6805
    时间
    1000ms
    内存
    128MiB
    难度
    1
    标签
    递交数
    281
    已通过
    104
    上传者