HSPポータル
サイトマップ お問い合わせ


HSPTV!掲示板


未解決 解決 停止 削除要請

2018
0921
marishi簡易ペイントソフトを作っています...9解決


marishi

リンク

2018/9/21(Fri) 18:22:10|NO.85396

簡易ペイントソフトを作っています。

repeat -1 getkey pa,1 getkey del,46 if pa=1 { ;pos mousex,mousey circle mousex,mousey,mousex+10,mousey+10,1 } if del=1 { dialog "本当にスクリーン上の絵を消していい?",3,"yeペイント" if stat=6 : cls } wait 1 loop
このままだと素早くマウスを動かすと、点々としてしまいます。
なんとかできませんか?



この記事に返信する


Nanashinogon

リンク

2018/9/21(Fri) 22:01:31|NO.85399

厨房から1つ提案。
こっちは丸で書きませんが、比較的簡単かと思います!

repeat -1 getkey pa,1 getkey del,46 ;ここで1ウェイト前のマウス座標を覚えておく savemousex=mousex savemousey=mousey wait 1 if pa=1 { ;pos mousex,mousey ;丸で描かせるのではなく、線を使ったほうが簡単ですよ! line mousex,mousey,savemousex,savemousey } if del=1 { dialog "本当にスクリーン上の絵を消していい?",3,"yeペイント" if stat=6 : cls } loop
どうでしょうか!



名無し

リンク

2018/9/21(Fri) 22:17:22|NO.85400

wait 1よりもawait 16の方が安定して使えますよ。
あんまり気にしなくてもいいですよ。



Nanashinogon

リンク

2018/9/21(Fri) 22:29:50|NO.85401

>>wait 1よりもawait 16の方が安定して使えますよ。
確かにそちらのほうが正確に描ける気がします。
従って、名無しさんの言う通り、wait 1よりawait 16の方が良いということでしょう!



marishi

リンク

2018/9/22(Sat) 09:59:16|NO.85402

ありがとうございます。でも丸でも書きたいです。
線で描くものは採用します。

screen 0,ginfo(20),ginfo(21),screen_hide #packopt hide 1 #include "user32.as" LoadCursor 0, 32515;+字のポインター SetClassLong hwnd, -12, stat GetWindowLong hwnd, -16;最大化できるように。 SetWindowLong hwnd, -16, stat | $10000 | $40000;々 width 640,480;ウィンドウサイズ gsel 0,1 repeat -1 savemousex=mousex savemousey=mousey await 16 if ginfo_act=0 { getkey pa,1 getkey del,46 getkey col,67 getkey li,2 if li=1 : line mousex,mousey,savemousex,savemousey if pa=1 { ;pos mousex,mousey circle mousex,mousey,mousex+10,mousey+10,1 } if del=1 { dialog "本当にスクリーン上の絵を消していい?",3,"yeペイント" if stat=6 : cls } if col=1 { dialog "",33,"" color ginfo_r,ginfo_g,ginfo_b } } loop
右クリックで線、左クリックで丸となっています



さか

リンク

2018/9/22(Sat) 11:26:28|NO.85404

これでどうですか。
離れた2点の距離(i)と移動量(vx,vy)を求めて間を描画します。
上記の処理を関数化した方が応用も聞いてすっきりしそう。


sx=-1.0: sy=-1.0 repeat -1 getkey pa,1 getkey del,46 if pa=1 { x=0.0+mousex: y=0.0+mousey circle x,y,x+10,y+10,1 if sx>0{ p1 = sx, sy p2 = x, y i = sqrt( (sx-x)*(sx-x) + (sy-y)*(sy-y) ) if i>0: vx=0.0+(x-sx)/i: vy=0.0+(y-sy)/i repeat i circle sx,sy,sx+10,sy+10,1 sx+=vx: sy+=vy loop } sx=0.0+x: sy=0.0+y }else{ sx=-1.0: sy=-1.0 } if del=1 { dialog "本当にスクリーン上の絵を消していい?",3,"yeペイント" if stat=6 : cls } wait 1 loop



marishi

リンク

2018/9/22(Sat) 11:42:51|NO.85405

ありがとうございます。
無事に点々とならず、できました。

title "yeペイント" screen 0,ginfo(20),ginfo(21),screen_hide sx=-1.0: sy=-1.0 #packopt hide 1 #include "user32.as" loadCursor 0, 32515 SetClassLong hwnd, -12, stat GetWindowLong hwnd, -16 SetWindowLong hwnd, -16, stat | $10000 | $40000 width 640,480 gsel 0,1 repeat -1 savemousex=mousex savemousey=mousey await 16 if ginfo_act=0 { getkey pa,1 getkey del,46 getkey col,67 getkey li,2 if li=1 : line mousex,mousey,savemousex,savemousey if pa=1 { x=0.0+mousex: y=0.0+mousey circle x,y,x+10,y+10,1 if sx>0{ p1 = sx, sy p2 = x, y i = sqrt( (sx-x)*(sx-x) + (sy-y)*(sy-y) ) if i>0: vx=0.0+(x-sx)/i: vy=0.0+(y-sy)/i repeat i circle sx,sy,sx+10,sy+10,1 sx+=vx: sy+=vy loop } sx=0.0+x: sy=0.0+y }else{ sx=-1.0: sy=-1.0 } if del=1 { dialog "本当にスクリーン上の絵を消していい?",3,"yeペイント" if stat=6 : cls } if col=1 { dialog "",33,"" color ginfo_r,ginfo_g,ginfo_b } } loop



あらや

リンク

2018/9/22(Sat) 11:47:05|NO.85406

APIを使ってペンの太さを変える方法もあります。

wikiの直線モジュール(ページの一番下)をそのまま使用しました。
https://wiki.hsp.moe/Paint%EF%BC%8Fline.html#cb5780c7


; ; 描画命令モジュール ; for HSP3 ; #uselib "gdi32.dll" #func global CreatePen "CreatePen" int, int, int #func global SelectObject "SelectObject" int,int #func global Polyline "Polyline" int, var, int #func global DeleteObject "DeleteObject" int #define global ctype RGB(%1,%2,%3) ((%3*65536)+(%2*256)+%1) ;CreatePen用定数 #define global PS_SOLID 0 // 全て塗りつぶし #define global PS_DASH 1 // ------- #define global PS_DOT 2 // ....... #define global PS_DASHDOT 3 // _._._._ #define global PS_DASHDOTDOT 4 // _.._.._ #define global PS_NULL 5 // 空のペンを作成します。描画は行われません。 #define global PS_INSIDEFRAME 6 // 実線のペンを作成します。 ;--------------------------------------------------------------------------- #module ;拡張line命令。 ;点線・破線、太さを変更した直線を描画。 #deffunc s_line int slx, int sly, int elx, int ely, int fnPenStyle, int nWidth ;slx 線を引き始める位置X ;sly 線を引き始める位置Y ;elx 線を引き終わる位置X ;ely 線を引き終わる位置Y ;fnPenStyle 線のタイプ(0〜4) ; PS_SOLID 0 // 実線 ; PS_DASH 1 // ------- ; PS_DOT 2 // ....... ; PS_DASHDOT 3 // _._._._ ; PS_DASHDOTDOT 4 // _.._.._ ; PS_NULL 5 // 空のペンを作成します。描画は行われません。 ; PS_INSIDEFRAME 6 // 実線のペンを作成します。 ;nWidth 線の太さ ;ペンの作成 CreatePen fnPenStyle, nWidth, RGB(ginfo_r, ginfo_g, ginfo_b) hPen = stat : if hPen=0 : dialog "ペン設定に失敗しました",1,"エラー" : return 1 ;ライン描画 SelectObject hdc, hPen hOldPen = stat ; dim point,4 point = slx, sly, elx, ely Polyline hdc, point, 2 if stat = 0 : dialog "描画に失敗しました",1,"エラー" : return 1 DeleteObject hPen SelectObject hdc, hOldPen return #global ;--------------------------------------------------------------------------- screen 0,ginfo(20),ginfo(21),screen_hide #packopt hide 1 #include "user32.as" LoadCursor 0, 32515;+字のポインター SetClassLong hwnd, -12, stat GetWindowLong hwnd, -16;最大化できるように。 SetWindowLong hwnd, -16, stat | $10000 | $40000;々 width 640,480;ウィンドウサイズ gsel 0,1 repeat -1 savemousex=mousex savemousey=mousey await 16 if ginfo_act=0 { getkey pa,1 getkey del,46 getkey col,67 getkey li,2 if li=1 :line mousex,mousey,savemousex,savemousey if pa=1 :s_line mousex,mousey,savemousex,savemousey, PS_SOLID, 10 if del=1 { dialog "本当にスクリーン上の絵を消していい?",3,"yeペイント" if stat=6 : cls } if col=1 { dialog "",33,"" color ginfo_r,ginfo_g,ginfo_b } } redraw 1; これが無いと描画されない loop



Nanashinogon

リンク

2018/9/23(Sun) 20:48:11|NO.85424

完成したら宣伝のスレ、作ってくださいね!



marishi

リンク

2018/9/24(Mon) 09:32:41|NO.85431

>85424
OKです!



ONION software Copyright 1997-2023(c) All rights reserved.