pascal assignment lazarus / 61-Beginners ---------------------------------------------------------------------- user4592357 · 2016-04-21 19:14 i'd really appreciate if someone helped me with this. pretty new to pascal graphics, don't know what's wrong.. thanks in advance.. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses crt,graph;const xmax=640;ymax=480; type mat=array[0..10,0..10] of integer;     vec=array[0..10] of integer; var f:file of integer;zr,n:byte;m,t,k:integer;c:char;    zx0,zx1,zy0,zy1:real;y: array[0..2] of real;    graphdriver,graphmode:integer;    j,i:integer; l,Q:byte;    x:mat;        z,d:vec; function baz (a,b:integer): boolean;beginif (a mod b=2) and (a>0) thenbaz:=trueelse baz:=falseend; {===============MENU=====================}procedure menu(c1,c2,c3,c4:byte);begin {cleardevice;}  setbkcolor(0); {==MeC==}   Line(324,12,560,120); line(560,120,560,350); line(560,350,324,458); L ine(324,458,90,350); line(90,350,90,120); line(90,120,324,12); setfill style(14,5);    {===4 hat ==}setcolor(4); line(320,20,320,226); line(3 20,226,100,128); line(100,128,320,20); setfillstyle(1,4); setcolor(4);  line(328,20,328,226); line(328,226,552,128); line(552,128,328,20);set fillstyle(1,4);  line(328,236,328,450); line(328,450,552,342); line(55 2,342,328,236);  setfillstyle(1,4);   setcolor(4); line(320,234,320,45 0); line(320,450,100,342); line(100,342,320,234); setfillstyle(1,4);    {====2 poqr===}  setcolor(15); line(124,180,268,230); line(268,230,12 4,278); line(124,278,124,180); setfillstyle(1,15);  setcolor(15); line (526,180,526,278); line(526,278,380,230); line(380,230,526,180); setfi llstyle(1,15);      {---------------}  settextstyle(6,0,4); setcolor(c 1);outtextxy(210,130,'Pahanj');setcolor(c2);outtextxy(360,130,'Lucum') ;setcolor(c3);outtextxy(170,340,'Animation');setcolor(c4);outtextxy(36 0,340,'Avart');end; {-------------Pahanj----------------} procedure pahanj;begin cleardevice;settextstyle(3,0,5);setcolor(15);outtextxy(120,50,'Trvac en n amboghj...');{-----------------------------------}readkey end;{-- ---------------------------------------------------------------------- ------} {----------------Lucum------------}{==procedure lucum;begin==} procedure vector (n2:integer;x2:vec);beginfor i:=1 to n2 doreadln(x2[i]);end;beginrepeat write ('m='); readln (m)until (m>1) and (m<=10);for i:=1 to m do vector (m,z);for j:=1 to m do x[i,j] := z [j];l:=0;for i:=1 to m dofor j:=1 to m do if baz (x[i,j],5)= true then  l:=l+1; write('l=',l); end.   cleardevice;settextstyle(3,0,5);setcolo r(15);outtextxy(120,50,'Xndri Lucum@');  readkey; end; procedure animation; var   X, Y:array [1..400] of integer;   i, Gx, Gy, Gy1, Gd, Gm: integer;   z:byte;BEGIN     Gd:=Detect;     InitGraph(Gd, Gm, 'X:\BP');     randomize;     Gx:=GetMaxX;     Gy:=GetMaxY;     SetColor(15);    for i:=1 to 200 do                begin                   X[i]:= random(Gx);                     Y[i]:= random(Gy div 1);                     PutPixel(X[i],Y[i],15)                end;             repeat                inc (z);                for i:=1 to 200 do                        begin                             if (Y[i] < Gy) and (GetPixel(X[i],Y[i]+1)= 0)                              then                                        begin                                           PutPixel(X[i], Y[i],0);                                           Y[i]:= Y[i]+1;                                           PutPixel(X[i], Y[i],15)                                      end                                else                                      begin               if Y[i] < 20 then               begin               PutPixel(X[i], Y[i],0);               end else             begin                  Line(X[i] - 3, Y[i] - 2, X[i] + 3, Y[i] + 2);                  Line(X[i] + 3, Y[i] - 2, X[i] - 3, Y[i] + 2);                Line(X[i], Y[i] - 3, X[i], Y[i] + 3);               end;                                              Y[i]:={random(Gy div 40)}0;                                             X[i]:= random(Gx);               PutPixel(X[i], Y[i], 15);          end;     end;          settextstyle(7,0,7);          outtextxy(60,150,'HAPPY ');          outtextxy(300,250,'NEW');          outtextxy(500,350,'YEAR');          settextstyle(7,0,6);          outtextxy(60,470,'Thanks For Watching');     until keypressed;    readkey; END; begininitgraph(m,t,'');  repeat k:=1;  cleardevice;repeat case k of1:menu(15,4,4,4);2:menu(4,15,4,4);3:menu( 4,4,15,4);4:menu(4,4,4,15);end;c:=readkey; if ord(C)=80 then k:=k-1;if ord(C)=72 then k:=k+1;if k=0 then k:=4;if k=5 then k:=1;until ord(c)=13; case k of1:pahanj;2:lucum;3:animation;end;until k=4; end. ---------------------------------------------------------------------- eny · 2016-04-21 19:59 Quote from: gainnew on April 21, 2016, 09:14:50 pmi'd really appreciate if someone helped me with this. pretty new to pascal graphics, don't know what's wrong..The question is missing. ---------------------------------------------------------------------- Bart · 2016-04-21 20:25 Not related to the question (if any), but useing both crt and graph unit is not recommended in fpc. Bart ---------------------------------------------------------------------- user4592357 · 2016-04-22 02:53 Thequestion is that I don't understand why doesn't this code work fully??? Actually I can input the number of vector elements and the elements too, but then some things shoukdnbe printed on the screen but they won't ... And I don't know why So whixh one to usr?  Graph.or CRT? ---------------------------------------------------------------------- Handoko · 2016-04-22 04:37 Please provide more information. Like what is the error message, what is the result you expect and what is the output or it's better if you can provide screenshots. We can't guess what you want. ---------------------------------------------------------------------- CuriousKit · 2016-04-22 04:44 You need to get into the habit of commenting your code better - it's very unclear what you're trying to do exactly. If you're struggling to get a particular component or suite of functions to work, start with something simple, like a single line or triangle, for example.  Once you get that working, you can build up from there. P.S. Instead of "k:=k+1;" or "k:=k-1;", use "Inc(k);" and "Dec(k);". ---------------------------------------------------------------------- molly · 2016-04-22 05:19 @gainnew: If you start formatting your code properly, then the answer is in the beauty that emerged from it. ---------------------------------------------------------------------- Thaddy · 2016-04-22 06:57 Which of the two programs in the same file are you trying to run? Frankly, it's a mess. Use ptop on it first, as suggested. ---------------------------------------------------------------------- molly · 2016-04-22 07:12 ^^ let's say that the program works as intended  (except for x2 that needs to be declared as var parameter). So, after formatting the code properly, it is still a matter of formulating a sensible question or presenting a meaningful error- report. If not then the source does exactly what it was programmed to do. ---------------------------------------------------------------------- Thaddy · 2016-04-22 09:09 Quote from: molly on April 22, 2016, 09:12:11 am If not then the source does exactly what it was programmed to do. Yup If it compiles it works as intended If you know the syntax, that is... Ok 'nough said. Let's wait if we get the feedback needed to help. (you and I already know that - because Watson told me you also have done some research into this code - , but formulating the proper question is also an art) Thing is: I have several ways to make this work, not only var... And I am not sure which one he means ---------------------------------------------------------------------- user4592357 · 2016-04-26 17:23 Thanks for the replies. But I only see only some part of code working. Where I enter number and an array is created with that number of elements and then I enter the values... After that it stops and I don't know what's wrong. ---------------------------------------------------------------------- molly · 2016-04-26 18:42 Quote from: gainnew on April 26, 2016, 07:23:24 pmBut I only see only some part of code working. And if you properly format oyur code, you could see that even before running the compiled program. QuoteWhere I enter number and an array is created with that number of elements and then I enter the values... After that it stops and I don't know what's wrong. Oh, that one is easy  ... in line 133 you tell your program to end. Ergo, the program is terminated, just as you told it to. Other than that, i just lost my psychic abilities due to a heavy rainstorm. ---------------------------------------------------------------------- molly · 2016-04-26 19:00 It might help if you are able to express what you _think_ your program (there are currently two completely seperate programs (and a half) of them inside your code) should do, and in what specific order you expected things to happen. With all respect, you made such a mess of your code (hint: formatting, also clearly shows you where one program ends and the other one begins, except for the 'extra' half ) that it is unclear what the intentions - of you the programmer - are. If you ask for help, then please keep in mind that no-one here is in the habit of analyzing _your code_ _for you_. Right now you are playing a guessing game like hints, and although that is fun to play with friends, it usually is only fun with a couple of bottles of wine (but that usually produces very messy code  ). ---------------------------------------------------------------------- user4592357 · 2016-04-27 11:02 i don't understand why i get "error in statement" for the procedure??? ---------------------------------------------------------------------- user4592357 · 2016-04-27 15:05 actually i corrected the code, now it compiles but i get "BGI Error:- Graphics not Initialized(Use Initgraph)" how do i correct this??? ---------------------------------------------------------------------- Ñuño_Martínez · 2016-04-27 17:05 The error message itself is answering to you: "BGI Error:- Graphics not Initialized(Use Initgraph)". ---------------------------------------------------------------------- user4592357 · 2016-04-27 18:29 Well but idk how to correct that ---------------------------------------------------------------------- molly · 2016-04-27 18:36 Quote from: gainnew on April 27, 2016, 08:29:25 pmWell but idk how to correct that It seems you have difficulty to comprehend that you (originally) have two completely separate programs. The compiler is only able to understand one of them, and therefor will not compile/execute any of the second part. You failed to produce current code, you failed to describe what you expect your code to do (and more importantly in what order), yet you expect others to give you a solution for the problems that arise from your code... ---------------------------------------------------------------------- user4592357 · 2016-04-27 18:57 One doesn't work without the other one so idk how to compile and run the separately ---------------------------------------------------------------------- ab1jx · 2016-04-27 19:46 For one thing outtextxy and write don't belong together at all, one is graphics mode and one is text mode. You need initgraph in the graphics section, but it looks like you copied and pasted from multiple things into your posting. ---------------------------------------------------------------------- molly · 2016-04-27 20:09 Quote from: ab1jx on April 27, 2016, 09:46:04 pmFor one thing outtextxy and write don't belong together at all, one is graphics mode and one is text mode. That's not entirely correct, but i get the gist of your remark. e.g. you would have to know a bit more how to know how to reroute you text input and output. ---------------------------------------------------------------------- molly · 2016-04-28 15:24 Quote from: gainnew on April 27, 2016, 08:57:51 pmOne doesn't work without the other one so idk how to compile and run the separately I have not the faintest idea what the above sentence entails :-S idk, maybe this works for you ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program blue30; uses   crt,  graph;  const   xmax = 640;  ymax = 480;  type   mat = array[0..10,0..10] of integer;  vec = array[0..10] of integer;  var   f         : file of integer;  zr,n      : byte;  m,t,k     : integer;  c         : char;  zx0, zx1,  zy0, zy1  : real;  y       : array[0..2] of real;  graphdriver,  graphmode : integer;  j,i     : integer;  l,Q       : byte;  x         : mat;  z,d       : vec;  function baz (a,b:integer): boolean;begin  if (a mod b=2) and (a>0)   then baz:=true  else baz:=falseend;  //procedure vector (n2:integer;x2:vec);procedure vector (n2:integer;var x2:vec);begin  for i:=1 to n2   do readln(x2[i]);end;  procedure ask;begin  repeat   write ('m=');     readln (m)  until (m>1) and (m<=10);   for i:=1 to m   do  vector (m,z);   for j:=1 to m   do x[i,j] := z [j];   l:=0;   for i:=1 to m do    for j:=1 to m do      if baz (x[i,j],5)= true     then l:=l+1;   write('l=',l);end;   {===============MENU============= ========} procedure menu(c1,c2,c3,c4:byte);begin {cleardevice;}  setbkcolor(0);   {==MeC==}  Line(324,12,560,120);  line(560,120,560,350);  line(560,350,324,458);  Line(324,458,90,350);  line(90,350,90,120);  line(90,120,324,12);   setfillstyle(14,5);   {===4 hat ==}   setcolor(4);  line(320,20,320,226);  line(320,226,100,128);  line(100,128,320,20);   setfillstyle(1,4);  setcolor(4);  line(328,20,328,226);  line(328,226,552,128);  line(552,128,328,20);   setfillstyle(1,4);  line(328,236,328,450);  line(328,450,552,342);  line(552,342,328,236);   setfillstyle(1,4);  setcolor(4);   line(320,234,320,450);  line(320,450,100,342);  line(100,342,320,234);  setfillstyle(1,4);   {====2 poqr===}  setcolor(15);  line(124,180,268,230);  line(268,230,124,278);  line(124,278,124,180);  setfillstyle(1,15);   setcolor(15);  line(526,180,526,278);  line(526,278,380,230);  line(380,230,526,180);  setfillstyle(1,15);   {---------------}  settextstyle(6,0,3);   setcolor(c1);  outtextxy(160,115,'Little');  setcolor(c2);  outtextxy(340,115,'Critters');  setcolor(c3);  outtextxy(170,340,'Snow');  setcolor(c4);   outtextxy(360,340,'Exit'); end;   {-------------Pahanj----------------} procedure pahanj;begin   RestoreCrtMode;  Ask;  SetGraphMode(GetGraphMode);    cleardevice;  settextstyle(3,0,5);  setcolor(15);  outtextxy(120,50,'Little lord Fauntleroy...');   readkey end; {------------------------------------- -----------------------------------------}   {----------------Lucum--- ---------} procedure lucum;// Critters from swag - Nossamanconst   radcon:real=0.017453292;totalbodies=22;speedfactor:real=30;type   debris=record mass,dir,speed,x,y:real;oldx,oldy:integer;end;var   b:array[1..totalbodies]of debris;errcode: integer;ch:char;  i,countdow n,walls,delayfactor:integer;stampede:boolean;bait:debris;function theta(p1x,p1y,p2x,p2y:real):real; var t,lx,ly:real;begin  lx:=p2x-p1x; ly:=p2y-p1y; if((lx=0)and(ly=0))then theta:=0 else begin if lx=0   then t:=arctan(ly/0.0000000001)/radcon else t:=arctan(ly/lx)/radcon; if lx<0   then t:=t+180; if((lx>=0)and(ly<0))then t:=t+360; theta:=abs(t); end;end;function hypotenuse(x1,y1,x2,y2:real):real;var h1,h2:real;begin  hypotenuse:=sqrt(sqr(abs(x1-x2))+sqr(abs(y1-y2)));end;procedure initcritter; var i:integer; g:real;begin  for i:=1 to totalbodies do begin b[i].x:=random(600)+20; b[i].y:=random(440)+  20;b[i].dir:=random(359)+1; b[i].speed:=(random(100)+50)/speedfactor;b[i].mass  :=random(50)+100;b ait.x:=random(600)+20;bait.y:=random(440)+20;bait.mass:=100;   end; delayfactor:=round(500/b[1].speed);end; procedure orbit(a:integer); var i,a2,min,xmax,ymax:integer; t,m1,m2,ax,ay,newdir,rate:real;begin  if a=1 then a2:=totalbodies else a2:=a-1;if (stampede and (a=1)) then begin   t:=theta(b[a].x,b[a].y,bait.x,bait.y); m2:=hypotenuse(b[a].x,b[a].y,bait.x,bait.y);  m1:=bait.mass; rate:=10; end else begin t:=theta(b[a].x,b[a].y,b[a2].x,b[a2].y);  m2:=hypotenuse(b[a].x,b[a].y,b[a2].x,b[a2].y); m1:=b[a2].mass; rate:=4; end;  ax:=b[a].x+(m1*cos(b[a].dir*radcon))+(m2*cos(t*radcon));  ay:=b[a].y+(m1*sin(b[a].dir*radcon))+(m2*sin(t*radcon));  newdir:=theta(b[a].x,b[a].y,ax,ay);if a=1 then begin if abs(newdir-b[a].dir)>=  180 then begin if newdir>b[a].dir then newdir:=newdir-360 else newdir:=newdir+  360; end; if newdir>b[a].dir then b[a].dir:=b[a].dir+((newdir-b[a].dir)/rate);  if newdir359 then b[a].dir:=b[a].dir-360;if b[a].dir<0   then b[a].dir:=b[a].dir+360;b[a ].x:=b[a].x+(b[a].speed*cos(b[a].dir*radcon));  b[a].y:=b[a].y+(b[a].speed*sin(b[a].dir*radcon));if b[a].x<3 then b[a].x:=3;  if b[a].x>637 then b[a].x:=637;if b[a].y<3 then b[a].y:=3;if b[a].y>477 then   b[a].y:=477;if(b[a].x=637)or(b[a].x=3)or(b[a].y=477)or(b[a].y=3) then begin  b[a].speed:=(random(100)+50)/speedfactor;if a=1 then delayfactor:=round(500/  b[1].speed);end;if (b[a].oldx<>round(b[a].x))or(b[a].oldy<>round(b[a].y)) then  begin setcolor(black);circle(b[a].oldx,b[a].oldy,1);if a=1 then circle(b[a].  oldx,b[a].oldy,2);setcolor(white);circle(round(b[a].x),r ound(b[a].y),1);if a=  1 then begin setcolor(lightgray);circle(round(b[a].x),round(b[a].y),2);end;  end;b[a].oldx:=round(b[a].x);b[a].oldy:=round(b[a].y);end;begin cleard evice;settextstyle(3,0,5);setcolor(15);outtextxy(120,50,'Critters');  outtextxy(120,150,'esc to return to menu');  countdown:=100;stampede:= false;randomize;ch:=#0;setgraphmode(2);initcritter;  while keypressed do ch:=readkey;repeat for i:=1 to totalbodies do orbit(i);  dec(countdown);if countdown<0 then begin stampede:=not stampede; if stampede   then begin walls:=random(4); countdown:=random(delayfactor)+delayfactor*2;  case walls of   0:begin bait.x:=20; bait.y:=random(480); end;  1:begin bait.x:=619;bait.y:=random(480); end;  2:begin bait.y:=20; bait.x:=random(640); end;  3:begin bait.y:=459;bait.x:=random(640); end;  end;  end else countdown:=random(delayfactor)+delayfactor*2; end;  if keypressed then ch:=readkey; until ch=#27;end;  procedure animation;var  X, Y:array [1..400] of integer;  i, Gx, Gy, Gy1, Gd, Gm: integer;  z:byte; BEGIN  Gd:=Detect;  InitGraph(Gd, Gm, 'X:\BP');   randomize;   Gx:=GetMaxX;  Gy:=GetMaxY;  SetColor(15);   for i:=1 to 200 do  begin    X[i]:= random(Gx);    Y[i]:= random(Gy div 1);    PutPixel(X[i],Y[i],15)  end;   repeat    inc (z);     for i:=1 to 200 do    begin      if (Y[i] < Gy) and (GetPixel(X[i],Y[i]+1)= 0) then      begin        PutPixel(X[i], Y[i],0);        Y[i]:= Y[i]+1;        PutPixel(X[i], Y[i],15)      end      else      begin        if Y[i] < 20 then        begin        PutPixel(X[i], Y[i],0);        end         else        begin        Line(X[i] - 3, Y[i] - 2, X[i] + 3, Y[i] + 2);          Line(X[i] + 3, Y[i] - 2, X[i] - 3, Y[i] + 2);          Line(X[i], Y[i] - 3, X[i], Y[i] + 3);        end;         Y[i]:={random(Gy div 40)}0;        X[i]:= random(Gx);        PutPixel(X[i], Y[i], 15);      end;    end;     settextstyle(7,0,7);    outtextxy(60,150,'Sometimes ');    outtextxy(300,250,'it snows ');    outtextxy(500,350,'in April');     settextstyle(7,0,6);    outtextxy(60,470,'Thanks For Watching');  until keypressed;  readkey;END;  begin  initgraph(m,t,'');  repeat   k:=1;      cleardevice;    repeat      case k of        1:menu(15,4,4,4);        2:menu(4,15,4,4);        3:menu(4,4,15,4);      4:menu(4,4,4,15);      end;      c:=readkey;       if ord(C)=80 then k:=k-1;      if ord(C)=72 then k:=k+1;      if k=0 then k:=4;    if k=5 then k:=1;    until ord(c)=13;     case k of      1:pahanj;    2:lucum;      3:animation;    end;  until k=4;end.