I am making a math game and it involves making a graph. On some computers it works perfect but on some the graph does not match the picture box. It doesn't have to do with screen resolution as I have tried changing that with no difference. Any ideas on why it does not draw the same on every computer?
This is the code that draws the grid.
private void PaintGrid()
{
for (int i=1;i<20;i++) {
// Draw grid rectangle into the buffer
using (Graphics bufferGrph = Graphics.FromImage(buffer))
{
bufferGrph.DrawLine(new Pen(Color.Gray, 2), i * 30, 1, i * 30, 600);
bufferGrph.DrawLine(new Pen(Color.Gray, 2), 1, i * 30, 600,i * 30);
}
}
using (Graphics bufferGrph = Graphics.FromImage(buffer))
{
bufferGrph.DrawLine(new Pen(Color.CadetBlue, 5), 300, 1, 300, 600);
bufferGrph.DrawLine(new Pen(Color.CadetBlue, 5), 1, 300, 600, 300);
}
// Invalidate the panel. This will lead to a call of 'panel1_Paint'
panel1.Invalidate();
}
Related
How add a few chart in loop .
I try this but I have only one:
for (int x = 1; x < 5; x++)
{
var chart = worksheet.Drawings.AddChart(zaklad, OfficeOpenXml.Drawing.Chart.eChartType.ColumnClustered);
chart.Title.Text = "Total";
chart.SetPosition(wiersz, 14, wiersz * x, 25);
chart.SetSize(100, 100*x);
worksheet.Cells[wiersz, 14, wiersz + 1, 25].Style.Fill.PatternType = ExcelFillStyle.Solid;
ExcelAddress valueAddress = new ExcelAddress(wiersz, 14 , wiersz + 1, 25);
chart.Legend.Border.LineStyle = eLineStyle.Solid;
chart.Legend.Border.Fill.Style = eFillStyle.SolidFill;
chart.Legend.Border.Fill.Color = Color.DarkBlue;
}
My guess is you're drawing the last one (and the biggest according to your code) above the others.
Try the following:
// left, top, width, height
chart.SetPosition(0, 0, 100 * x, 100);
chart.SetSize(100, 100);
the inner shadow disappears during the transition it looks like the inner shadow is also scaled.
public void showTowerRange(int x0, int y0, double range) {
Circle circle = new Circle(
x0 * MAP_CELLS_WIDTH + MAP_CELLS_WIDTH / 2,
y0 * MAP_CELLS_HEIGHT + MAP_CELLS_HEIGHT / 2,
1,
Color.RED
);
circle.setOpacity(0.5);
gameRoot.getChildren().add(circle);
ScaleTransition scl = new ScaleTransition(Duration.millis(SHOW_RANGE_EFFECT_DURATION),circle);
scl.setByX(range * MAP_CELLS_WIDTH);
scl.setByY(range * MAP_CELLS_HEIGHT);
FadeTransition fd = new FadeTransition(Duration.millis(SHOW_RANGE_EFFECT_DURATION),circle);
fd.setByValue(-.3);
circle.setEffect(new InnerShadow(BlurType.GAUSSIAN, Color.GREEN, 4, 1, 0, 0));
circle.setEffect(new DropShadow(BlurType.GAUSSIAN, Color.WHITE, 2, 0, 0, 0));
ParallelTransition prl = new ParallelTransition(scl,fd);
prl.play();
}
Well, I have good news and bad news for you. The good one - scale transition does not ruin inner shadow. The bad one - it is you ruining inner shadow:)
The point is, setEffect() method does not add another effect, it just set effect property of the Node, replacing previous value. What you need to do is to chain you effects (see example here). So instead of this:
circle.setEffect(new InnerShadow(BlurType.GAUSSIAN, Color.GREEN, 4, 1, 0, 0));
circle.setEffect(new DropShadow(BlurType.GAUSSIAN, Color.WHITE, 2, 0, 0, 0));
You must do this:
InnerShadow is = new InnerShadow(BlurType.GAUSSIAN, Color.GREEN, 4, 1, 0, 0);
DropShadow ds = new DropShadow(BlurType.GAUSSIAN, Color.WHITE, 2, 0, 0, 0);
ds.setInput(is);
circle.setEffect(ds);
I have the following test code, where I try to clip a MeshView with a circle.
I also tried putting the meshView into a group then clipping that, but this result in a black circle.
Is there a way to clip a MeshView, preferably without putting it into a group?
import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.scene.image.Image
import scalafx.scene.paint.{Color, PhongMaterial}
import scalafx.scene.shape.{TriangleMesh, Circle, MeshView}
import scalafx.scene.{Group, PerspectiveCamera, Scene, SceneAntialiasing}
object Test4 extends JFXApp {
stage = new PrimaryStage {
scene = new Scene(500, 500, true, SceneAntialiasing.Balanced) {
fill = Color.LightGray
val clipCircle = Circle(150.0)
val meshView = new MeshView(new RectangleMesh(500,500)) {
// takes a while to load
material = new PhongMaterial(Color.White, new Image("https://peach.blender.org/wp-content/uploads/bbb-splash.png"), null, null, null)
}
// val meshGroup = new Group(meshView)
meshView.setClip(clipCircle)
root = new Group {children = meshView; translateX = 250.0; translateY = 250.0; translateZ = 560.0}
camera = new PerspectiveCamera(false)
}
}
}
class RectangleMesh(Width: Float, Height: Float) extends TriangleMesh {
points = Array(
-Width / 2, Height / 2, 0,
-Width / 2, -Height / 2, 0,
Width / 2, Height / 2, 0,
Width / 2, -Height / 2, 0
)
texCoords = Array(
1, 1,
1, 0,
0, 1,
0, 0
)
faces = Array(
2, 2, 1, 1, 0, 0,
2, 2, 3, 3, 1, 1
)
The clippling actually works fine over the MeshView wrapped around a Group.
If you check JavaDoc for setClip():
There is a known limitation of mixing Clip with a 3D Transform. Clipping is essentially a 2D image operation. The result of a Clip set on a Group node with 3D transformed children will cause its children to be rendered in order without Z-buffering applied between those children.
As a result of this:
Group meshGroup = new Group(meshView);
meshGroup.setClip(clipCircle);
you will have a 2D image, and it seems Material is not applied. However you can check there's a mesh, by seting this:
meshView.setDrawMode(DrawMode.LINE);
So in your case, adjusting dimensions:
#Override
public void start(Stage primaryStage) {
Circle clipCircle = new Circle(220.0);
MeshView meshView = new MeshView(new RectangleMesh(400,400));
meshView.setDrawMode(DrawMode.LINE);
Group meshGroup = new Group(meshView);
meshGroup.setClip(clipCircle);
PerspectiveCamera camera = new PerspectiveCamera(false);
StackPane root = new StackPane();
final Circle circle = new Circle(220.0);
circle.setFill(Color.TRANSPARENT);
circle.setStroke(Color.RED);
root.getChildren().addAll(meshGroup, circle);
Scene scene = new Scene(root, 500, 500, true, SceneAntialiasing.BALANCED);
scene.setCamera(camera);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
will give this:
In the end, clipping doesn't make sense with 3D shapes. For that you can use just 2D shape to get the result you want.
If you want 3D clipping have a look at CSG operations. Check this question for a JavaFX based solution.
I'm trying to make it so when I click on a server, it becomes selected and I can then run code after clicking on it.
Thank you for whatever assistance you can provide.
function OnGUI() {
if (!Network.isClient && !Network.isServer) {
if (joining) {
if (hostData) {
scrollPosition = GUI.BeginScrollView(Rect(Screen.width / 4, Screen.height /
6, Screen.width / 1.5, Screen.height / 2), scrollPosition, Rect(0, 0,
300, 1000 /* hostData.length * 30 */ ));
GUI.Label(Rect(30, 0, 100, 20), "Game Name");
GUI.Label(Rect(350, 0, 100, 20), "Server Info");
GUI.Label(Rect(590, 0, 100, 20), "Player Count");
GUI.Label(Rect(700, 0, 100, 20), "Password");
for (var i: int = 0; i < hostData.length; i++) {
GUI.Label(Rect(0, 30 + i * 30, 200, 22), hostData[i].gameName);
GUI.Label(Rect(160, 30 + i * 30, 500, 22), hostData[i].comment);
GUI.Label(Rect(610, 30 + i * 30, 100, 20), hostData[i].connectedPlayers +
" / " + hostData[i].playerLimit);
if (hostData[i].passwordProtected) {
clientPass = GUI.PasswordField(Rect(680, 30 + i * 30, 100, 25),
clientPass, "*" [0], 12);
}
if (GUI.Button(Rect(800, 30 + i * 30, 100, 25), "Join")) {
Network.Connect(hostData[i], clientPass);
}
}
GUI.EndScrollView();
}
I found the problem. It was obvious when I changed screen resolutions. Just by changing my screen resolution to 16x9 or 16x10 the buttons showed up.
I need to add a class to a Rect. I can't seem to figure out how to do it.
bar = (new Rect(x, ySegment * 10 + 30 + margin, w, 0)
.attr('opacity', 0.8)
.attr('class', data[i].segments[j].color)
.addTo(stage));
the class attr is ignored.
A DisplayObject like Rect isn't the representation of an HTMLElement. That's why custom attributes like "class" don't work. If your intention is to re-use attributes for different DisplayObjects, then try the following:
var myAttrs = {
fillColor: 'red',
opacity: 0.5
};
new Rect(20, 20, 100, 100).attr(myAttrs).addTo(stage);
new Rect(20, 130, 100, 100).attr(myAttrs).addTo(stage);
Play with it here: Orbit