Photoshop actions with auto rotate - action

I build my action for create image thumbs, and I want add to the end of action auto rotate to my thumb.
My question is: How add rotate with random angle from -45 to 45 degree?

You can rotate an image automatically via an Adobe Script:
if (!app.documents.length > 0) {
alert("No active document");
}
else {
var docRef = app.activeDocument;
var docWidth = docRef.width.as("px");
var docHeight = docRef.height.as("px");
if (docWidth > docHeight) {
docRef.rotateCanvas(90);
}
}
Random numbers can be generated with:
this.rawValue = Math.random() * (45 - 1) + 1;
I've not done enough Adobe Script to tell you how to put this all together, but I'm sure you are clever enough!
Helpful site: http://www.photoshopsupport.com/tutorials/jennifer/photoshop-scripts.html
Enjoi!

Sorry for another answer, I didn't want to make my other one massive and unreadable.
I have attempted (VERY BADLY) the script (and, for the record, it's not been tested or anything and I'm not great at this)
if (!app.documents.length > 0) {
alert("No active document"); //no document?! whats happening?!
} else {
var docRef = app.activeDocument;
var docWidth = docRef.width.as("px");
var docHeight = docRef.height.as("px");
if (docWidth > docHeight) { //if width is greater than height
PlusMinus.rawValue = Math.random() * (2 - 1) + 1; //GET 1 OR 2
if (PlusMinus.rawValue == 1) {
deLimit = "-"; //set minus if its a 1
} else {
deLimit = "+"; //set plus if its a 2
}
Angles.rawValue = Math.random() * (45 - 1) + 1; //GET NUMBER FROM 1-45
docRef.rotateCanvas(deLimit+Angles);
}
}
I'm sure you will get the idea from that!

Related

Drag and Drop Item list not working properly on ImGUI

Im using ImGUI and I want to implement a layer menu for the images and to move them im using
Drag to reorder items in a vector.
Sometimes it works just fine but others the images just jumps from the current position to a random one.
for (int i = 0; i < this->Images->size(); i++) {
ImGui::Image((void*)(intptr_t)this->Images->at(i).texture, ImVec2(100 * temp_percentage, 100 * temp_percentage));
ImGui::SameLine();
ImGui::Selectable(this->Images->at(i).name.c_str());
if (ImGui::IsItemActive() && !ImGui::IsItemHovered())
{
int n_next = i + (ImGui::GetMouseDragDelta(0).y < 0.f ? -1 : 1);
if (n_next >= 0 && n_next < this->Images->size())
{
std::swap(this->Images->at(i), this->Images->at(n_next));
*this->CurrentImage = this->Images->front();
centerImage();
ImGui::ResetMouseDragDelta();
}
}
ImGui::Separator();
}
The problem lies at !ImGui::IsItemHovered(), there is small spacing between the lines (cell, selectable,... ), so when the mouse hovers over that spacing, the item isn't hovered but still is actived, and therefore will execute the swap and reset mouse delta multiple times making it goes to the top or bottom of the list. This will also happen if the mouse goes out of the table/window bounds.
To make the problem more visible, you can make the spacing bigger using ImGui::GetStyle().ItemSpacing.y = 50.f;.
To actually fix the problem, you'll have to calculate the item index using the mouse position, here is a way to do it, tho not perfect but it works.
ImGuiStyle& style = ImGui::GetStyle();
ImVec2 windowPosition = ImGui::GetWindowPos();
ImVec2 cursorPosition = ImGui::GetCursorPos();
// this is not a pixel perfect position
// you can try to make it more accurate by adding some offset
ImVec2 itemPosition (
windowPosition.x + cursorPosition.x,
windowPosition.y + cursorPosition.y - style.ItemSpacing.y
);
for (int i = 0; i < this->Images->size(); i++) {
ImGui::Image((void*)(intptr_t)this->Images->at(i).texture, ImVec2(100 * temp_percentage, 100 * temp_percentage));
ImGui::SameLine();
ImGui::Selectable(this->Images->at(i).name.c_str());
if (ImGui::IsItemActive() && ImGui::IsMouseDragging(0))
{
int n_next = floorf((ImGui::GetMousePos().y - itemPosition.y) / itemHeight);
if (n_next != i && n_next >= 0 && n_next < this->Images->size())
{
std::swap(this->Images->at(i), this->Images->at(n_next));
*this->CurrentImage = this->Images->front();
centerImage();
}
}
ImGui::Separator();
}
There is also another problem in your code, if there are multiple items with the same name, ImGui::IsItemActive() will return true for all of them if one is actived.
You can fix this easily by adding ##some_unique_string after the name, for example ImGui::Selectable("Image#image_1") will just display Image.

Tetris function for checking if piece fits doesn't work right

Im practicing C++, and been working on tetris clone. I have tried to figure out my own solutions with help of few tutorials to learn to code with this language. Im having almost everything else working, but this function is giving me some problems:
bool Board::isBoxFree(int pX, int pY, int pPiece[][4], int pBoard[][20])
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
if (pPiece[i][j] != 0)
{
if (pBoard[(pX / 15) + i][(pY / 15) + j] != 0)
{
return false;
break;
}
if (pY / 15 + j > 18)
{
return false;
break;
}
else
return true;
break;
}
}
}
This works with some of the pieces, but gives wrong values systematically with different tetris pieces. For example when checking if straight line can go right the last block overlaps borders. With n-shape or t-shape there is no problem. Sometimes when going down tetrominos overlap one block before function working and tetromino saving to board with the overlapping position. Some tetrominos don't seem to hit anything but are still collided and saved to the board one block away when they should have been collided.
Is this function written wrong or is there something wrong with my use of two dimensional arrays?
This is how I check if tetromino can go down inside game tick:
if (this->playBoard(xLoc, yLoc, this->arr, rotate, this->boardArr).isBoxFree(xLoc, yLoc + boxSize, this->arr, this->boardArr))
And here is how I check if tetromino can go left or right:
if (this->ev.key.code == Keyboard::Left)
{
if (this->playBoard().isBoxFree(xLoc - boxSize, yLoc , this->arr, this->boardArr)&& move ==false )//(move == false && xLoc>boxSize)
{
xLoc = xLoc - boxSize;
move = true;
}
}
else if (this->ev.key.code == Keyboard::Right)
{
if(this->playBoard().isBoxFree(xLoc+boxSize*3, yLoc , this->arr, this->boardArr)&& move == false) //(move == false && xLoc<boxSize*7)
{
xLoc = xLoc + boxSize;
move = true;
}
}
As you can see I have multiplied boxSize with 3 when checking if going right is possible for it to work right with at least some tetrominos. That alone tells that there is something wrong with my code that I haven't figured out.
Help is much appreciated since this is one of the last problems I have with my tetris. Even the line clearing function works.
Re: Is this function written wrong
You have an error in your Board::isBoxFree() functin, in the inner for loop (I've removed redundant breaks, as Paul commented):
if (pPiece[i][j] != 0)
{
if (pBoard[(pX / 15) + i][(pY / 15) + j] != 0)
return false;
if (pY / 15 + j > 18)
return false;
else
return true;
}
You can remove else too, as if a condition was true - you would return already. So:
if (pPiece[i][j] != 0)
{
if (pBoard[(pX / 15) + i][(pY / 15) + j] != 0)
return false;
if (pY / 15 + j > 18)
return false;
return true;
}
So for the first pPiece[i][j] that is NOT 0, if the board at that location is empty - you would return true, without checking other elements.
This is a common pattern. You check all elements of your pPiece and return false as soon as you find the collision. Then, when you are out of the loop (no collisions were found) - you return true
Re: is there something wrong with my use of two dimensional arrays?
Possibly. My eyes hurt a little looking at all those / 15, > 18... :)

Calling Variables in another function (c++)

So I've gotta create a whole bunch of Variables for some colours for a customisable menu I'm making. I wanted to know if there was a way to call the variables from the first function into other functions (there are alot) These variables have to be used in over 100 locations across about 10 different functions and I really don't want to redefine all the sh*t over again every single time. (Looks messy and is a pain if I need to make changes. Heres my Menu Colour Function
Color MenuColor(int MenuAlpha_Main)
{
Color Theme;
Color Basic = Color(c_config::get().menu_color_r, c_config::get().menu_color_g, c_config::get().menu_color_b, MenuAlpha_Main);
Color Background = Color(c_config::get().menu_background_r, c_config::get().menu_background_g, c_config::get().menu_background_b, MenuAlpha_Main);
Color MiscSelectedTab_Colour = Color(c_config::get().MiscSelectedTab_r, c_config::get().MiscSelectedTab_g, c_config::get().MiscSelectedTab_b, MenuAlpha_Main);
Color MiscSelectedTab_Highlight_Colour = Color(c_config::get().MiscSelectedTab_Highlight_r, c_config::get().MiscSelectedTab_Highlight_g, c_config::get().MiscSelectedTab_Highlight_b, MenuAlpha_Main);
Color MiscUnSelectedTab_Colour = Color(c_config::get().MiscUnSelectedTab_r, c_config::get().MiscUnSelectedTab_g, c_config::get().MiscUnSelectedTab_b, MenuAlpha_Main);
Color MiscUnSelectedTab_Highlight_Colour = Color(c_config::get().MiscUnSelectedTab_Highlight_r, c_config::get().MiscUnSelectedTab_Highlight_g, c_config::get().MiscUnSelectedTab_Highlight_b, MenuAlpha_Main);
/////rainbow sync//////
static unsigned int last_time;
last_time = GetTickCount();
Color rainbow;
rainbow.FromHSV(fmod(last_time * 0.0002f, 1.f), 1.f, 0.5f);
//////////////////////
// Oh fuck, time for the customizable shit
Color MiscSelectedTab;
Color MiscSelectedTab_Highlight;
Color MiscUnSelectedTab;
Color MiscUnSelectedTab_Highlight;
if (c_config::get().menu_colour_style == 0) {
Theme = Basic; //Normal Style
}
else if (c_config::get().menu_colour_style == 1) {
Theme = rainbow; //Rainbow
}
else if (c_config::get().menu_colour_style == 2) {
//This shit is done below
}
return Theme;
if (c_config::get().menu_colour_style == 0 || c_config::get().menu_colour_style == 0 && !c_config::get().fullmenuhighlight) {
MiscSelectedTab = Background;
MiscSelectedTab_Highlight = Theme;
MiscUnSelectedTab = Background;
MiscUnSelectedTab_Highlight = Theme;
}
else if (c_config::get().menu_colour_style == 0 || c_config::get().menu_colour_style == 0 && c_config::get().fullmenuhighlight) {
MiscSelectedTab = Theme;
MiscSelectedTab_Highlight = Theme;
MiscUnSelectedTab = Theme;
MiscUnSelectedTab_Highlight = Theme;
} // MISC SUBTAB (Misc/Colours)
else if (c_config::get().menu_colour_style == 2) {
MiscSelectedTab = MiscSelectedTab_Colour;
MiscSelectedTab_Highlight = MiscSelectedTab_Highlight_Colour;
MiscUnSelectedTab = MiscUnSelectedTab_Colour;
MiscUnSelectedTab_Highlight = MiscUnSelectedTab_Highlight_Colour;
}
return MiscSelectedTab;
return MiscSelectedTab_Highlight;
return MiscUnSelectedTab;
return MiscUnSelectedTab_Highlight;
}
I'm still fairly fresh to cpp so please don't judge. And the return values would need to be referenced in a function like this
void miscsubtab(int& current_players_esp_subtab, int tab_amount, Vector _pos, int MenuAlpha_Main)
{
int in_sizew_esp_player_subtabs = GroupBoxSize_Width - 8;
static std::string ESP_Player_SubTabs_Names[2] = { "Misc", "Colours" };
for (int i = 0; i < tab_amount; i++)
{
RECT text_size2 = g_pSurface->GetTextSizeRect(Globals::SmallText, ESP_Player_SubTabs_Names[i].c_str());
int tab_area[4] = {
_pos.x + 9 + (i * (in_sizew_esp_player_subtabs / tab_amount)), _pos.y + 52 + 5,
(in_sizew_esp_player_subtabs / tab_amount), 20
};
if (GetAsyncKeyState(VK_LBUTTON) && g_pSurface->MouseInRegion(tab_area[0], tab_area[1], tab_area[2],
tab_area[3]))
current_players_esp_subtab = i;
if (current_players_esp_subtab == i)
{
g_pSurface->FilledRect(tab_area[0], tab_area[1], tab_area[2], tab_area[3], MiscSelectedTab); //HERE
g_pSurface->FilledRect(tab_area[0], tab_area[1] + tab_area[3], tab_area[2], 3, MiscSelectedTab_Highlight); //HERE
g_pSurface->DrawT(tab_area[0] + (((in_sizew_esp_player_subtabs / tab_amount) / 2) - (text_size2.right / 2)),
tab_area[1] + (tab_area[3] / 2) - (text_size2.bottom / 2),
Color(143, 143, 143, MenuAlpha_Main), Globals::SmallText, false,
ESP_Player_SubTabs_Names[i].c_str());
}
else
{
g_pSurface->FilledRect(tab_area[0], tab_area[1], tab_area[2], tab_area[3], MiscUnSelectedTab); //HERE
g_pSurface->FilledRect(tab_area[0], tab_area[1] + tab_area[3], tab_area[2], 3, MiscUnSelectedTab_Highlight); //HERE
g_pSurface->DrawT(tab_area[0] + (((in_sizew_esp_player_subtabs / tab_amount) / 2) - (text_size2.right / 2)),
tab_area[1] + (tab_area[3] / 2) - (text_size2.bottom / 2),
Color(143, 143, 143, MenuAlpha_Main), Globals::SmallText, false,
ESP_Player_SubTabs_Names[i].c_str());
}
}
}
Any help would be greatly appreciated.
Thanks -Kenny
You can define a seperate Theme struct for it and use all colors from a Theme variable.
class Theme {
public:
enum Style {BASIC, RAINBOW, CUSTOM};
Style style;
Color MiscSelectedTab;
Color MiscSelectedTab_Highlight;
Color MiscUnSelectedTab;
Color MiscUnSelectedTab_Highlight;
}
Theme MenuColor(int MenuAlpha_Main)
{
Theme theme;
...
if (c_config::get().menu_colour_style == 0) {
theme.style = Theme::BASIC; //Normal Style
}
else if (c_config::get().menu_colour_style == 1) {
theme.style = Theme::RAINBOW; //Rainbow
}
else if (c_config::get().menu_colour_style == 2) {
theme.style = Theme::CUSTOM;
//This shit is done below
}
....
return theme;
}
...
Theme myTheme = MenuColor(5);
myTheme.MiscSelectedTab;
myTheme.MiscSelectedTab_Highlight;
myTheme.MiscUnSelectedTab;
myTheme.MiscUnSelectedTab_Highlight;

p5.js - get a rectangle to move left and right repeatedly (bounce)

I'm trying out some sample code for a bigger project, and I'm having trouble getting my rectangle to bounce between two lines.
function draw() {
print(frameCount)
background(255)
var x = 150 + frameCount;
rect(x,200,15,15);
line(150,0,150,400);
line(250,0,250,400);
if (x >= 250) {
background(255)
x = 350-frameCount;
rect(x,200,15,15);
line(250,0,250,400);
line(150,0,150,400);
} if (x <= 145) {
background(255)
x = 145 + (frameCount % 100);
rect(x,200,15,15);
line(250,0,250,400);
line(150,0,150,400);
}
}
I'm getting the feeling that after the first instance, it's disregarding the original if statement, which dictates a bounce to the left. I'm really not sure what's going wrong, and any help would be appreciated.
You probably just want to store the current position and speed in a set of variables, and then move the rectangle based on those. Here's an example:
var x = 0;
var speed = 1;
function draw(){
x += speed;
if(x < 0 || x > width){
speed *= -1;
}
background(64);
line(x, 0, x, height);
}
I've written a tutorial on this available here. That's for regular Processing, but the ideas are the same in P5.js.

Photoshop CS4 Script or Action to: Write 0 to 100 on separate text layers

My goal is to create 101 separate text layers containing 0-100 (i.e. 1, 2, 3...100) I know I can mass change the attributes but cant write or alter the containing text.
What you want can easily be done with a script (easier than renaming 100 layers in all the right order and record an action for it) This script will create 100 layers of text, each layer will be named 1,2,3..etc and the text will be the same. I think that's waht you are after, your description was rather short.
// call the source document
var srcDoc = app.activeDocument;
var numOfLayers = 100;
//var numOfLayers = srcDoc.layers.length;
var numPadding = "0";
var layerNum = 1; // change this to 0 to start layers at 0
var w = Math.floor(srcDoc.width.value/2);
var h = Math.floor(srcDoc.height.value/2);
// main loop starts here
for (var i = numOfLayers -1; i >= 0 ; i--)
{
if (layerNum < 10) numPadding = "0";
else numPadding ="";
createText("Arial-BoldMT", 20.0, 0,0,0, layerNum, w, h);
var currentLayer = srcDoc.activeLayer;
currentLayer.name = numPadding + layerNum;
layerNum +=1;
}
// function CREATE TEXT(typeface, size, R, G, B, content, Xpos, Ypos)
// --------------------------------------------------------
function createText(fface, size, colR, colG, colB, content, tX, tY)
{
var artLayerRef = srcDoc.artLayers.add()
artLayerRef.kind = LayerKind.TEXT
textColor = new SolidColor();
textColor.rgb.red = colR;
textColor.rgb.green = colG;
textColor.rgb.blue = colB;
textItemRef = artLayerRef.textItem
textItemRef.font = fface;
textItemRef.contents = content;
textItemRef.color = textColor;
textItemRef.size = size
textItemRef.position = new Array(tX, tY) //pixels from the left, pixels from the top
activeDocument.activeLayer.textItem.justification.CENTER
}
Save this out as numberLayers1-100.jsx and then reun it from Photoshop via the Files -> Scripts menu.