? Splitting a group of things from an array of things (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Splitting a group of things from an array of things

  • #1 ✎ 340 spaceturtles Video Games I like to play video games! Hobbies Avatar Block I didn't change my avatar for 30 days. Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Basically I want to do this: What's happening: 1. an array of pixels drawn as a 2d square exists 2. a randomly drawn line from one side to the other (also works if it loops back to the same side) shows where pixels have been removed 3. the square array is split into two smaller arrays of half-ish squares How can I do this in code? The things can be anything from numbers to characters to sprites Another diagram I drew in paint in case the previous one is too small: Posted Edited by spaceturtles
  • #2 ✎ 297 MZ952 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Third Year My account is over 3 years old Website Reading I like to read books! Hobbies It can probably be handled by a scanline sort of ordeal (I'm thinking polygon filling). But uh, how exactly do you want the output? You say "half-ish squares," but what does that really mean? Are you looking to modify the data in the OG square array? Posted
  • #3 ✎ 340 spaceturtles Video Games I like to play video games! Hobbies Avatar Block I didn't change my avatar for 30 days. Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength I'm trying to recreate the break-off mechanics from games like Space Engineers and KSP. If two halves of an object occupy a 2d grid and the parts holding the pieces together are removed, the pieces are put into their own grid arrays and become their own entities Posted
  • #4 ✎ 1041 Yttria in what form is the input line? if you can get it in slope-intercept form and the split is always along a line, deciding which elements go in which bin is easy. Posted
  • #5 ✎ 340 spaceturtles Video Games I like to play video games! Hobbies Avatar Block I didn't change my avatar for 30 days. Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength The line represents the objects removed from the grid, not necessarily a literal line. If you have a grid arranged like this: 00000000 01100110 01111110 01100110 01111110 01100110 00000000 Where 1s are existing objects and 0s represent an imaginary part of the array which doesn't exist (deleted elements, for instance) Then if you remove the "middle" parts: 00000000 01100110 01100110 01100110 01100110 01100110 00000000 It creates two groups of things. I can understand how they could connect to each other using an array of adjacent IDs per object, but I don't know how to separate them into two or more new arrays using this information: 0000 0000 0110 0110 0110 0110 0110 0110 0110 0110 0110 0110 0000 0000 another example: 00000000 01100110 01100110 01100110 01111110 01100110 00000000 00000000 01100110 01100110 01100000 01100110 01100110 00000000 0000 0000 0110 0110 0110 0110 0110 0000 0110 0110 0000 0000 0110 0110 0000 Posted Edited by spaceturtles
  • #6 ✎ 340 spaceturtles Video Games I like to play video games! Hobbies Avatar Block I didn't change my avatar for 30 days. Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength I think I found what I've been looking for for the past three months After searching google for it using roughly matching terms I came across "finding connected components in graphs" which explains my problem quite well in the search string and gives me https://www.geeksforgeeks.org/connected-components-in-an-undirected-graph/ and a bunch of others. Now I just need to implement it. Thanks for trying help Posted