簡體   English   中英

PHP 解鎖圖案圖形查看器

[英]PHP unlock pattern graphical viewer

我創建了一個解鎖模式查看器。 通過給腳本一個解鎖模式,例如“1-5-9”,它會為你繪制它。 但是,當解鎖圖案以數字 7 或 8 開頭時,我遇到了一些錯誤。然后它在數字 6 中放置了一個點。

1-4-7-8-9

在此處輸入圖像描述

1-5-9

在此處輸入圖像描述

8-5-2-3 - 這里腳本在數字 6 中畫了一個點

在此處輸入圖像描述

我的劇本

要使腳本正常工作,只需運行以下命令: unlock_pattern_drawer_to_image.php?pattern=8-5-2-3

<?php 
/**
*
* File: edb/unlock_pattern_drawer_to_image.php
* Version 1.1
* Date 13:04 03.07.2020
* Copyright (c) 2019-2020 S. A. Ditlefsen
* License: http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/*- Variables -------------------------------------------------------------------------- */
if(isset($_GET['pattern'])) {
    $pattern = $_GET['pattern'];
    $pattern = strip_tags(stripslashes($pattern));
}
else{
    $pattern = "";
}

$pattern_array = explode("-", $pattern);
$pattern_array_size = sizeof($pattern_array);


/*- Generate image ---------------------------------------------------------------------- */

$img_width = 150;
$img_height = 150;
 
$img = imagecreatetruecolor($img_width, $img_height);

$white = imagecolorallocate($img, 255, 255, 255);
$light_blue = imagecolorallocate($img, 134, 180, 203);
$dark_blue  = imagecolorallocate($img, 9, 39, 88);
$red  = imagecolorallocate($img, 100, 44, 44);
 
imagefill($img, 0, 0, $white);

// Draw 3x3 circles
// Ready cordinates
$cord_counter = 1;
for($x=1;$x<4;$x++){
    for($y=1;$y<4;$y++){
        $from_left = ($x*50)-25;
        $from_top  = ($y*50)-25;
        imageellipse($img, $from_left, $from_top, 20, 20, $light_blue);

        // Cord
        $cord_array_x[$cord_counter] = "$from_left";
        $cord_array_y[$cord_counter] = "$from_top";

        $cord_counter = $cord_counter + 1;
    } // y
} // x

// Draw the array
for($z=0;$z<$pattern_array_size;$z++){
    $pattern_placement = $pattern_array[$z];
    $place_on_image_cord_x = $cord_array_x[$pattern_placement];
    $place_on_image_cord_y = $cord_array_y[$pattern_placement];

    // echo"<p>z=$z. pattern_placement=$pattern_placement</p>\n";

    // First = circle, rest=arrow, last=diamond
    if($z == 0){
        imagefilledellipse($img, $place_on_image_cord_x, $place_on_image_cord_y, 6, 6, $dark_blue);
    }
    elseif($z == $pattern_array_size-1){
        imagefilledrectangle($img, $place_on_image_cord_y-3, $place_on_image_cord_x-3, $place_on_image_cord_y+3, $place_on_image_cord_x+3, $dark_blue);
    }
    else{

    }

    if(isset($coming_from_place_on_image_cord_x)){
        imageline($img, $coming_from_place_on_image_cord_y, $coming_from_place_on_image_cord_x, $place_on_image_cord_y, $place_on_image_cord_x, $dark_blue);    
    }
    

    // Transfer
    $coming_from_pattern_placement = "$pattern_placement";
    $coming_from_place_on_image_cord_x = "$place_on_image_cord_x";
    $coming_from_place_on_image_cord_y = "$place_on_image_cord_y";
} // z


header("Content-type: image/png"); 
imagepng($img);

?>

所以你自己的評論說神秘的點應該是繪圖的開始

    // First = circle, rest=arrow, last=diamond
    if($z == 0){
        imagefilledellipse($img, $place_on_image_cord_x, $place_on_image_cord_y, 6, 6, $dark_blue);
    }

所以顯然它的 position 被錯誤地選擇了。 不僅開始是七八。 如果您嘗試從起點 1 到 9 系統地進行模式化,您會立即看到問題所在,並且您只需更改兩個字符即可修復它。

$pattern_array[$z]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM