找回密码
 加入
搜索
查看: 3552|回复: 6

[效率算法] [已解决]一年级数学"圈一圈", 用虚线圈出指定数量算法

  [复制链接]
发表于 2016-11-9 08:53:31 | 显示全部楼层 |阅读模式
本帖最后由 雨林GG 于 2016-11-25 05:26 编辑


    一年级数学看图列式, 9 - 5 = ? 已知图形位置数组, $gArray[0][0]存放着图片的"行数, 宽度, 列宽, 列数, 高度, 行高", 从1行1列开始存放各个图片的位置。
    减5, 就圈出5张图片,可以从左也可以从右开始,如何来计算怎么圈法?不知有没有朋友做过,请不吝赐教,给个思路或参考资料都可以,我实在是没有办法。
附例:
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <Array.au3>
Global $ghGDIPDll = "GdiPlus.dll"

Global $hGUI, $hGraphic, $hPen
Global $gFile = "小鸡.png"
Global $gArray[][] = [["3,112,37,4,112,10"], _ ;行数, 宽度, 列宽, 列数, 高度, 行高
                ["",        "",                        "",                         "319,23",                 "468,23"], _ ;图片的位置
                ["",        "",                        "170,145",                 "319,145",                "468,145"], _
                ["",        "21,267",        "170,267",                 "319,267",                "468,267"]]
_ArrayDisplay($gArray)
_GDIPlus_Startup()
$hGUI = GUICreate("圈一圈", 600, 400)
$gaT = StringSplit($gArray[0][0], ",")
For $iRow = 1 To $gaT[1]
        For $iCol = 1 To $gaT[4]
                If $gArray[$iRow][$iCol] = "" Then ContinueLoop
                $iLeft = StringRegExpReplace($gArray[$iRow][$iCol], ',\d+', "")
                $iTop = StringReplace($gArray[$iRow][$iCol], $iLeft & ",", "")
                $Pic = GUICtrlCreatePic("", $iLeft, $iTop, $gaT[2], $gaT[5])
                _GdiImage_ToGuiPic($gFile, $Pic, $gaT[2], $gaT[5])
        Next
Next
GUISetState()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hPen = _GDIPlus_PenCreate(0xFF000000, 5)
_GDIPlus_PenSetDashStyle ($hPen, $GDIP_DASHSTYLEDOT) ;点线

_GDIPlus_GraphicsDrawLine($hGraphic, 468 + $gaT[2] + 5, 23 -5, 468 + $gaT[2] + 5, 267 + $gaT[5] + 5, $hPen)
Sleep(500)
_GDIPlus_GraphicsDrawLine($hGraphic, 468 + $gaT[2] + 5, 267 + $gaT[5] + 5, 319 - 5, 267 + $gaT[5] + 5, $hPen)
Sleep(500)
_GDIPlus_GraphicsDrawLine($hGraphic, 319 - 5, 267 + $gaT[5] + 5, 319 - 5, 145 - 5, $hPen)
Sleep(500)
_GDIPlus_GraphicsDrawLine($hGraphic, 319 - 5, 145 - 5, 319 + 5 + $gaT[5] + $gaT[3]/2, 145 - 5, $hPen)
Sleep(500)
_GDIPlus_GraphicsDrawLine($hGraphic, 319 + 5 + $gaT[5] + $gaT[3]/2, 145 - 5, 319 + 5 + $gaT[5] + $gaT[3]/2, 23 -5, $hPen)
Sleep(500)
_GDIPlus_GraphicsDrawLine($hGraphic, 319 + 5 + $gaT[5] + $gaT[3]/2, 23 -5, 468 + $gaT[2] + 5, 23 -5, $hPen)

_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()

; 循环到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE


Func _GdiImage_ToGuiPic($sFile, $iCtrl, $iW_Img, $iH_Img)
        If Not FileExists($sFile) Then Return SetError(1, 0, 0)
        Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)
        If @error Then Return SetError(2, 0, 0)
        ;Local $iW_Img = _GDIPlus_ImageGetWidth($hImage), $iH_Img = _GDIPlus_ImageGetHeight($hImage)
        Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW_Img, $iH_Img)
        Local $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap)
        ;_GDIPlus_SetSmoothingMode($hGfx)
        ;_GDIPlus_GraphicsSetSmoothingMode($hGfx, 2) ;$GDIP_SMOOTHINGMODE_HIGHQUALITY = 2 ; Specifies that smoothing is applied using an 8 X 4 box filter.
        _GDIPlus_GraphicsSetInterpolationMode($hGfx, 7)

        _GDIPlus_GraphicsDrawImageRect($hGfx, $hImage, 0, 0, $iW_Img, $iH_Img)

        Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
        _GDIPlus_GraphicsDispose($hGfx)
        _GDIPlus_BitmapDispose($hBitmap)
        _GDIPlus_ImageDispose($hImage)
        ;_WinAPI_DeleteObject(GUICtrlSendMsg($iCtrl, 0x0172, 0x0000, 0)) ;delete previous image in pic control
        _WinAPI_DeleteObject(GUICtrlSendMsg($iCtrl, 0x0172, 0x0000, $hHBitmap)) ;STM_SETIMAGE = 0x0172
        _WinAPI_DeleteObject($hHBitmap)
EndFunc   ;==>_GdiImage_ToGuiPic

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2016-11-9 16:43:11 | 显示全部楼层
圈几只小鸡  不如换几只为不同色的小鸡
 楼主| 发表于 2016-11-9 18:21:29 | 显示全部楼层
回复 2# afan


    课本上给出的例题就是虚线的为减法
发表于 2016-11-9 19:32:08 | 显示全部楼层
回复 3# 雨林GG


    那你折腾  请无视回复
发表于 2016-11-9 20:51:56 | 显示全部楼层
帮你顶
发表于 2016-11-23 12:41:56 | 显示全部楼层
本帖最后由 pcbar 于 2016-11-23 12:52 编辑

实在无聊也来圈小鸡.

小鸡的布局在1处修改

圈几只小鸡在2处修改


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 1金钱 +40 收起 理由
雨林GG + 40 划线方法好

查看全部评分

 楼主| 发表于 2016-11-25 05:23:07 | 显示全部楼层

RE: 一年级数学&quot;圈一圈&quot;, 用虚线圈出指定数量算法

回复 6# pcbar


   我也是昨天刚写完, 我的思路是先根据数, 随机(从行或列,从左或右)抽取, 做上标志, 然后从第一行第一列左上角开始 上下左右 寻找, 划上线. 看了还是版主的划线方法巧妙, 搜索4条线, 有就删, 很巧妙, 又简单, 谢谢您的帮助...
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-27 12:44 , Processed in 0.119417 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表