Rotating Text in Processing - processing

I'm working on something and seem to be stuck. I'm trying to add text over a button in Processing, however, once I use the translate method, my text is appearing upside down. How I can I simply rotate it so that it appears normal? Here's what I have:
void setup(){
size(600,600);
background(255);
translate(20,500);
scale(1,-1);
line(0,0,0,475);
line(0,0,550,0);
fill(0,255,0);
rect(400,-50,100,40);
fill(0);
font = loadFont("TimesNewRoman.vlw");
textFont(font,24);
rotate(PI/2);
text("Compute",405,-30);
}

Your problem is not caused by the translate() function. It's caused by passing a negative value into the scale() function. Here's a simple program that shows your problem:
scale(1,-1);
text("hello", 20, -20);
(You should really get into the habit of testing your assumptions and trying to isolate the problem like this.)
The scale(1, -1); line is flipping everything vertically. I can't really imagine why you would want to do that, so the simplest option would be to get rid of that line.
If you really need your scale flipped, then you're going to have to flip it back before you draw your text.

Related

How do i move the mouse with processing?

I was testing processing features and wondered if I could move the mouse with code with/without libraries. So can anyone write me a code / give me a library so that it works?
I tried reading half the 284 questions and found nothing, I tried reading through github trying to find a code / a library that works.
Not an answer, but a potential workaround:
Using noCursor(); you can get rid of the default cursor, and then develop your own custom cursor using something like shapes.
E.g. circle(mouseX + 20, mouseY, 20); would always draw a "cursor" 20 pixels to the right of where your mouse position actually is.
This is how I made a custom and dynamic cursor for a little game, where it changed color and sometimes position depending on activities on the screen.

Problem when assigning Input.mousePosition to transform.position in Unity2D

I have been following the Inventory tutorials for Unity by Kryzarel and have encountered a weird issue that I think may be from something unrelated.
Tons of googling has yielded no results. It seems like an obscure issue.
https://www.youtube.com/channel/UCOM0GGMEcu-gyf4F1mT7A8Q/videos for reference of the channel.
But the issue I'm running into is I do the following:
draggableItem.transform.position = Input.mousePosition;
So basically draggable Item is a reference to an Image component on a GameObject. I log Input.mousePosition before hand and the values make sense (within the hundreds e.g. (563,262,0)). However, the transform position is nowhere near the number logged. For the example, I'm seeing (48660.31, 23917.95, -7889.887). There is no logic between the debug.log statement giving Input.mousePosition and the code assigning it to the transform. Anyone have any idea what I could possibly have configured wrong, or could be wrong?
I would expect the position to be (563,262,0) not the ridiculous number that it ends up being. I've tried localPosition instead of transform.position, and it sort of works. In that it's off by about 500 or 700 to the top-right of what I'm moving relative to the mouse, I want to avoid hacky solutions like subtracting some magic number if possible.
Edit: Some further background, other mouse clicks and mouse related things appear to work correctly. It's an orthographic camera, or the default for a unity2D project
Solution: IN my case I was able to set it per the accepted answer, I then had to modify position not localPosition and also had to zero out the z-value of the world point.
The mouse position is relative to your screen, not your world. You need to convert the screen space to world space with:
var pos = Camera.ScreenToWorldPoint(Input.mousePosition);

Position changing after rotation processing

I am working on a tic-tac-toe game in my computer science class using processing-java. In my program, on the far right side I have a status bar that states which player's turn it is, who won, and who lost. This status bar is also placed vertically, so in my code I am rotating it and although it is rotating properly, it is causing another problem. The status bar appears in a certain area on the game screen, but after one X or O is placed, it moves spots and I am unsure of how to fix this. After another piece is placed, it moves a second time, then a third and then finalizes its place in an area I do not want it to be. This is my code regarding the text and rotation.
void updateStatus(String status) { // function to update the status message
fill(0);
rect(statusX, sbh, width, height-1);
stroke(#FFFFFF);
strokeWeight(4);
line(statusX, sbh, statusX, screenH); // Status line
fill(255);
String fullStatus = "It is player "+status+"'s turn";
//String fullStatus = "It is player X's turn";
float statusTxtX = width*15/16, statusTxtY = height*2.5/7;
pushMatrix();
translate(statusTxtX, statusTxtY);
rotate(HALF_PI);
textSize(55);
textFont(mainFont);
text(fullStatus, 0, 0);
//textDraw(status, mainFont, height, 255, CENTER, CENTER, statusX, height*3/12, width, height*1/2);
popMatrix();
}
The problem is with text-aligns. There is one in the placing() function and one in the textDraw() function. When you disable those the text stays in the same location. However, this will mess up the X's and O's, so you'll need to do some work on tracing where what text-align is set.
As a more general tip (since you're learning): put your first focus on functionality. You could for example build TicTacToe using println() and the numpad as input. When the game mechanics work you can add a nice user interface. Doing both at the same time often makes messy code that is prone to errors that are hard to debug. I bumped into that wall plenty of times myself ;)

After mouse click image disappears and shows up in new random position. How can I check the new position? (processing)

I need help with my code in processing. It is actually a short and easy code, but I am a beginner in programming, so for me seems everything difficult... :(
My goal is...
To click on an image.
After the mouse click, the image should disappear and show up in a new random position.
Then I should be able to click on the image in the new random position, and it should do the same again: disappear and show up in a new random position. and so on.
I have written some code (see below), but it does not work properly. I would really appreciate it if someone could help me to find out, what is wrong with my code. Thank you very much in advance! :)
Here is my code:
PImage pic;
// Declare variables for the picture
float pic_x;
float pic_y;
float pic_r = 100;
float pic_x_new = random(0, 400);
float pic_y_new = random(0, 400);
boolean mouseOverPic;
void setup(){
size(500,500);
background(0,100,0);
//loading the picture
pic = loadImage("pic.png");
image(pic, pic_x, pic_y, pic_r, pic_r);
}
void draw(){
mouseOverPic = mouseX <= pic.width
&& mouseX >= pic_x
&& mouseY <= pic.height
&& mouseY >= pic_y;
if (mousePressed && mouseOverPic) {
background(100);
image(pic, pic_x_new, pic_y_new, pic_r, pic_r);
}
}
Can you please try to be more specific than saying your code does not work properly? Have you tried debugging your code to narrow your problem down? Which line of code behaves differently from what you expected?
The code you have doesn't make a ton of sense, because you're only ever drawing the image when it's being clicked. That doesn't sound like what you want to do. And your collision detection code is not correct. Try running through your code with some example values to see exactly what it's doing. I've written a tutorial on collision detection in Processing available here.
To fix this, you really need to break your problem down into smaller pieces and take those pieces on one at a time. For example:
Can you create a simple example program that just shows a hard-coded rectangle that changes color if the mouse is inside it?
Can you then make it so the rectangle displays in a random location every time the program is run?
Then can you make it so the rectangle changes location when you click it?
If you get stuck on a specific step, please narrow your problem down and post a MCVE in a new question. Good luck.
I belive you test against pic_x, but uses pic_x_new to draw the image (same with y). You should use the same var to place and test the image.
Another approach would be to make a function to test mouse against the image passing the new values as parameters.

Best/Easier way to add a shape/image to a Dynamics AX 2009 form?

I would like to add a few coloured square shapes to a form in order to display a legend. Since I haven't come across any way of adding coloured-in shapes, I've resorted to creating the shapes as images, loading them as resources and am currently trying to load them to the form...although this seems like a lengthy workaround for a simple single-coloured square.
First off, is there any way of adding a basic shape of a given colour to an AX form? Otherwise, is there any easier way of adding the image to the form without having to replicate the CompanyImage (or CompanyInfo) form?
NOTE: I'm looking to have the image stored within AX proper and not having the image linked by a filepath to an image on the local machine.
You can draw simple shapes with the WinGDI Class.
Here is a simple sample :
void drawShapes()
{
WinGDI winGDI;
Int brush, height, width;
;
//myWindow being the FormWindowControl
height = myWindow.heightValue()/2;
width = myWindow.widthValue()/2;
myWindow.lockDC();
winGDI = new WinGDI(myWindow.hDC());
brush = winGdi.createSolidBrush(WinAPI::RGB2int(0, 0, 255));
winGDI.fillRect(0, 0, width, height, brush);
winGDI.deleteObject(brush);
winGDI.ellipse(0, 0, width, height);
brush = winGdi.createSolidBrush(WinAPI::RGB2int(255, 0, 0));
winGDI.fillRect(width, height, 2*width, 2*height, brush);
winGDI.deleteObject(brush);
myWindow.UnlockDC();
}
I assume you got something similar.
Now if you just call it once in the form's init, the drawing's will be erased as soon as the paint method of the window control is called (and it's called pretty often).
So the easiest way is to call it in the paint method of the window. This way every time myWindow's content is redrawn, your shapes are too.
You can also force the redrawing of the shapes at a (short) regular time interval like the Tetris Tutorial does (look at the cycle method) using setTimeout but it may be overkill for static content.
You should now have this
You can store images as containers (BLOB) on the database and show them on a form or a report:
How to: Add an Image to a Form
This could be a simple workaround but this what i did for one of my changes. Since you wanted to use it for legend you can just add a button and set the property as flat, give it a color and a text. That should be good enough as a legend.

Resources