Forum > Beginners

Never code like this

(1/7) > >>

Petri:
Never code like this unless you are much more an algorithmic artist like me than a coder and you only want to make colorful  pictures.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program pointsbypoint;uses graph,Crt,math;VAR     gd,gm                   :       integer;        PathToDriver    :       string = '';        color                   :       word;        maxx,maxy               :       smallint;        x,y,x0,y0,x1,y1,x2,y2   :       word;        dist1,dist2,image               :       word;        xp,yp,        factor1,factor2,factor3 :       Real;PROCEDURE MYINITIALIZATION;BEGIN   Randomize;   gd:=detect;     gm:=0;   InitGraph(gd,gm,PathToDriver);   IF GraphResult<>grok THEN   BEGIN     closegraph;      halt;   END;   maxx:=GetMaxX;   maxy:=GetMaxY;END;PROCEDURE LETSSTART;BEGIN   Randomize;   x0:=Random(maxx);   y0:=Random(maxy);   x1:=Random(maxx);   y1:=Random(maxy);   x2:=Random(maxx);   y2:=Random(maxy);   factor1:=Random(1000)/10000;   factor2:=Random(1000)/10000;   factor3:=Random(1000)/10000;END; BEGIN        MYINITIALIZATION;        FOR image:=1 TO 10 DO                BEGIN;                        LETSSTART;                        for x:=0 to (maxx-1) do                                for y:=0 to (maxy-1) do                                        begin                                                xp:=x*factor1;                                                yp:=y*factor2;                                                dist1:=trunc(Sqrt(((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1))));                                                dist2:=trunc(Sqrt(((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2))));                                                color:=abs(trunc(0.0005*(sin(factor3*xp)*x+0.001*dist2)*(yp-xp)*0.002*dist1));                                                IF Keypressed THEN halt;                                                PutPixel(x,y,color);                                        end;                END;END.

creaothceann:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program PointsByPoint;uses        CRT, Graph, Math;  function InitGraphics : boolean;var        Driver, Mode : SmallInt;begin        Driver := Graph.Detect;        Mode   := 0;        InitGraph(Driver, Mode, '');        Result := (GraphResult = grOK);        if not Result then CloseGraph;end;  var        MaxX, MaxY : SmallInt;  procedure Render(        const x0, y0 : Word;  const Factor1 : Real;        const x1, y1 : Word;  const Factor2 : Real;        const x2, y2 : Word;  const Factor3 : Real);var        Color        : Word;        Dist1, Dist2 : Word;        x, y         : Word;        xp, yp       : Real;begin        Dec(MaxX);        Dec(MaxY);        for y := 0 to MaxY do begin                yp := y * Factor2;                for x := 0 to MaxX do begin                        xp    := x * Factor1;                        Dist1 := Trunc(Sqrt(((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1))));                        Dist2 := Trunc(Sqrt(((x0 - x2) * (x0 - x2) + (y0 - y2) * (y0 - y2))));                        Color := Abs(Trunc(0.0005 * (Sin(Factor3 * xp) * x + 0.001 * Dist2) * (yp - xp) * 0.002 * Dist1));                        PutPixel(x, y, Color);                        // writing to a line array in main RAM and transferring that line at once would probably be much faster                end;                if KeyPressed then Halt;        end;end;  begin        if not InitGraphics then Halt;        Randomize;        MaxX := GetMaxX;        MaxY := GetMaxY;        Render(                Random(MaxX), Random(MaxY), Random(1000) / 10000,                Random(MaxX), Random(MaxY), Random(1000) / 10000,                Random(MaxX), Random(MaxY), Random(1000) / 10000);end.

Weiss:
In FPC graph unit, how do we save graph into an image file? I made a little application to process numerical data into nice graphs. But don't see any function within graph unit that would relate to saving results. 

Turbo Pascal 6 speaks about saving image onto heap by assigning it to a pointer. I am still digging through all this, but  it will be appreciated if someone gave me a little hint. What do I do with a pointer, how do I save image to file?

Sorry for silly questions, low time student here.  I was going to post a separate topic, but I see your graph is saved, how do you do that?

Fred vS:

--- Quote from: Weiss on August 04, 2022, 12:33:10 am ---... I see your graph is saved, how do you do that?

--- End quote ---

Hello.

At the bottom of the picture of the OP, there is the Windows taskbar.
So maybe it was a screenshot when the program was running.

QuinnMartin:
>writing to a line array in main RAM and transferring that line at once would probably be much faster

How would do you do that?

I've never been very impressed with the speed of canvas line and pixel drawing in Delphi, and I figure Lazarus isn't much faster.  Even with double buffering it's slow.

Navigation

[0] Message Index

[#] Next page

Go to full version