| My first progy 
 
	 
	
		| Author | Message |   
		| viperfan7 
 
 
 
 
 | 
			
				|  Posted: Tue Oct 03, 2006 9:27 am    Post subject: My first progy |  |   
				| 
 |  
				| here it is, (starts braging) I'm the most advanced turing programer in grade 10 at my school, the rest of my class is still at Draw.Oval, not even at variables. Please tell me if theres an easeir way to do this 
 
 Quote: 
View.Set ("nocursor, graphics:600;300")
 % NAME:viperfan7
 % TITLE:random pixle colour line
 % DATE:October 3
 % -----------------------------------------------------------------
 
 % DESCRIPTION:
 % -----------
 
 %enter clears the screen, arrow keys draw the line, my first from scratch progy
 
 % =========================
 % VAR DECLARATIONS
 % =========================
 
 const boarder := 10
 var c : string (1)
 var X, Y, C, CA, CB, CC, CD, CE, CF, CG, CH, CI, CJ, CK, CL, CM, CN, CO, CP, A, B : int
 X := Rand.Int (boarder, maxx - boarder)
 Y := Rand.Int (boarder, maxy - boarder)
 C := Rand.Int (1, maxcolour)
 CA := Rand.Int (1, maxcolour)
 CB := Rand.Int (1, maxcolour)
 CC := Rand.Int (1, maxcolour)
 CD := Rand.Int (1, maxcolour)
 CE := Rand.Int (1, maxcolour)
 CF := Rand.Int (1, maxcolour)
 CG := Rand.Int (1, maxcolour)
 CH := Rand.Int (1, maxcolour)
 CI := Rand.Int (1, maxcolour)
 CJ := Rand.Int (1, maxcolour)
 CK := Rand.Int (1, maxcolour)
 CL := Rand.Int (1, maxcolour)
 CM := Rand.Int (1, maxcolour)
 CN := Rand.Int (1, maxcolour)
 CO := Rand.Int (1, maxcolour)
 CP := Rand.Int (1, maxcolour)
 A := Rand.Int (0, 10)
 B := Rand.Int (0, 10)
 
 % ==========================
 % MAIN PROGRAM
 % ==========================
 
 
 loop
 c := getchar
 Draw.Dot (X, Y, C)
 Draw.Dot (X - 1, Y - 1, CA)
 Draw.Dot (X + 1, Y - 1, CB)
 Draw.Dot (X - 1, Y + 1, CC)
 Draw.Dot (X + 1, Y + 1, CD)
 Draw.Dot (X + 1, Y, CE)
 Draw.Dot (X, Y - 1, CF)
 Draw.Dot (X - 1, Y, CG)
 Draw.Dot (X, Y + 1, CH)
 Draw.Dot (X + 2, Y - 2, CI)
 Draw.Dot (X - 2, Y - 2, CJ)
 Draw.Dot (X - 2, Y + 2, CK)
 Draw.Dot (X + 2, Y + 2, CL)
 Draw.Dot (X, Y + 2, CM)
 Draw.Dot (X + 2, Y, CN)
 Draw.Dot (X, Y - 2, CO)
 Draw.Dot (X - 2, Y, CP)
 case c of
 label KEY_UP_ARROW :
 Y += 1
 if C < 127 then
 C += 117 - A else
 C -= 117 + B
 end if
 if CA < 127 then
 CA += 117 - A else
 CA -= 117 + B
 end if
 if CB < 127 then
 CB += 117 - A else
 CB -= 117 + B
 end if
 if CC < 127 then
 CC += 117 - A else
 CC -= 117 + B
 end if
 if CD < 127 then
 CD += 117 - A else
 CD -= 117 + B
 end if
 if CE < 127 then
 CE += 117 - A else
 CE -= 117 + B
 end if
 if CF < 127 then
 CF += 117 - A else
 CF -= 117 + B
 end if
 if CG < 127 then
 CG += 117 - A else
 CG -= 117 + B
 end if
 if CH < 127 then
 CH += 117 - A else
 CH -= 117 + B
 end if
 if CI < 127 then
 CI += 117 - A else
 CI -= 117 + B
 end if
 if CJ < 127 then
 CJ += 117 - A else
 CJ -= 117 + B
 end if
 if CK < 127 then
 CK += 117 - A else
 CK -= 117 + B
 end if
 if CL < 127 then
 CL += 117 - A else
 CL -= 117 + B
 end if
 if CM < 127 then
 CM += 117 - A else
 CM -= 117 + B
 end if
 if CN < 127 then
 CN += 117 - A else
 CN -= 117 + B
 end if
 if CO < 127 then
 CO += 117 - A else
 CO -= 117 + B
 end if
 if CP < 127 then
 CP += 117 - A else
 CP -= 117 + B
 end if
 label KEY_DOWN_ARROW :
 Y -= 1
 if C < 127 then
 C += 117 - A else
 C -= 117 + B
 end if
 if CA < 127 then
 CA += 117 - A else
 CA -= 117 + B
 end if
 if CB < 127 then
 CB += 117 - A else
 CB -= 117 + B
 end if
 if CC < 127 then
 CC += 117 - A else
 CC -= 117 + B
 end if
 if CD < 127 then
 CD += 117 - A else
 CD -= 117 + B
 end if
 if CE < 127 then
 CE += 117 - A else
 CE -= 117 + B
 end if
 if CF < 127 then
 CF += 117 - A else
 CF -= 117 + B
 end if
 if CG < 127 then
 CG += 117 - A else
 CG -= 117 + B
 end if
 if CH < 127 then
 CH += 117 - A else
 CH -= 117 + B
 end if
 if CI < 127 then
 CI += 117 - A else
 CI -= 117 + B
 end if
 if CJ < 127 then
 CJ += 117 - A else
 CJ -= 117 + B
 end if
 if CK < 127 then
 CK += 117 - A else
 CK -= 117 + B
 end if
 if CL < 127 then
 CL += 117 - A else
 CL -= 117 + B
 end if
 if CM < 127 then
 CM += 117 - A else
 CM -= 117 + B
 end if
 if CN < 127 then
 CN += 117 - A else
 CN -= 117 + B
 end if
 if CO < 127 then
 CO += 117 - A else
 CO -= 117 + B
 end if
 if CP < 127 then
 CP += 117 - A else
 CP -= 117 + B
 end if
 label KEY_LEFT_ARROW :
 X -= 1
 if C < 127 then
 C += 117 - A else
 C -= 117 + B
 end if
 if CA < 127 then
 CA += 117 - A else
 CA -= 117 + B
 end if
 if CB < 127 then
 CB += 117 - A else
 CB -= 117 + B
 end if
 if CC < 127 then
 CC += 117 - A else
 CC -= 117 + B
 end if
 if CD < 127 then
 CD += 117 - A else
 CD -= 117 + B
 end if
 if CE < 127 then
 CE += 117 - A else
 CE -= 117 + B
 end if
 if CF < 127 then
 CF += 117 - A else
 CF -= 117 + B
 end if
 if CG < 127 then
 CG += 117 - A else
 CG -= 117 + B
 end if
 if CH < 127 then
 CH += 117 - A else
 CH -= 117 + B
 end if
 if CI < 127 then
 CI += 117 - A else
 CI -= 117 + B
 end if
 if CJ < 127 then
 CJ += 117 - A else
 CJ -= 117 + B
 end if
 if CK < 127 then
 CK += 117 - A else
 CK -= 117 + B
 end if
 if CL < 127 then
 CL += 117 - A else
 CL -= 117 + B
 end if
 if CM < 127 then
 CM += 117 - A else
 CM -= 117 + B
 end if
 if CN < 127 then
 CN += 117 - A else
 CN -= 117 + B
 end if
 if CO < 127 then
 CO += 117 - A else
 CO -= 117 + B
 end if
 if CP < 127 then
 CP += 117 - A else
 CP -= 117 + B
 end if
 label KEY_RIGHT_ARROW :
 X += 1
 if C < 127 then
 C += 117 - A else
 C -= 117 + B
 end if
 if CA < 127 then
 CA += 117 - A else
 CA -= 117 + B
 end if
 if CB < 127 then
 CB += 117 - A else
 CB -= 117 + B
 end if
 if CC < 127 then
 CC += 117 - A else
 CC -= 117 + B
 end if
 if CD < 127 then
 CD += 117 - A else
 CD -= 117 + B
 end if
 if CE < 127 then
 CE += 117 - A else
 CE -= 117 + B
 end if
 if CF < 127 then
 CF += 117 - A else
 CF -= 117 + B
 end if
 if CG < 127 then
 CG += 117 - A else
 CG -= 117 + B
 end if
 if CH < 127 then
 CH += 117 - A else
 CH -= 117 + B
 end if
 if CI < 127 then
 CI += 117 - A else
 CI -= 117 + B
 end if
 if CJ < 127 then
 CJ += 117 - A else
 CJ -= 117 + B
 end if
 if CK < 127 then
 CK += 117 - A else
 CK -= 117 + B
 end if
 if CL < 127 then
 CL += 117 - A else
 CL -= 117 + B
 end if
 if CM < 127 then
 CM += 117 - A else
 CM -= 117 + B
 end if
 if CN < 127 then
 CN += 117 - A else
 CN -= 117 + B
 end if
 if CO < 127 then
 CO += 117 - A else
 CO -= 117 + B
 end if
 if CP < 127 then
 CP += 117 - A else
 CP -= 117 + B
 end if
 label KEY_ENTER :
 cls
 if C < 127 then
 C += 117 - A else
 C -= 117 + B
 end if
 if CA < 127 then
 CA += 117 - A else
 CA -= 117 + B
 end if
 if CB < 127 then
 CB += 117 - A else
 CB -= 117 + B
 end if
 if CC < 127 then
 CC += 117 - A else
 CC -= 117 + B
 end if
 if CD < 127 then
 CD += 117 - A else
 CD -= 117 + B
 end if
 if CE < 127 then
 CE += 117 - A else
 CE -= 117 + B
 end if
 if CF < 127 then
 CF += 117 - A else
 CF -= 117 + B
 end if
 if CG < 127 then
 CG += 117 - A else
 CG -= 117 + B
 end if
 if CH < 127 then
 CH += 117 - A else
 CH -= 117 + B
 end if
 if CI < 127 then
 CI += 117 - A else
 CI -= 117 + B
 end if
 if CJ < 127 then
 CJ += 117 - A else
 CJ -= 117 + B
 end if
 if CK < 127 then
 CK += 117 - A else
 CK -= 117 + B
 end if
 if CL < 127 then
 CL += 117 - A else
 CL -= 117 + B
 end if
 if CM < 127 then
 CM += 117 - A else
 CM -= 117 + B
 end if
 if CN < 127 then
 CN += 117 - A else
 CN -= 117 + B
 end if
 if CO < 127 then
 CO += 117 - A else
 CO -= 117 + B
 end if
 if CP < 127 then
 CP += 117 - A else
 CP -= 117 + B
 end if
 end case
 end loop
 
 
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| TokenHerbz 
 
  
 
 
 | 
			
				|  Posted: Tue Oct 03, 2006 1:05 pm    Post subject: (No subject) |  |   
				| 
 |  
				| Yes, there is an easier way. 
 Attempt to learn function and proc's first, and get into some for loops and array's
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| md 
 
  
 
 
 | 
			
				|  Posted: Tue Oct 03, 2006 7:49 pm    Post subject: (No subject) |  |   
				| 
 |  
				| Actually, loops and arrays would be a better start... but yes there is a better way. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| ericfourfour 
 
 
 
 
 | 
			
				|  Posted: Tue Oct 03, 2006 10:02 pm    Post subject: (No subject) |  |   
				| 
 |  
				| Its pretty good for a first program. Next you should learn counted (for) loops because they are not that hard to learn and it will lower the amount of lines you write. After that you should learn arrays. They will drastically lower the amount of lines in the program that you wrote. 
 Anyway, here is what your program thing will look similar to (excluding the pattern of dots, these are random) a few weeks-months from now if you continue programming.
 
 
 	  | code: |  	  | 
proc draw_sparkly (x, y, width, height : int)
 for i : x .. x + width - 1
 for j : y .. y + width - 1
 Draw.Dot (i, j, Rand.Int (1, maxcolour))
 end for
 end for
 end draw_sparkly
 var x := Rand.Int (100, maxx - 100)
 var y := Rand.Int (100, maxy - 100)
 var width := 5
 var height := 5
 var chars : array char of boolean
 var button_down := false
 loop
 Input.KeyDown (chars)
 button_down := true
 if chars (KEY_UP_ARROW) then
 y += 1
 elsif chars (KEY_DOWN_ARROW) then
 y -= 1
 elsif chars (KEY_LEFT_ARROW) then
 x -= 1
 elsif chars (KEY_RIGHT_ARROW) then
 x += 1
 elsif chars (KEY_ENTER) then
 cls
 button_down := false
 else
 button_down := false
 end if
 if button_down then
 draw_sparkly (x, y, width, height)
 end if
 delay (10)
 end loop
 
 | 
 
 As you can see, with some of the above suggestions you could reduce all of that to 35 lines (7%) and I'm sure you could get lower.
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| viperfan7 
 
 
 
 
 | 
			
				|  Posted: Wed Oct 04, 2006 9:09 am    Post subject: (No subject) |  |   
				| 
 |  
				| thx! I'll study it, thx for the help again |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Clayton 
 
  
 
 
 | 
			
				|  Posted: Wed Oct 04, 2006 9:17 am    Post subject: (No subject) |  |   
				| 
 |  
				| CompSci.ca's Turing section has its own Turing Walkthrough composed of tutorials written by other members, take a look at the tutorials within for help with your coding  |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Zacebdal 
 
 
 
 
 | 
			
				|  Posted: Tue Oct 17, 2006 9:24 pm    Post subject: Interesting |  |   
				| 
 |  
				| That is very tedious programming and, like others have mentioned, you should learn loops and...arrays? im not too sure myself about arrays, im just a newbe like you right now. but nonetheless its ok for a first program and just keep on working and definately take a look at that tutorial for loops and things like that. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Prince Pwn 
 
 
 
 
 | 
			
				|  Posted: Tue Oct 17, 2006 9:41 pm    Post subject: (No subject) |  |   
				| 
 |  
				| Press "F2" in Turing before you copy and paste your code. Makes it look neater =) |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		|  |  
 |