How to resolve the algorithm Simple turtle graphics step by step in the Yabasic programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Simple turtle graphics step by step in the Yabasic programming language

Table of Contents

Problem Statement

The first turtle graphic discussed in Mindstorms: Children, Computers, and Powerful Ideas by Seymour Papert is a simple drawing of a house. It is a square with a triangle on top for the roof. For a slightly more advanced audience, a more practical introduction to turtle graphics might be to draw a bar chart.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Simple turtle graphics step by step in the Yabasic programming language

Source code in the yabasic programming language

// Rosetta Code problem: http://rosettacode.org/wiki/Simple_turtle_graphics
// Adapted from Python to Yabasic by Galileo, 01/2022

import turtle
 
sub rectang(width, height)
    local i
    
    for i = 1 to 2
        move(height)
        turn(-90)
        move(width)
        turn(-90)
    next
end sub
 
sub square(size)
    rectang(size, size)
end sub
 
sub triang(size)
    local i
    
    for i = 1 to 3
        move(size)
        turn(120)
    next
end sub
 
sub house(size)
    turn(180)
    square(size)
    triang(size)
    turn(180)
end sub
 
sub barchart(lst$, size)
    local t$(1), t(1), n, m, i, scale, width
    
    n = token(lst$, t$())
    redim t(n)
    
    for i = 1 to n
        t(i) = val(t$(i))
        if t(i) > m m = t(i)
    next
    
    scale = size/m
    width = size/n
    for i = 1 to n
        rectang(t(i)*scale, width)
        pen(false)
        move(width)
        pen(true)
    next
    pen(false)
    move(-size)
    pen(true)
end sub
 
startTurtle()
color 255, 255, 255
turn(90)
house(150)
pen(false)
move(10)
pen(true)
barchart("0.5 0.333 2 1.3 0.5", 200)

  

You may also check:How to resolve the algorithm Pseudo-random numbers/Middle-square method step by step in the RPL programming language
You may also check:How to resolve the algorithm Fractal tree step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Convex hull step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Caesar cipher step by step in the Haskell programming language
You may also check:How to resolve the algorithm Elementary cellular automaton/Infinite length step by step in the Elixir programming language