English Amiga Board Amiga Lore



Go Back   English Amiga Board > Coders > Coders. General > Coders. Tutorials

 
 
Thread Tools
Old 08 January 2012, 17:07   #41
diablothe2nd
Registered User

diablothe2nd's Avatar
 
Join Date: Dec 2011
Location: Northampton, UK
Age: 31
Posts: 1,232
my algrebra sucks.

I'm trying to create a variable that counts from 255 down, in 1 step increments.

n=n-1 seems to take care of the negative step... but its getting the starting number of 255 in there somewhere that's screwing with my head

closest i've got is:

x=255
n=n-1+x

which is obviously wrong. I know there's a simple answer but I've been thinking about this too hard i think and got my head stuck in it's own loop
diablothe2nd is offline  
AdSense AdSense  
Advertisement:
Old 08 January 2012, 17:10   #42
diablothe2nd
Registered User

diablothe2nd's Avatar
 
Join Date: Dec 2011
Location: Northampton, UK
Age: 31
Posts: 1,232
n=n-1+255?


ugh maybe i'm doing this wrong and simply need to make N a number that goes from 255-0 in another way.

multiple for and next loops dont seem to all work at once which i why i'm declaring them as variables first.

Last edited by prowler; 08 January 2012 at 22:48. Reason: Back-to-back posts merged.
diablothe2nd is offline  
Old 08 January 2012, 17:43   #43
diablothe2nd
Registered User

diablothe2nd's Avatar
 
Join Date: Dec 2011
Location: Northampton, UK
Age: 31
Posts: 1,232
here's the code, perhaps it'll explain more:

Code:
y=255-(n=n+1)
For z=255 to 0 Step -1:Line 0,y,320,y,z,1:Next
which *should* simply draw a gradient of white to black from bottom to top.
diablothe2nd is offline  
Old 08 January 2012, 22:27   #44
P-J
EAB veteran... Honest!
P-J's Avatar
 
Join Date: Mar 2001
Location: Warwickshire, England
Age: 34
Posts: 1,144
Send a message via MSN to P-J
Quote:
Originally Posted by diablothe2nd View Post
here's the code, perhaps it'll explain more:

Code:
y=255-(n=n+1)
For z=255 to 0 Step -1:Line 0,y,320,y,z,1:Next
which *should* simply draw a gradient of white to black from bottom to top.
This makes no sense dude. You want to draw from Y-line 255 to Y-Line 0 one by one, have the colour value also go from 255 to 0 as you come back up?

Why not just :

Quote:
For y=255 to 0 Step -1:Line 0,y,320,y,y,1:Next
Also, you said earlier that multiple FOR/NEXT loops wouldn't do what you wanted. Were you using nested loops?
P-J is offline  
Old 08 January 2012, 22:31   #45
diablothe2nd
Registered User

diablothe2nd's Avatar
 
Join Date: Dec 2011
Location: Northampton, UK
Age: 31
Posts: 1,232
Quote:
Originally Posted by P-J View Post
Why not just :

Code:
For y=255 to 0 Step -1:Line 0,y,320,y,y,1:Next
Also, you said earlier that multiple FOR/NEXT loops wouldn't do what you wanted. Were you using nested loops?
Gah! so simple to me now. i was totally overthinking it and got myself in a tizzy.

thanks

RE:loops, no i think i was simply misunderstanding how they work.

say though that the Z and Y values were opposite. one climbing to 255, one reducing. how would i go about doing that?

much obliged!

Last edited by diablothe2nd; 08 January 2012 at 22:35. Reason: edited many times cos i'm tired and keep messing up :P
diablothe2nd is offline  
Old 08 January 2012, 22:35   #46
P-J
EAB veteran... Honest!
P-J's Avatar
 
Join Date: Mar 2001
Location: Warwickshire, England
Age: 34
Posts: 1,144
Send a message via MSN to P-J
Quote:
Originally Posted by diablothe2nd View Post
say though that the Z and Y values were opposite. one climbing to 255, one reducing. how would i go about doing that?
Plain version

Code:
For y=255 to 0 Step -1:Line 0,y,320,y,(255 - y),1:Next
Better version for learning

Code:
for y=255 to 0 step -1
    z = (255 - y)   // So if y = 255, z = 0. If y = 254, z = 1 (etc...)
    line 0, y, 320, y, z, 1
next
A good way to do this sort of stuff is with a pen and paper. Write down the values you want side by side, and then try and work out a formula that links them. In this sort of case it's not necessary, but as you do game programming you could come up against some real sticky situations that need a lot of maths. That's when I turn to the trusty pen and paper and just draw it out.

In this case you could also use some kind of 8-bit NOT if your language supports in. NOT(255) would be 0, NOT (254) would be 1 and so on. But it's worth getting an understanding of binary to understand how that works. Not really worth it if you're coding in basic since that's all taken care of with built-in stuff.

Hope this helps.

Last edited by P-J; 08 January 2012 at 22:44.
P-J is offline  
Old 08 January 2012, 22:40   #47
diablothe2nd
Registered User

diablothe2nd's Avatar
 
Join Date: Dec 2011
Location: Northampton, UK
Age: 31
Posts: 1,232
effin' AWESOME! just what the doctor ordered

algebra was never my strong point. and i've never come across For and Next functions before so wasn't sure what i could get away with.
diablothe2nd is offline  
Old 08 January 2012, 22:54   #48
P-J
EAB veteran... Honest!
P-J's Avatar
 
Join Date: Mar 2001
Location: Warwickshire, England
Age: 34
Posts: 1,144
Send a message via MSN to P-J
Quote:
Originally Posted by diablothe2nd View Post
algebra was never my strong point.
Me neither. When I left school and spent 23 hours a day coding on the Amiga (and then PC), I learnt more algebra in a few days than I was ever able to learn at school.

Have you used debuggers before? I think Blitz has one, and possibly a better replacement somewhere. It's a useful learning tool because you can (for example) add a watch on a variable, step through your code, and then see how that variable is affected by each operation. It's great to get into the habit of using one, especially if you plan to progress to coding in assembly.
P-J is offline  
Old 08 January 2012, 22:55   #49
diablothe2nd
Registered User

diablothe2nd's Avatar
 
Join Date: Dec 2011
Location: Northampton, UK
Age: 31
Posts: 1,232
just to add to your edit

Quote:
in this case you could also use some kind of 8-bit NOT if your language supports in. NOT(255) would be 0, NOT (254) would be 1 and so on. But it's worth getting an understanding of binary to understand how that works. Not really worth it if you're coding in basic since that's all taken care of with built-in stuff.
ironically i'm quite knowledgable in both binary and hex. The difficulty for me though is i've never done any programming more advanced than editing configs, so dont know what function to choose, and more specifically when it should be used.

the pdf of functions is helping though. I guess it's like CAD, or any graphical program that i'm completely fluent in. There are many ways of doing it, but figuring out the most efficient way is only gained from experience. If i wanted to draw say a hexagon on screen i wouldn't know whether or not to draw all 6 lines using 6 line parameters... or use 1 and somehow copy and manipulate it! in CAD it'd be 2 key presses, 1 click and typing a single dimension... total time taken, 3 seconds :P

its so frustrating for me, cos i've got a near photographic/videographic image my head of everything i want the end user to see and do... from launching the game to finishing/completing it. putting that down into images is a piece of piss for me. coding it though.... phew! I've noticed you programmers start out with a vague idea and just go with the flow. I think my line of thinking of "this is what it will be", even though i'm considering limitations of hardware, is my problem. i simply have no knowledge of the tools infront of me to back trace.

Last edited by diablothe2nd; 08 January 2012 at 23:01.
diablothe2nd is offline  
Old 09 January 2012, 04:25   #50
Thorham
Computer Nerd

Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 37
Posts: 1,826
Going from dark to light:
Code:
for y=0 to 255 step 1
    line 0, y, 320, y, y, 1
next
Going from light to dark:
Code:
z=255
for y=0 to 255 step 1
    line 0, y, 320, y, z, 1
    z=z-1
next
Note that 'step 1' may be removable (most basic dialects default to 'step 1' for 'for next' loops).
Quote:
Originally Posted by diablothe2nd View Post
I've noticed you programmers start out with a vague idea and just go with the flow.
Not really, because that is the worst way to write programs; you really have to think it out properly, or you'll end up with a mess. It's similar to the good (bad!) old: 'Type first, think later' way of programming.

Last edited by Thorham; 09 January 2012 at 04:52.
Thorham is offline  
Old 09 January 2012, 09:13   #51
pmc
rebooting...
pmc's Avatar
 
Join Date: Apr 2007
Location: Elsewhere
Posts: 1,593
Quote:
Originally Posted by Thorham
Not really, because that is the worst way to write programs; you really have to think it out properly, or you'll end up with a mess. It's similar to the good (bad!) old: 'Type first, think later' way of programming.
Agree.

Think first, code second!

This gets quicker as you get more experienced as you start getting to the stage where you kind of know how to go about coding something as you're coding, or at least a few split seconds before you write the actual code. That's how it feels to me at least.

But if something's larger, more unfamiliar or new the first thing I do is spend time coding things "in my head" first.
pmc is offline  
Old 09 January 2012, 10:12   #52
Graham Humphrey
Moderator
Graham Humphrey's Avatar
 
Join Date: Jul 2004
Location: Norwich, Norfolk, UK
Age: 27
Posts: 9,978
Quote:
Originally Posted by diablothe2nd View Post
my first hurdle seems to be colour codes. the circle command syntax has only one spot on the end for a colour code and i can't find the correct syntax for a non grey colour. i've tried using RGB hex values, both with and without a hash (#) but it's not having it.
'Colour' in this case has to be a colour number from the palette you're using. If you're using 256 colours for example you have to pick a number from 0 to 255 and the circle will be drawn using that colour register.
Graham Humphrey is offline  
Old 09 January 2012, 12:36   #53
diablothe2nd
Registered User

diablothe2nd's Avatar
 
Join Date: Dec 2011
Location: Northampton, UK
Age: 31
Posts: 1,232
thanks for clearing that one up graham
diablothe2nd is offline  
AdSense AdSense  
Advertisement:
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
I want to learn about Workbench mancity support.Apps 26 21 May 2012 06:14
Wanting to learn Blitz Basic on real Amiga Adropac2 request.Other 20 20 August 2008 07:30
Blitz Basic 2.1 problem with reading a CD32 joypad Graham Humphrey Coders. General 10 09 August 2008 09:24
How did you learn to program bippym Coders. General 80 01 April 2007 19:25
A little lesson to learn about Pong MethodGit Retrogaming General Discussion 7 07 December 2001 13:03

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 16:22.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Page generated in 0.17311 seconds with 14 queries