ScratchData LogoScratchData
Back to gregatku's profile

2D & 3D Lists

GRgregatku•Created February 7, 2021
2D & 3D Lists
19
11
306 views
View on Scratch

Instructions

2D & 3D Lists - Click the Green Flag, then Set the Depth, Height & Width values for the 2 Lists. & click [Click me ...] to the fill the 2 Lists accordingly. ... When the Lists have information in them: Set the 3rd-D, Row & Col values to identify a list item & click [Click me ...] to the find that item in the 2 Lists.

Description

Created by @gregatku for use in Coding Classes for Kids Unlimited, for whom I work as a Coding teacher. This project is really about teaching techniques for manipulating a 1D-List (which is what all Scratch Lists really are) so as to make it effectively a 2D-List (say, for a rectangle of pixels containing maybe each pixel's colour) or a 3D-List (say for a Direction, y-position & x-position of a Sprite &/or its clones), so the items added to the Lists in this project's case are used deliberately to identify which item in each List it is. Normally the information in the Lists would be relevant to the Project you are actually working on. For example, in my "Conway's Life No Clones" project I use a 2D-List just like this one to represent the State of a Cell in the rectangular grid, where the value is either 0 (dead cell), or 1 (live cell). As you will see from the Code adding items to a List is pretty straightforward, and usually when you add the List items at start up, you often initialise them to the same value (say 0), then the code would be even simpler, eg for the 3D-list all you'd need to do it put "add 0 to 3D-list" inside a "repeat (depth * height * width)" loop. Mine was more complicated because I wanted to put identifying information in the List Items, so I could easily verify when trying to grab a particular value from either list given a 3rd-D/Row/Col reference that it actually retrieved the correct value. It was a good thing I did that because in my first attempt to code the calculation for an Item# in the 3D-List, my formula had a bug, so it was very easy to identify this and fix it. So the important thing in this whole project is knowing how to retrieve the correct item from the list. Here are the formulas it uses to do this: 2D-item: ((Row - 1)*width) + Col 3D-item: ((((3rd-D - 1)*height) + (Row - 1))*width)+Col

Project Details

Project ID484580676
CreatedFebruary 7, 2021
Last ModifiedJuly 23, 2021
SharedFebruary 8, 2021
Visibilityvisible
CommentsAllowed