Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <graphics.h>
- void dda(float x1, float y1, float x2, float y2){
- detectgraph(&gd,&gm);
- initgraph(&gd,&gm,"C:\\TC\\BGI");
- float x, y, dx, dy, length;
- int i, intx, inty;
- abs(x2 - x1) > abs(y2 - y1) ? (length = abs(x2 - x1)) : (length = abs(y2 - y1));
- dx = (x2 - x1) / length;
- dy = (y2 - y1) / length;
- dx >= 0 ? (x = x1 + 0.5) : (x = x1 - 0.5);
- dy >= 0 ? (y = y1 + 0.5) : (y = y1 - 0.5);
- for(i = 0, intx = x, inty = y; i <= length; i++, x += dx, y += dy, intx = x, inty = y)
- putpixel(intx, inty, 30);
- delay(100);
- }
- int main(){
- dda(50,100,100,100);
- dda(50,100,50, 50);
- dda(100, 100, 100, 50);
- dda(50, 50, 75, 0);
- dda(100, 50, 75, 0);
- dda(100, 50, 50, 50);
- closegraph();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement