0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ストワで始めるLua第四回のコード

Last updated at Posted at 2023-04-15

動画はこちら

LPF
x=0
k=0.1
function lpf(prex,low)
	return (1-k)*prex+k*low
end

function onTick()
	local z=math.random()-0.5

	x=lpf(x,z)
	
	output.setNumber(1,x)
	output.setNumber(2,z)
end

モニターのボタン
selectFlg=false
isTouching=false

flagA=false

function isPointInRectangle(x, y, rectX, rectY, rectW, rectH)
    --x,y:input  rectX,Y:LeftUp Rect   rectW,H:size
 	return x > rectX and y > rectY and x < rectX+rectW and y < rectY+rectH
end

function onTick()
	local w,h,x,y,inputX,inputY
	--input
	
	isTouch=input.getBool(1)
	w=input.getNumber(1)
	h=input.getNumber(2)
	inputX=input.getNumber(3)
	inputY=input.getNumber(4)
	
	--Touch display
	if isTouch==true and isTouching==false then
		isTouching=true
		if isPointInRectangle(inputX,inputY,0,0,4,5) then
			flagA=not(flagA)
		end
	end

    --release button
	if isTouch==false then
		isTouching=false
	end
end

function onDraw()
	--display
	local w,h
	w=screen.getWidth()
	h=screen.getHeight()
	
	if flagA then
		screen.setColor(0,255,0)
	else
		screen.setColor(255,0,0)
	end
	screen.drawRectF(0,0,4,5)
	
	screen.setColor(255,255,255)
	
	screen.drawText(0,0,"A")
end

追記
動画内で言及するのを忘れていた部分。
引数はローカル変数になるといっていますが、関数の引数にテーブルを使用した場合は、
関数内で値を変更するとテーブル内の値も変わってしまうため注意が必要です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?