[已解决]一年级数学"圈一圈", 用虚线圈出指定数量算法
本帖最后由 雨林GG 于 2016-11-25 05:26 编辑一年级数学看图列式, 9 - 5 = ? 已知图形位置数组, $gArray存放着图片的"行数, 宽度, 列宽, 列数, 高度, 行高", 从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, ",")
For $iRow = 1 To $gaT
For $iCol = 1 To $gaT
If $gArray[$iRow][$iCol] = "" Then ContinueLoop
$iLeft = StringRegExpReplace($gArray[$iRow][$iCol], ',\d+', "")
$iTop = StringReplace($gArray[$iRow][$iCol], $iLeft & ",", "")
$Pic = GUICtrlCreatePic("", $iLeft, $iTop, $gaT, $gaT)
_GdiImage_ToGuiPic($gFile, $Pic, $gaT, $gaT)
Next
Next
GUISetState()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hPen = _GDIPlus_PenCreate(0xFF000000, 5)
_GDIPlus_PenSetDashStyle ($hPen, $GDIP_DASHSTYLEDOT) ;点线
_GDIPlus_GraphicsDrawLine($hGraphic, 468 + $gaT + 5, 23 -5, 468 + $gaT + 5, 267 + $gaT + 5, $hPen)
Sleep(500)
_GDIPlus_GraphicsDrawLine($hGraphic, 468 + $gaT + 5, 267 + $gaT + 5, 319 - 5, 267 + $gaT + 5, $hPen)
Sleep(500)
_GDIPlus_GraphicsDrawLine($hGraphic, 319 - 5, 267 + $gaT + 5, 319 - 5, 145 - 5, $hPen)
Sleep(500)
_GDIPlus_GraphicsDrawLine($hGraphic, 319 - 5, 145 - 5, 319 + 5 + $gaT + $gaT/2, 145 - 5, $hPen)
Sleep(500)
_GDIPlus_GraphicsDrawLine($hGraphic, 319 + 5 + $gaT + $gaT/2, 145 - 5, 319 + 5 + $gaT + $gaT/2, 23 -5, $hPen)
Sleep(500)
_GDIPlus_GraphicsDrawLine($hGraphic, 319 + 5 + $gaT + $gaT/2, 23 -5, 468 + $gaT + 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 圈几只小鸡不如换几只为不同色的小鸡 回复 2# afan
课本上给出的例题就是虚线的为减法 回复 3# 雨林GG
那你折腾请无视回复 帮你顶{:face (427):} 本帖最后由 pcbar 于 2016-11-23 12:52 编辑
实在无聊也来圈小鸡.{:face (197):}
小鸡的布局在1处修改
圈几只小鸡在2处修改
RE: 一年级数学"圈一圈", 用虚线圈出指定数量算法
回复 6# pcbar我也是昨天刚写完, 我的思路是先根据数, 随机(从行或列,从左或右)抽取, 做上标志, 然后从第一行第一列左上角开始 上下左右 寻找, 划上线. 看了还是版主的划线方法巧妙, 搜索4条线, 有就删, 很巧妙, 又简单, 谢谢您的帮助...
页:
[1]