With any bigger than 300, the drawing won't fit neatly on the Stage. We use a conditional statement to test if the user input a valid size number.The user's input will be stored in the "Answer" block. This number will be the size of the largest triangle in pixels. The "Ask () And Wait" block, found in the "Sensing" Palette, prompts the user to input a number up to 300.The first six blocks in our main sequence size, position, and orient our Sprite then clear the Stage of any previous drawings.
Ultra fractal animation posting to da code#
Now that we know its height, we can center the triangle drawing vertically by calculating centeredY = "0 - height / 2"ģrd Challenge: Write the main code sequence below to make the bug draw fractal triangles based on user input. That formula is height = (√ 3 / 2) sideLength. To find the vertical center, we first need to find the height of the equilateral triangle because it's not the same as the length of its sides.We're considering the base of this triangle to be its width. So if we know the Stage has a center point of X = 0, then to center the triangle horizontally drawing should start at centeredX = "0 - sideLength / 2".The X limits are 240 and -240, and the Y limits are 180 and -180. The Stage is a four-quadrant coordinate grid with the origin (0, 0) in the center.The Sierpiński procedure draws the fractal in a spiraling, counter-clockwise pattern from the bottom left corner of the largest triangle. The next custom procedure centers the entire drawing on the Stage by calculating the appropriate starting position for the Sprite based on the user's desired size input.Add the code blocks below to your new "centerTheDrawing" procedure:.Type "sideLength" to replace "number1".Make a third block named "centerTheDrawing".This process is repeated three times total as required by the "Repeat" loop inside the "Else" statement, drawing two more triangles of 150 pixels at different positions on the Stage. The procedure returns to the "Move" and "Turn" blocks from the first call, moves 300 pixels, and turns 120 degrees. In the second call, "levelOfRecursions" does equal 0, executing a call to the "triangle" procedure, which draws a triangle with a side length of 150 pixels. The "Move" and "Turn" blocks are not yet reached and nothing is drawn on the Stage. Since 1 is not equal to 0, the procedure subtracts 1 from "levelOfRecursions" and calls itself with an argument of 0. The procedure first checks if "levelOfRecursions" is equal to 0. The procedure starts with user input of 1 level of recursion and a largest triangle side length of 300 pixels. Add the code blocks below to your new "triangle" procedure:.Programmers call these input definitions "parameters". This number will set the side length of each triangle drawn. Click the "Options" text drop-down arrow.Type "triangle" in the field to name the block.Click on the "More Blocks" palette and then click the "Make A Block" button.
Ultra fractal animation posting to da how to#
Here's how to make a custom "triangle" block: We'll need three custom blocks for this project. The "Make A Block" feature allows you create custom procedures that you can reuse in your Scratch projects. For example, a scoreboard has variables that contain points.Ģnd Challenge: Make three custom blocks for drawing fractal art.
![ultra fractal animation posting to da ultra fractal animation posting to da](https://dm0qx8t0i9gc9.cloudfront.net/thumbnails/video/Bu140tZ/videoblocks-digital-animation-of-a-looping-fractal-shape_hgzehaonpf_thumbnail-1080_01.png)
![ultra fractal animation posting to da ultra fractal animation posting to da](https://images-na.ssl-images-amazon.com/images/I/51DHQ17CAPL._SX315_BO1,204,203,200_.jpg)
Fractals are repeating patterns that look similar at every scale of magnification. There is an interesting example of recursion found in nature called a fractal.