בעיה ביצירת קו מקווקו ב- C (עיצוב גרפי) - תכנות - HWzone פורומים
עבור לתוכן
  • צור חשבון

בעיה ביצירת קו מקווקו ב- C (עיצוב גרפי)


moses_23

Recommended Posts

יש לי את קטע התוכנית הזו:

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <math.h>

int main(void)
{


/* request auto detection */
int gdriver = DETECT, gmode, errorcode;



/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");

/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
float x1,x2,y1,y2,m,n;
float x,y,t;
float dx,dy;
x1=100;
y1=200;
x2=200;
y2=400;

dx=fabs(x2-x1);
dy=fabs(y2-y1);
m=(y2-y1)/(x2-x1);
n=y1-m*x1;
if(dx<dy)
{
for (y=y1;y<=y2;y++);
x=(y-n)/m;
putpixel(x,y,BLUE);
}
else{
if (x2>x1){
t=x1;
x1=x2;
x2=t;
for (x=x1;x<=x2;x++);
y=m*x+n;
putpixel(x,y,WHITE);
}
}
/* clean up */
getch();
closegraph();
return 0;
}

הקטע אמור להביא לי קו מקווקו.

אבל הבעיה שאני לא רואה שום דבר חוץ מנקודה אחת ולפעמים גם את זה לא

מה הבעיה שלי?

אגב...אני משתמש בתיקיה BGI במקום BIN למי שהבין...

קישור לתוכן
שתף באתרים אחרים

תשים }{ בלולאת הFOR שלך ותתוריד את ה;.

ד.א. תנסה את:


void fun(int x1, int y2, int x2, int y2, int step)
int i;
double x, y, dx, dy;
int step;

x=x1;
y=y1;
dx=(x2-x1)/step;
dy=(y2-y1)/step;
for(i=0;i<step;i++, x+=dx, y+=dy)
putpixel((int)x, (int)y, BLUE);

}

כאשר (x1, y1), (x2, y2) אלה הקאורדינאטות, וSTEP זה מספר הנק באמצע שאתה רוצה(קו מקווקו).

יכול להיות שתצטרך לשנות את החלוקה בSTEP. לא בדקתי את זה.

קישור לתוכן
שתף באתרים אחרים

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

×
  • צור חדש...