SRL Archive - General

Drawing pictures with SCAR (diagrams etc)


marpis

2008-10-08 14:57:51

How can i make scar to draw a linear diagram (dunno if that is correctly said)
with variables? like

     y |
| /
| / <-- in the beginning, lets set y=x+z, and z=0
|/
-----------------------
/ | x
/ |
Then when whe have set a line that adds 1 to z every second, so after a few seconds the picture would be something like this

     y |/
/|
/ |
/ |
-----------------------
/ | x
|


And so we could calculate things, like how does the value of z affect something.

bullzeye95

2008-10-08 16:33:57

Why do you need to draw a graph to find stuff like that? It's a waste of time.

Freddy1990

2008-10-09 10:32:16

Check SCARRoot\Scripts\Misc\Parabola.scar for a script that can draw a quadratic function, you should be able to base one for linear diagrams on that…

Seroko

2008-10-10 07:26:28

From: bullzeye95
Why do you need to draw a graph to find stuff like that? It's a waste of time.


Why do I make scripts I am never going to use? Its all about learning imo :) Let him do it for what ever reason motivates him, at least hes learning.

Smarter Child

2008-10-12 14:29:07

does drawing diagrams in Scar relate to scripting in some sort?

Edit: Runescape scripting i mean

Da 0wner

2008-10-12 18:33:19

It depends on how you use it. It is a waste of time imo but you can use it for graphs on how fast it gathers a resource or basically any stat the script keeps track off.

marpis

2008-10-13 00:44:50

From: bullzeye95
Why do you need to draw a graph to find stuff like that? It's a waste of time.


For fun? like how many mobs killed/feathers picked/ores smelt, while y being amount of mobs/feathers/ores and x being time script has ran.

Useless? yes. But so are many other things in runescape scripts

bullzeye95

2008-10-13 07:35:40

Alright, I was assuming that you wanted to draw a graph so that the script could solve an equation, instead of for you/the user to see.

Smartzkid

2008-10-14 20:37:04

I think this is what you're looking for :)

http://www.srl-forums.com/forum/grapher-t39556.html

marpis

2008-10-15 04:01:53

well, looks like its too hard for me to make scar draw pictures to its own grid, BUT i started to make a script that draws em into mspaint :P not exactly sure how its best to do, but im learning fast.

Smartzkid

2008-10-15 15:21:34

All you gotta do is use the code I wrote :p

Program Grapher;

{*******************************************************************************
function GraphPtsEx( ... ): integer;
By: Smartzkid
Description: Graphs points stored in TPA 'pts', returns handle to a bitmap
Parameters:
GraphPxlsX, GraphPxlsY: integer; Size of the graph
zoom: integer; Zoom
pts: TPointArray; Graph points
GraphBCGColor, Background color
GraphAxisColor, Axis color
GraphLineColor: integer; Line color
Axis_ForceVisible: boolean; Force origin to be visible
connectPoints: boolean; Draws lines connecting points
pointSize: integer; Draws circles for each point (1 = disabled)
gridlines: boolean; Draw gridlines
GridlineXS\pacing, GridlineYSpacing, Spacing between gridlines
GridlineColor: integer): integer; Gridline color
*******************************************************************************}
function GraphPtsEx(GraphPxlsX, GraphPxlsY: integer; zoom: integer; pts: TPointArray; GraphBCGColor, GraphAxisColor, GraphLineColor: integer; Axis_ForceVisible: boolean; connectPoints: boolean; pointSize: integer; gridlines: boolean; GridlineXSpacing, GridlineYSpacing, GridlineColor: integer): integer;
var
x_min, x_max, y_min, y_max: integer;
i, temp: integer;
scaleX, scaleY: extended;
Graph_BMP, Result_BMP: integer;
graphPoints: TPointArray;
canvas: TCanvas;
begin
//Param-error catching
if(GraphPxlsX < 1)then
Exit;
if(GraphPxlsY < 1)then
Exit;
if(zoom < 1)then
zoom := 1;
if(Gridlines)then
begin
if(GridlineXSpacing < 1)then
GridlineXSpacing := 5;
if(GridlineYSpacing < 1)then
GridlineYSpacing := 5;
end;

//Create the bitmap that the graph will be displayed on and fill with a given color
Graph_BMP := BitmapFromString(GraphPxlsX, GraphPxlsY, '');
FastDrawClear(Graph_BMP, GraphBCGColor);

if(Axis_ForceVisible = false)then
begin
x_min := pts[0].x;
y_min := pts[0].y;
end;

//Find lowest and highest points
for i := 0 to high(pts) do
begin
if(pts[i].x < x_min)then
x_min := pts[i].x;
if(pts[i].x > x_max)then
x_max := pts[i].x;
if(pts[i].y < y_min)then
y_min := pts[i].y;
if(pts[i].y > y_max)then
y_max := pts[i].y;
end;

//add a 10% 'buffer' to the x axis
temp := round((abs(x_max) - x_min) / 10);
x_min := x_min - temp;
x_max := x_max + temp;

//add a 10% 'buffer' to the y axis
temp := round((abs(y_max) - y_min) / 10);
y_min := y_min - temp;
y_max := y_max + temp;

//Determine Graph-point to pixel scale
scaleX := GraphPxlsX / round(x_max - x_min);
scaleY := GraphPxlsY / round(y_max - y_min);

if(Gridlines)then
begin
//Draw vertical gridlines
for temp := 0 to round(GraphPxlsX / (GridlineXSpacing * ScaleX)) do
for i := 0 to GraphPxlsY - 1 do
FastSetPixel(Graph_BMP, round(GridlineXSpacing * temp * ScaleX) + (round(abs(x_min) * scaleX) mod GridlineXSpacing), i, GridlineColor);

//Draw horizontal gridlines
for temp := 0 to round(GraphPxlsY / (GridlineYSpacing * ScaleY)) - 1 do
for i := 0 to GraphPxlsX - 1 do
FastSetPixel(Graph_BMP, i, round(GridlineYSpacing * temp * ScaleY) + (round(((GraphPxlsY / ScaleY) + abs(y_min)) * scaleY) mod GridlineYSpacing), GridlineColor);
end;

//Draw vertical axis
if(x_min < 0)then
for i := 0 to GraphPxlsY - 1 do
FastSetPixel(Graph_BMP, round(abs(x_min) * scaleX), i, GraphAxisColor);

//Draw horizontal axis
if(y_min < 0)then
for i := 0 to GraphPxlsX - 1 do
FastSetPixel(Graph_BMP, i, round(((GraphPxlsY / ScaleY) - abs(y_min)) * scaleY), GraphAxisColor);


//Calculate the points
SetLength(graphPoints, Length(pts));
for i := 0 to high(pts) do
begin
graphPoints[i].X := round((pts[i].x - x_min) * scaleX);
graphPoints[i].Y := round(GraphPxlsY - ((pts[i].y - y_min) * scaleY));
end;

//Graph the points
for i := 0 to High(graphPoints) do
try
FastSetPixel(Graph_BMP, graphPoints[i].X, GraphPoints[i].Y, GraphLineColor);
except
writeln('Error at pt ' + inttostr(i + 1));
writeln(inttostr(graphPoints[i].X) + ', ' + inttostr(graphPoints[i].Y));
end;

if(connectPoints) or (pointSize > 1)then
canvas := GetBitmapCanvas(Graph_BMP);

if(connectPoints)then
canvas.Pen.Color := GraphLineColor; //Sets line color

if(pointSize > 1)then
canvas.Brush.Color := GraphLineColor; //Fills elipses with line color

if(connectPoints)then
for i := 0 to High(graphPoints) - 1 do
try
canvas.MoveTo(graphPoints[i].X, graphPoints[i].Y);
canvas.LineTo(graphPoints[i + 1].X, graphPoints[i + 1].Y);
except
writeln('Error drawing line between pts ' + inttostr(i) + ' and ' + inttostr(i + 1));
end;

if(pointSize > 1)then
for i := 0 to High(graphPoints) do
canvas.Ellipse(graphPoints[i].X - pointSize, graphPoints[i].Y - pointSize, graphPoints[i].X + pointSize, graphPoints[i].Y + pointSize);

Result_BMP := BitmapFromString(GraphPxlsX * zoom, GraphPxlsY * zoom, '');
SafeCopyCanvas(canvas, GetBitmapCanvas(Result_BMP), 0, 0, GraphPxlsX, GraphPxlsY, 0, 0, GraphPxlsX * zoom, GraphPxlsY * zoom)
FreeBitmap(Graph_BMP);

result := Result_BMP;
end;

{*******************************************************************************
function GraphPts(GraphPxlsX, GraphPxlsY: integer; pts: TPointArray): integer;
By: Smartzkid
Description: Graphs points stored in TPA 'pts', returns handle to a bitmap
Parameters:
GraphPxlsX, GraphPxlsY: integer; Size of the graph
pts: TPointArray; Graph points
*******************************************************************************}
function GraphPts(GraphPxlsX, GraphPxlsY: integer; pts: TPointArray): integer;
begin
result := GraphPtsEx(GraphPxlsX, GraphPxlsY, 1, pts, 16777215, 5018076, 0, false, true, 2, true, 10, 10, 16701619);
end;

//Below is the stuff that you'd change

var
points: TPointArray;
bitmap: integer;

begin
SetLength(points, 2);
points[0] := Point(-4, -4);
points[1] := Point(4, 4);
bitmap := GraphPts(400, 400, points);
DisplayDebugImgWindow(400, 400);
SafeCopyCanvas(GetBitmapCanvas(bitmap), GetDebugCanvas, 0, 0, 400, 400, 0, 0, 400, 400);
FreeBitmap(bitmap);
end.

Zigon

2008-10-16 11:30:24

I think that would be awesome if scripts showed graphs in their progress reports. I'm not to sure why you'd use algebraic equations(linear, quadratic,ect..) in scar for. If i wasn't so rusty with scar I think that would be fun to make though.