Outils pour utilisateurs

Outils du site


back2root:archives:denthor:part-03

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révisionLes deux révisions suivantes
back2root:archives:denthor:part-03 [2021/09/04 22:42] fraterback2root:archives:denthor:part-03 [2023/05/18 20:35] frater
Ligne 1: Ligne 1:
 ===== PART 03 : Lines and circles ===== ===== PART 03 : Lines and circles =====
  
-Greetings! This is the third part of the VGA Trainer series! Sorry it took so long to get out, but I had a running battle with the traffic department for three days to get my car registered, and then the MailBox +Greetings! This is the third part of the VGA Trainer series! Sorry it took so long to get out, but I had a running battle with the traffic department for three days to get my car registered, and then the MailBox went down. Ahh, well, life stinks. Anyway, today will do some things vital to most programs : Lines and circles.
-went down. Ahh, well, life stinks. Anyway, today will do some things vital to most programs : Lines and circles.+
  
-Watch out for next week's part : Virtual screens. The easy way to eliminate flicker, "doubled sprites", and subjecting the user to watch you building your screen. Almost every ASPHYXIA demo has used a virtual +Watch out for next week's part : Virtual screens. The easy way to eliminate flicker, "doubled sprites", and subjecting the user to watch you building your screen. Almost every ASPHYXIA demo has used a virtual screen (with the exception of the SilkyDemo), so this is one to watch out for. I will also show you how to put all of these loose procedures into units.
-screen (with the exception of the SilkyDemo), so this is one to watch out for. I will also show you how to put all of these loose procedures into units.+
  
 If you would like to contact me, or the team, there are many ways you  can do it : If you would like to contact me, or the team, there are many ways you  can do it :
Ligne 40: Ligne 38:
 </code> </code>
  
-Sorry about my ASCI ;-) ... anyway, Pascal doesn't work that way ... it +Sorry about my ASCI ;-) ... anyway, Pascal doesn't work that way ... it works with radians instead of degrees. (You can convert radians to degrees, but I'm not going to go into that now. Note though that in pascal, the
-works with radians instead of degrees. (You can convert radians to degrees, +
-but I'm not going to go into that now. Note though that in pascal, the+
 circle goes like this : circle goes like this :
  
Ligne 97: Ligne 93:
 </code> </code>
  
-In the above example, the smaller the amount that deg is increased by, +In the above example, the smaller the amount that deg is increased by, the closer the pixels in the circle will be, but the slower the procedure. 
-the closer the pixels in the circle will be, but the slower the procedure+
-0.005 seem to be best for the 320x200 screen. NOTE : ASPHYXIA does not use +
-this particular circle algorithm, ours is in assembly language, but this +
-one should be fast enough for most. If it isn't, give us the stuff you are +
-using it for and we'll give you ours.+
  
 +0.005 seem to be best for the 320x200 screen. 
 +
 +<WRAP center round info 60%>
 +ASPHYXIA does not use this particular circle algorithm, ours is in assembly language, but this one should be fast enough for most. If it isn't, give us the stuff you are using it for and we'll give you ours.
 +</WRAP>
  
 ==== Line algorithms ==== ==== Line algorithms ====
  
-There are many ways to draw a line on the computer. I will describe one +There are many ways to draw a line on the computer. I will describe one and give you two. (The second one you can figure out for yourselves; it is based on the first one but is faster
-and give you two. (The second one you can figure out for yourselves; it + 
-is based on the first one but is faster)+The first thing you need to do is pass what you want the line to look like to your line procedure. What I have done is said that x1,y1 is the first point on the screen, and x2,y2 is the second point. We also pass the 
 +color to the procedure. (Remember the screens top left hand corner is (0,0); see Part 1)
  
-The first thing you need to do is pass what you want the line to look +{{drawio>back2root:archives:denthor:part-03-line-01.png}}
-like to your line procedure. What I have done is said that x1,y1 is the +
-first point on the screen, and x2,y2 is the second point. We also pass the +
-color to the procedure(Remember the screens top left hand corner is (0,0); +
-see Part 1)+
  
 Ie.            o  (X1,Y1) Ie.            o  (X1,Y1)
Ligne 126: Ligne 119:
 To find the length of the line, we say the following : To find the length of the line, we say the following :
  
 +<code>
            XLength = ABS (x1-x2)            XLength = ABS (x1-x2)
            YLength = ABS (y1-y2)            YLength = ABS (y1-y2)
 +</code>
  
-The ABS function means that whatever the result, it will give you an +The ABS function means that whatever the result, it will give you an absolute, or posotive, answer. At this stage I set a variable stating wheter the difference between the two x's are negative, zero or posotive. 
-absolute, or posotive, answer. At this stage I set a variable stating +
-wheter the difference between the two x's are negative, zero or posotive+
-(I do the same for the y's) If the difference is zero, I just use a loop +
-keeping the two with the zero difference posotive, then exit.+
  
-If neither the x's or y'have a zero difference, I calculate the X and Y +(I do the same for the y's) If the difference is zero, I just use a loop keeping the two with the zero difference posotive, then exit.
-slopes, using the following two equations :+
  
 +If neither the x's or y's have a zero difference, I calculate the X and Y slopes, using the following two equations :
 +
 +<code>
            Xslope = Xlength / Ylength            Xslope = Xlength / Ylength
            Yslope = Ylength / Xlength            Yslope = Ylength / Xlength
 +</code>
  
 As you can see, the slopes are real numbers. As you can see, the slopes are real numbers.
-NOTE : XSlope = 1 / YSlope 
  
-Now, there are two ways of drawing the lines :+<WRAP center round info 60%> 
 +XSlope = 1 / YSlope 
 +</WRAP>
  
 +Now, there are two ways of drawing the lines :
 +<code>
            X = XSlope * Y            X = XSlope * Y
            Y = YSlope * X            Y = YSlope * X
 +</code>
  
-The question is, which one to use? if you use the wrong one, your line +The question is, which one to use? if you use the wrong one, your line will look like this : 
-will look like this :+ 
 +{{drawio>back2root:archives:denthor:part-03-line-02.png}}
  
         o         o
Ligne 158: Ligne 157:
 Instead of this : Instead of this :
  
 +{{drawio>back2root:archives:denthor:part-03-line-03.png}}
         ooo         ooo
            ooo            ooo
Ligne 163: Ligne 163:
  
 Well, the solution is as follows : Well, the solution is as follows :
 +
 +{{drawio>back2root:archives:denthor:part-03-line-04.png}}
  
                            *\``|``/*                            *\``|``/*
Ligne 170: Ligne 172:
                            */``|``\*                            */``|``\*
  
-If the slope angle is in the area of the stars (*) then use the first +If the slope angle is in the area of the stars (*) then use the first equation, if it is in the other section (`) then use the second one. 
-equation, if it is in the other section (`) then use the second one. + 
-What you do is you calculate the variable on the left hand side by +What you do is you calculate the variable on the left hand side by putting the variable on the right hand side in a loop and solving. Below is our finished line routine :
-putting the variable on the right hand side in a loop and solving. Below +
-is our finished line routine :+
  
 <code pascal> <code pascal>
Ligne 229: Ligne 229:
 </code> </code>
  
-Quite big, isn't it? Here is a much shorter way of doing much the same +Quite big, isn't it? Here is a much shorter way of doing much the same thing :
-thing :+
  
 <code pascal> <code pascal>
back2root/archives/denthor/part-03.txt · Dernière modification : 2023/05/18 21:07 de frater