How to Modify ZedGraphControl GraphPane Line? - line

How can I modify an existing line/curve in a ZedGraphControl's GraphPane?
I use the following to get the data for that line:
CurveList lineData = zgcControl.GraphPane.CurveList[i];
But I am stumped on what to do with the CurveList after that. I want to modify the contents of the curvelist but I do not know how.
Any help with this? Thanks!

What are you trying to modify?
Lets say you wanted to move the curve up by 100 units on the Y axis, it would look something like this:
CurveList lineData = zedGraphControl1.GraphPane.CurveList;
CurveItem curve = lineData[0];
for (int i = 0; i < curve.Points.Count; i++ )
{
PointPair point = curve.Points[i];
point.Y += 100;
}

Related

zedgraph: how to get dashed lines independant of physical graph size or # of data points

when i plot my data, the dashes are only visible if: the # of data points is small, or if i manually widen the window, or if i zoom in on the graph. my expectation is that i'd see dashes regardless of these factors, as you'd get in excel. am i overlooking a zedgraph config? thanks very much.
void plot_array(ref ZedGraphControl zgc)
{
int num_samples = 100;
double[] xvals = new double[num_samples];
double[] yvals = new double[num_samples];
for (double i = 0; i < num_samples; i++)
{
xvals[(int)i] = i / 10;
yvals[(int)i] = Math.Sin(i / 10);
}
var lineItem = zgc.GraphPane.AddCurve("Can't see the dashes", xvals, yvals, Color.Black);
lineItem.Line.Style = System.Drawing.Drawing2D.DashStyle.Custom;
lineItem.Line.DashOn = 10;
lineItem.Line.DashOff = 10;
lineItem.Symbol.Type = SymbolType.None;
zgc.AxisChange();
zgc.Refresh();
}
Obvious , nothing is wrong with your settings, everything is normal since you have lot of data the dashed line tends to (look) straight line.
if you try:
lineItem.Line.DashOn = 1;
lineItem.Line.DashOff = 10;
it solves your problem

game maker random cave generation

I want to make a cave explorer game in game maker 8.0.
I've made a block object and an generator But I'm stuck. Here is my code for the generator
var r;
r = random_range(0, 1);
repeat(room_width/16) {
repeat(room_height/16) {
if (r == 1) {
instance_create(x, y, obj_block)
}
y += 16;
}
x += 16;
}
now i always get a blank frame
You need to use irandom(1) so you get an integer. You also should put it inside the loop so it generates a new value each time.
In the second statement, you are generating a random real value and storing it in r. What you actually require is choosing one of the two values. I recommend that you use the function choose(...) for this. Here goes the corrected statement:
r = choose(0,1); //Choose either 0 or 1 and store it in r
Also, move the above statement to the inner loop. (Because you want to decide whether you want to place a block at the said (x,y) location at every spot, right?)
Also, I recommend that you substitute sprite_width and sprite_height instead of using the value 16 directly, so that any changes you make to the sprite will adjust the resulting layout of the blocks accordingly.
Here is the code with corrections:
var r;
repeat(room_width/sprite_width) {
repeat(room_height/sprite_height) {
r = choose(0, 1);
if (r == 1)
instance_create(x, y, obj_block);
y += sprite_height;
}
x += sprite_width;
}
That should work. I hope that helps!
Looks like you are only creating a instance if r==1. Shouldn't you create a instance every time?
Variable assignment r = random_range(0, 1); is outside the loop. Therefore performed only once before starting the loop.
random_range(0, 1) returns a random real number between 0 and 1 (not integer!). But you have if (r == 1) - the probability of getting 1 is a very small.
as example:
repeat(room_width/16) {
repeat(room_height/16) {
if (irandom(1)) {
instance_create(x, y, obj_block)
}
y += 16;
}
x += 16;
}
Here's a possible, maybe even better solution:
length = room_width/16;
height = room_height/16;
for(xx = 0; xx < length; xx+=1)
{
for(yy = 0; yy < height; yy+=1)
{
if choose(0, 1) = 1 {
instance_create(xx*16, yy*16, obj_block); }
}
}
if you want random caves, you should probably delete random sections of those blocks,
not just single ones.
For bonus points, you could use a seed value for the random cave generation. You can also have a pathway random generation that will have a guaranteed path to the finish with random openings and fake paths that generate randomly from that path. Then you can fill in the extra spaces with other random pieces.
But in regards to your code, you must redefine the random number each time you are placing a block, which is why all of them are the same. It should be called inside of the loops, and should be an integer instead of a decimal value.
Problem is on the first line, you need to put r = something in the for cycle

Changing content of a matrix in c

How do you change just part of a matrix in c (I'm actually in Objective-C, but using matrices in c). For example:
NSInteger tempMapMatrix[100][100] =
{{0,0,1,1,2,2,1,1,0,2,4,4,4,0,0,1,2,2,1,0,0,0,0,0,0},
{0,1,1,2,3,2,1,1,4,4,3,4,4,0,0,1,2,2,1,0,0,0,0,0,0},
{1,1,2,3,3,2,1,4,1,3,3,4,4,0,0,1,2,2,1,0,0,0,0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,5,5,5,5},
{5,5,5,5,5,1,2,3},
{5,2,2,2,5,1,2,3},
{5,2,5,2,5,1,2,3},
{5,2,2,2,5,1,2,3}};
but I'm getting an error (Expected Expression). I've tried
tempMapArray = stuff;
tempMapArray[][] = stuff;
but none work.
Any way to change the first couple of ints in the matrix?
You need to iterate over them, this is C, you don't have syntactic sugar to assingn pieces of arrays like you want. If you want to change, for example, every first element of each row you could do something like:
for (int = 0; i < 100; ++i) {
tempMatrix[i][0] = 5;
}
so for the first couple of every row you should do
for (int = 0; i < 100; ++i) {
tempMatrix[i][0] = 5;
tempMatrix[i][1] = 5;
}
and so on.
You have to access and change each element in the matrix individually.
I.e.:
tempMapMatrix[0][0] = 5;
tempMapMatrix[0][1] = //...
There is no way to "batch change" the contents of an array (one-dimensional or n-dimensional) in C.
The easiest way to achieve this effect is to write a for-loop and iterate over the contents of the two dimensional array and insert the required values in the required places.

Actionscript 3: How to make movieclip variables work with variables on stage (Healthbar Help)

I am totally new at this whole programming thing, and I really need help. So basically, I'm trying to make a healthbar that will increase or decrease depending on what button is clicked. I made a healthbar movieclip with 101 frames (I included zero) and put this in the actionscript layer of the movieclip:
var health:Number = 0;
if(health == 0)
{
gotoAndStop("1")
}
if(health == 1)
{
gotoAndStop("2")
}
if(health == 2)
{
gotoAndStop("3")
}
and on and on like so. Basically, on the stage itself, I have a button called fortyfiveup_btn that is commanded to do this:
var health:Number = 0;
fortyfiveup_btn.addEventListener(MouseEvent.CLICK, fortyfiveupClick);
function fortyfiveupClick(event:MouseEvent):void{
health = health+45
}
I quickly realized that both health variables, the one for the button and the one for the healthbar will not interact. How can I make it so if the button is clicked, the health goes to the relevant frame or percentage?
Thanks for any answers, and I appreciate all the help I can get :)
If the answer == yes to my comment you should do this:
You need to give the movieclip an instancename (perhaps lifebar) and from stage you can access the health inside the "lifebar" with lifebar.health.
So you need this inside your stage:
//You can delete the var health:Number = 0;
fortyfiveup_btn.addEventListener(MouseEvent.CLICK, fortyfiveupClick);
function fortyfiveupClick(event:MouseEvent):void{
//You can write this, too: lifebar.health += 45;
lifebar.health = lifebar.health+45;
}
You can even optimize your lifebar script, don't use 101 times the if(health == x) you can use this, too:
gotoAndStop(health + 1);
(I think this is inside an ENTER_FRAME event?)
EDIT:
Some error countermeasures:
//Don't let health decrease below 0
if(health < 0) health = 0;
//And don't above 100
else if(health > 100) health = 100;
gotoAndStop(health + 1);
Use int instead of Number when you don't use decimal numbers and uint when you don't use negative integers (this bugs when the number can drop under 0, so for your health we take int):
health:int = 0;

Check how close UILabels are to each other

I am trying to make a game which has a jumbled up algebra equation. I have assigned an outlet to each component of the equation. For example, if the equation was:
x2 + y = 2(a+b)
Then x2 (which is x squared), +, y, = and 2(a+b) would all be its own outlet. But the equation is going to be jumbled up and I want the user to move the label outlets to the correct order. I have enabled touchesMoved, but my problem lies in checking if the equation is in the correct order. I would wrap the code into an IBAction button action, but how do I analyze the text? Would I check for the offset between each label? Is there an easy way/API to do this? Thanks!
Assuming your labels are called xLabel,plusLabel, yLabel, equalsLabel, and abLabel, you could do something like this:
NSUInteger xLeftBorder = CGRectGetMinX(xLabel.frame);
NSUInteger plusLeftBorder = CGRectGetMinX(plusLabel.frame);
NSUInteger yLeftBorder = CGRectGetMinX(yLabel.frame);
NSUInteger equalsLeftBorder = CGRectGetMinX(equalsLabel.frame);
NSUInteger abLeftBorder = CGRectGetMinX(abLabel.frame);
if(xLeftBorder < plusLeftBorder && plusLeftBorder < yLeftBorder && yLeftBorder < equalsLeftBorder && equalsLeftBorder < abLeftBorder){
//Correct!
}
else{
//Incorrect
}
This is kind of clumsy, but it works. An even better way to do it would be to put this in a function with each parameter being a label to check. For example:
bool isCorrect = [self checkIf:xLabel isLessThan: plusLabel isLessThan: yLabel isLessThan:equalsLabel isLessThan:abLabel];
This is assuming the function you write returns a bool.
Hope this helped!