Computer Science Canada column problem. |
Author: | MossyMossy [ Tue Oct 20, 2009 7:45 pm ] |
Post subject: | column problem. |
here is my code so far. Quote: var column :int locate (21, 1) for count : 1..80 put "-".. end for loop locate (23, 1) put " " locate (23, 1) put "Choose a column for the line between 1 and 80, and with -1:".. get column exit when column = -1 for row : 1..20 locate (row, column) put "+".. end for end loop After doing this, I have to make it on a slant now, I CANNOT figure out how to make a Decreasing angle, like a slant, so it go's down like " \ " instead of "|' Please help. |
Author: | copthesaint [ Wed Oct 21, 2009 12:16 am ] | ||
Post subject: | RE:column problem. | ||
Mod Edit: Don't just give the answer. kthxbai |
Author: | Zren [ Wed Oct 21, 2009 12:56 am ] | ||
Post subject: | Re: column problem. | ||
BASIC: This won't make an exact line, but it'll suffice for this. Think about what column you start, then which you'll end in. Then find the difference (delta). end - start = difference col6 - col4 = 2 columns apart Then consider the fact that a straight column ( | ) has a diffence of 0. We then think about the previous column (diff of 2) and realize we'll want to stretch the line over a total of 3 column values (4, 5, 6). So we'll be breaking it down into 3 different smaller lines (or breaking it up 2 times). We want to find out the y-value where we move to the next column. ![]() Figured it out? ADVANCED: If I were you, I'd try this first with Draw.Dot() before implementing it into your program. However, here's how to essentially draw a Aliased line. If you need help with how the two are relevant or any of the math, just ask. http://www.programmersheaven.com/2/FAQ-DIRECTX-Draw-Line Quote: How do I draw a line?
You can use the Windows GDI to draw a line as DirectDraw doesn't provide a line drawing function. If you want to draw a line using DirectX then use Breshenham's Line Drawing Algorithm to draw lines by joining Pixels. The pseudocode to draw a line between (x1, y1) and (x2, y2) a) Assume x=x1 and y=y1. Plot (x, y) Pixel b) Find the largest among (x2-x1) and (y2-y1) (To find the line is predominant on which axis) c) If(x2-x1) is the biggest (Line is predominant on X Axis)
|
Author: | MossyMossy [ Wed Oct 21, 2009 8:16 am ] |
Post subject: | Re: column problem. |
I've got it set for the user's input to make it for the vertical line, now i need to input it so that the user can select the row again but make it vertical. Quote: var column : int
locate (21, 1) for count : 1..80 put "-".. end for loop locate (23, 1) put " " locate (23, 1) put "Please enter a column for the line between 1 and 80, end it with -1:".. get column exit when row > 25 or column > 80 locate (row, column) put "+".. end for end loop I've got the vertical line down correct, but im stuck on the mathematical problem that is here, Quote: var row, column:int := 1 cls locate (21, 1) for count : 1..80 put "-".. end for put "please enter a row" get row put "please enter column" get column loop exit when row > 25 locate (column, row) put "*" .. row := row +1 column := column +1 end loop |
Author: | Zren [ Wed Oct 21, 2009 12:42 pm ] |
Post subject: | Re: column problem. |
Right now you have the variables row and column. or x1,y1. Now you automatically assume that the line is going have a "width" of 25 or so (25-row actually) since that's how many times you repeat column+1. First we want to find out column and row of where we will stop (aka x2, y2). |
Author: | MossyMossy [ Wed Oct 21, 2009 1:02 pm ] |
Post subject: | Re: column problem. |
Zren @ Wed Oct 21, 2009 12:42 pm wrote: Right now you have the variables row and column. or x1,y1. Now you automatically assume that the line is going have a "width" of 25 or so (25-row actually) since that's how many times you repeat column+1. First we want to find out column and row of where we will stop (aka x2, y2).
now how can i find that, make a variable called width? then subtract the column with row? |
Author: | Zren [ Wed Oct 21, 2009 2:45 pm ] | ||
Post subject: | Re: column problem. | ||
Slope is also usually in the form of a decimal. Also, this is for a line that is dependant on X (or Column). You need a formula that depends on Y (Rows). hint: I've already posted the difference. |