Qbasicnews.com

Full Version: stuck...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
k, i need to figure out, for one part of a program, how to, with an input, allow the user of the program to scale the size of the screen..

for instance, to scale the screen (graph) to 10, i used -

For xpixel = 0 to 400
xscale = (xpixel/20) -10

...this is just part of a loop, but it scales the screen from

-10 _______________0 ________________10 (xaxis)

..im stuck on how to scale the screen to something other than ten. I know im gonna use a variable, say SCL, .. I tried doing

xscale = (xpixel/ (2* SCL)) - SCL, because this seems to be what the first equation is doing....its dividing the xpixel by twice of the value you want to scale the screen to (10), and subtracting this value after it is divided by xpixe... Any suggestions...?
Hello
Interesting. If you use normal qb screen modes (aka screen 1-13) then there's a command: window (x,y)-(x1,y1) Here's an example
Code:
'Set screen mode
SCREEN 12
'Get pi. It returns smth like 3.1415...
Pi! = ATN(1) * 4
'set screen to cordinate system. the smallest point on x axis is -4
'(left screen border) and on y axis(screen upper border) -3. the biggest
'point coordinates are x 4 and y 3
WINDOW (-4, -3)-(4, 3) 'but you can put bigger numbers h
'ere too. like: (-320,-240)-(320,240)
'Just do a loop
FOR i = 0 TO (2 * Pi!) STEP .01 '<- the bigger this number is, more sloppy
                                'the citcle is.
   'in qb full cicrle is 2 times Pi.
   'draw circle to the screen.
   PSET (SIN(i), COS(i)), 4
NEXT

Is it what you mean?
i think this is what you're after:
[syntax="qbasic"]DEFINT A-Z

DECLARE Function ScaleTo!(number AS SINGLE, oldmax AS SINGLE, newmax AS SINGLE)

DIM n AS SINGLE
DIM m AS SINGLE
DIM scale AS SINGLE

'If the maximum(m) is 100, then the number(n), if 50, should always be @ half-way
m = 100
n = 50

scale=70

SCREEN 12

LINE (0,0)-(0,10),15
'm+2 so the lines don't take up any space....gotta think 3d for a sec
LINE (m+2,0)-(m+2,4), 7

PSET (n+1, 2), 1

nx! = ScaleTo(n,m,scale)

LINE (scale+2,5)-(scale+2,10), 8

PSET (CINT(nx!), 7), 4

END

Function ScaleTo!(number AS SINGLE, oldmax AS SINGLE, newmax AS SINGLE)

ScaleTo! = (number / oldmax) * newmax

END FUNCTION
[/syntax]

I think that's what ur after......

Oz~
ok lets seee if I can explain this a little bit further. My...whole project aim is to design a program in which the user inputs maximum and minimum values of the axis...and also inputs the coordinates of a parabola..

Ive have this to work with:

SCREEN 12

'draw x & y axis'
LINE (200,0)-(200,400)
LINE (0,200) - (400,200)

FOR xpixel = 0 to 400
xscale = Thiss..is where im stuck, which is a little discouraging because its the first thing i come across that i have to do work & i dont get it..

..so I'm gonna have to use the users inputs in that equation for xscale.

What i have right now is the code that scales the axis to 10 max and ten min for both x and y axis' and it draws a parabola :

SCREEN 12

'draw x & y axis'
LINE (200,0)-(200,400)
LINE (0,200) - (400,200)

FOR xpixel = 0 to 400
xscale = (xpixel/200-10
yscale - xscale ^2
ypixel = 20 * (10-yscale)
circle (xpixel, ypixel),2
NEXT xpixel

So basically, given pretty much the same format, unless theres an easier way, I need to write the same code up there except adjust it so that the user can control the axis' values and what the parabola looks like...
[syntax="qbasic"]
TYPE ScaleType
min AS SINGLE
max AS SINGLE
END TYPE

DECLARE FUNCTION ScaleIt! (number AS SINGLE, old AS ScaleType, new AS ScaleType)

DIM Originalx AS ScaleType
DIM Originaly AS ScaleType

'400x400
Originalx.min = -200
Originaly.min = -200
Originalx.max = 200
Originaly.max = 200

DIM Nextx AS ScaleType
DIM Nexty AS ScaleType

PRINT "* Scale To: *"
INPUT " Minimum-x: ", NextX.min
INPUT " Maximum-x: ", NextX.max
INPUT " Minimum-y: ", NextY.min
INPUT " Maximum-y: ", NextY.max

'Wait for a key to be pressed......
a$ = INPUT$(1)

CLS

SCREEN 12

'As VonGodric said, use window
WINDOW (originalx.min, originaly.min)-(originalx.max, originaly.max)

'Dotted grid
FOR px = -200 to 200 STEP 5
FOR py = -200 to 200 STEP 5
PSET (px, py), 7
NEXT py
NEXT px

'Zero is our Origin now....draw axis
LINE (originalx.min, 0)-(originalx.min, 0), 15
LINE (0, originaly.min)-(0, originaly.max), 15

'parabla formula here

END

FUNCTION ScaleIt! (number AS SINGLE, old AS ScaleType, new AS ScaleType)

osize! = old.max - old.min + 1
nsize! = new.max - new.min + 1

ScaleIt = (number / osize!) * nsize!


END FUNCTION[/syntax]

Oz~