Previous Thread
Next Thread
Print Thread
Page 1 of 3 1 2 3
Joined: Feb 2014
Posts: 1,016
Likes: 110
G
Very Senior Member
OP Offline
Very Senior Member
G
Joined: Feb 2014
Posts: 1,016
Likes: 110
I wanted to see a moving big trak so I was experimenting with a layout that would show a moving image:



It's a bit imprecise, but it is fun to see something moving.

3 members like this: Waremonger, Dullaron, ICEknight
Joined: Mar 2001
Posts: 17,093
Likes: 153
R
Very Senior Member
Offline
Very Senior Member
R
Joined: Mar 2001
Posts: 17,093
Likes: 153
That's cool. I didn't know you could move things arbitrarily in layouts like that.

Joined: Feb 2014
Posts: 1,016
Likes: 110
G
Very Senior Member
OP Offline
Very Senior Member
G
Joined: Feb 2014
Posts: 1,016
Likes: 110
I had to add math to the layout plugin so I could do sin, cos and floor, then just looking at the motor status and updating xpos, ypos and ang.

Then using the set_bounds_callback to return a bounding box.

For the rotation, I generated 360 image states (1 for each degree of rotation) and used the set_element_state_callback to return the image number.
(This is terribly inefficient, the layout size ends up being 800k or so).

Code
<!-- the content of the script element will be called as a function by the layout plugin -->
<!-- use CDATA block to avoid the need to escape angle brackets and ampersands -->

<script><![CDATA[

-- file is the layout file object
print("BIGTRAK2.LAY")
print("LAYOUT LOADED  file.device.name = "..file.device.name)
print("LAYOUT LOADED  file.device.shortname = "..file.device.shortname)
print("LAYOUT LOADED  file.device.tag = = "..file.device.tag)
print(math.cos(3.4))  -- math isn't in env table
print(machine.output:get_value("left_motor_forward"))
print(machine.output:get_value("motor_pos"))

speed = 9 / 60
axle = 6.4 / 2
ang = 0
xpos = 50
ypos = 50

function calcpos(val) 
	if     val == "11000" then xpos = xpos + math.cos(ang) * speed ypos = ypos + math.sin(ang) * speed 
	elseif val == "00110" then xpos = xpos - math.cos(ang) * speed ypos = ypos - math.sin(ang) * speed 
	elseif val == "10010" then ang = ang + speed / axle 
	elseif val == "01100" then ang = ang - speed / axle 
	print(ang) 
	end 
end


file:set_resolve_tags_callback(
	function ()

	file.views["Internal Layout"].items["bigtrak"]:set_bounds_callback(
		function ()
			local b = emu.render_bounds()
			local boxxsize = 25
			local boxysize = 25
			xc = xpos
			yc = ypos
			x0 = xc - boxxsize / 2
			y0 = yc - boxysize / 2
			x1 = xc + boxxsize / 2
			y1 = yc + boxysize / 2

			bs = 1/100 -- boundscale (must scale it down to between 0.0 and 1.0)
			b:set_xy(x0 * bs, y0 * bs, x1 * bs, y1 * bs)
			
			out = machine.output
			newval = tostring(out:get_value("left_motor_forward")) .. 
					tostring(out:get_value("right_motor_forward")) .. 
					tostring(out:get_value("left_motor_reverse")) .. 
					tostring(out:get_value("right_motor_reverse")) .. 
					tostring(out:get_value("0.1")) 
			print(newval, xpos, ypos, x0, y0, x1, y1, ang)
			calcpos(newval)
			return b
		end)
		
	file.views["Internal Layout"].items["bigtrak"]:set_element_state_callback(
		function ()
			image = math.floor(ang / 3.14 * 180.0)
			image = (image + 90) % 360
			print ("image" .. image)
			return image
		end)


		
 end)

]]></script>


Joined: Mar 2001
Posts: 17,093
Likes: 153
R
Very Senior Member
Offline
Very Senior Member
R
Joined: Mar 2001
Posts: 17,093
Likes: 153
Oh, the rotation is fake? I'm surprised there aren't fruit machines or something that could use "native" rotation.

Joined: Feb 2014
Posts: 1,016
Likes: 110
G
Very Senior Member
OP Offline
Very Senior Member
G
Joined: Feb 2014
Posts: 1,016
Likes: 110
Yes, if you could do 2d rotation of svgs or bitmaps that would be brilliant.

Joined: Feb 2014
Posts: 1,016
Likes: 110
G
Very Senior Member
OP Offline
Very Senior Member
G
Joined: Feb 2014
Posts: 1,016
Likes: 110
[Linked Image from i.imgur.com]

Managed to get a working keypad going, that's all I have the patience for today.

Last edited by Golden Child; 09/23/23 12:41 PM.
Joined: Feb 2014
Posts: 1,016
Likes: 110
G
Very Senior Member
OP Offline
Very Senior Member
G
Joined: Feb 2014
Posts: 1,016
Likes: 110
Figured out how to use groups, experimenting with showing dual keypads at once.

Pressing the 1 key:

[Linked Image from i.imgur.com]

2 members like this: Foxhack, robcfg
Joined: Feb 2014
Posts: 1,016
Likes: 110
G
Very Senior Member
OP Offline
Very Senior Member
G
Joined: Feb 2014
Posts: 1,016
Likes: 110
I was playing around with parameters so I wouldn't have to repeat a bunch of slightly different code.


So the idea is to have a few colors as parameters that would make it easier to just cut and paste the same code.

If the colors are the same for the next button, just don't change them for the next button.

And then also use a parameter for the text string.


Code
<!-- col0 is background  yellow -->
	<param name="col0r" value="0.97"/> 
	<param name="col0g" value="0.76"/>
	<param name="col0b" value="0.26"/>
	
	<!-- col1 is text color  black -->
	<param name="col1r" value="0.0"/>
	<param name="col1g" value="0.0"/>
	<param name="col1b" value="0.0"/>

	<!-- col2 is highlight background color black -->
	<param name="col2r" value="0.0"/> 
	<param name="col2g" value="0.0"/>
	<param name="col2b" value="0.0"/>
	
	<!-- col3 is highlight text color yellow -->
	<param name="col3r" value="0.97"/>
	<param name="col3g" value="0.76"/>
	<param name="col3b" value="0.26"/>



	<repeat count="10">
		<param name="str0" start="0" increment="1"/>
		<element name="key~str0~ref">
		  <rect><color red="0.0" blue="0.0" green="0.0"/></rect>
		  
		  <rect state="0"><color red="~col0r~" green="~col0g~" blue="~col0b~"/>
		  	<bounds left="0.05" right="0.95" top="0.05" bottom="0.95" /></rect>
		  	
	  	  <text state="0" string="~str0~"><color red="~col1r~" green="~col1g~" blue="~col1b~"/>
	  	  	  	<bounds left="-0.10" right="1.10" top="-0.10" bottom="1.10" /></text>
	  	  	  	
		  <rect state="1"><color red="~col2r~" green="~col2g~" blue="~col2b~"/>
		  	<bounds left="0.05" right="0.95" top="0.05" bottom="0.95" /></rect>
		  	
	  	  <text state="1" string="~str0~"><color red="~col3r~" green="~col3g~" blue="~col3b~"/>
	  	  	<bounds left="0.10" right="0.90" top="0.10" bottom="0.90" /></text>
		</element>
	</repeat>	
		
		
Code
	<!-- col0 is background  green -->
	<param name="col0r" value="0.15"/> 
	<param name="col0g" value="0.44"/>
	<param name="col0b" value="0.40"/>
	
	<!-- col1 is text color  red -->
	<param name="col1r" value="1.0"/>
	<param name="col1g" value="0.0"/>
	<param name="col1b" value="0.0"/>

	<!-- col2 is highlight background color -->
	<param name="col2r" value="1.0"/> 
	<param name="col2g" value="0.0"/>
	<param name="col2b" value="0.0"/>
	
	<!-- col3 is highlight text color -->
	<param name="col3r" value="0.15"/>
	<param name="col3g" value="0.44"/>
	<param name="col3b" value="0.40"/>

	<param name="str0" value="FIRE"/>


	<element name="keyfireref">
	  <rect><color red="0.0" blue="0.0" green="0.0"/></rect>
	  
	  <rect state="0"><color red="~col0r~" green="~col0g~" blue="~col0b~"/>
	  	<bounds left="0.05" right="0.95" top="0.05" bottom="0.95" /></rect>
	  	
  	  <text state="0" string="~str0~"><color red="~col1r~" green="~col1g~" blue="~col1b~"/>
  	  	  	<bounds left="0.10" right="0.90" top="0.10" bottom="0.90" /></text>
  	  	  	
	  <rect state="1"><color red="~col2r~" green="~col2g~" blue="~col2b~"/>
	  	<bounds left="0.05" right="0.95" top="0.05" bottom="0.95" /></rect>
	  	
  	  <text state="1" string="~str0~"><color red="~col3r~" green="~col3g~" blue="~col3b~"/>
  	  	<bounds left="0.10" right="0.90" top="0.10" bottom="0.90" /></text>
	</element>




One thing that I was thinking about was a parameter that would have a list of values, and each time the parameter is used, it will return the next value in the list.


so you could turn this:

Code
<element ref="keyclrref" inputtag="IN.0" inputmask="0x8">
			<bounds x="30" y="0" width="8" height="8" />
</element>
<element ref="keyfireref" inputtag="IN.0" inputmask="0x4">
			<bounds x="30" y="10" width="8" height="8" />
</element>


<element ref="keyclsref" inputtag="IN.1" inputmask="0x8">
			<bounds x="30" y="20" width="8" height="8" />
</element>

<element ref="keyrptref" inputtag="IN.2" inputmask="0x8">
			<bounds x="30" y="30" width="8" height="8" />
</element>


into something like:

Code
<param name="item" list="clr,IN.0,0x8,30,0,fire,IN.0,0x4,30,10,cls,IN.1,0x8,30,20,rpt,IN.2,0x8,30,30">

<repeat count="4">
<element ref="key~item~ref" inputtag="~item~" inputmask="~item~">
			<bounds x="~item~" y="~item~" width="8" height="8" />
</element>
</repeat>

Joined: Feb 2014
Posts: 1,016
Likes: 110
G
Very Senior Member
OP Offline
Very Senior Member
G
Joined: Feb 2014
Posts: 1,016
Likes: 110
Here's a video with the keypad and also resizing the trak and repositioning it (as it can go off the screen pretty easily).


1 member likes this: exidyboy
Joined: Feb 2014
Posts: 1,016
Likes: 110
G
Very Senior Member
OP Offline
Very Senior Member
G
Joined: Feb 2014
Posts: 1,016
Likes: 110
Discovered love2d and was playing around with a keyboard controlled rotating image.

What I'd like to do is to figure out how to send data to a love2d lua program that would display the big trak.


1 member likes this: Dullaron
Page 1 of 3 1 2 3

Link Copied to Clipboard
Who's Online Now
6 members (Reznor007, Cpt. Pugwash, simzy39, Lord Nightmare, sCZther, 1 invisible), 55 guests, and 2 robots.
Key: Admin, Global Mod, Mod
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Forum Statistics
Forums9
Topics9,236
Posts120,924
Members5,061
Most Online1,283
Dec 21st, 2022
Our Sponsor
These forums are sponsored by Superior Solitaire, an ad-free card game collection for macOS and iOS. Download it today!

Superior Solitaire
Forum hosted by www.retrogamesformac.com