More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
post
page
◑ Python IDE Dashboard

Lighthouse Animation Challenge

lighthouseThe purpose of this challenge is to use a Python program to demonstrate how frame-based animations can be implemented.

For this challenge we are using the Processing.py library.

The code below will run the setup() procedure once, when the program starts. Then the animateLighthouse() procedure will be called 20 times per second (based on the frame rate), indefinitely.

This code makes use of two transformations:

  • A translation: 2D translations are often used to re-position or animate objects on screen (gliding effect)
  • A rotation: in this case, a rotation is applied to animate the light beam. The angle of rotation increments by 0.5 degrees between each frame.

lighthouse-translation-rotation

Python Code


Your Challenge


Complete this code to animate the boat:

  • The boat should translate/glide horizontally from left to right.
  • Once the boat fully disappears to the right of the screen, it should reappear to the left.

lighthouse-translation

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with:

Python Turtle – WordArt Challenge

In this challenge we will use Python Turtle to draw text on screen and customise the appearance of our text.

To do so we have created our own font as a Python dictionary. Each letter of the alphabet is represented as a set of (x,y) coordinates as follows:
character-A-dot-to-dot
We will then use these coordinates to trace a line using Python Turtle using a “dot-to-dot” approach.

WordArt #1: Dot-To-Dot Text


WordArt #2: Oblique Text


WordArt #3: Circular Text


Your Challenge


Customise the code above to create your own WordArt effects such as:

  • Growing Text: Write text where each letter is bigger than the previous one.
  • Backwards Text: Write text where the text is written backwards.
  • Vertical Text: Write text where the text is written vertically.
  • Wrapped Text: Write text where long text is written across multiple lines.
  • Reflective Text: Write text with its own reflection underneath.
Tagged with: ,

Confetti Artwork Challenges

confetti-blueFor these challenges we will produce on screen artwork by randomly positioning confetti on different shapes of canvas. Our code will use Python Turtle to draw the canvas and the confetti.

Square Canvas


Check how the code provided below randomly positions each confetti within the boundaries of a square canvas:

Circular Canvas


Check how the code provided below randomly positions each confetti within the boundaries of a circular canvas:

Challenge #1: Ring Canvas


Adapt the code provided below to randomly position each confetti within the boundaries of a ring/doughnut shape:

Challenge #2: Diamond Canvas


Adapt the code provided below to randomly position each confetti within the boundaries of a diamond shape:

Challenge #3: Triangular Canvas


Adapt the code provided below to randomly position each confetti within the boundaries of an equilateral triangle:

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: ,

Confetti Challenge

confettiIn this Python challenge we will write a script to randomly draw confetti on a canvas while ensuring that none of the confetti overlap with each other!

Problem Decomposition


In this challenge we will need to solve the following problems:

  1. How to draw confetti on screen?
  2. How to randomly position a confetti on screen?
  3. How detect if a confetti is overlapping with another confetti?
  4. How to detect an overlap with any of the confetti already positioned on screen?
  5. How to randomise the colour of a confetti?
Problem Solution
How to draw confetti on screen? Using the Python Turtle library we can easily draw circles on the screen.
How to randomly position a confetti on screen? By generating two random numbers representing the x and y coordinates of the confetti. These coordinates will be used in Python Turtle to draw a circle on screen at the right (x,y) location.
How detect if a confetti is overlapping with another confetti? Using Pythagoras formula we can calculate the distance between two confetti.
If this distance is lower than 2*radius of a confetti, then the two confetti are overlapping.
confetti-pythagoraconfetti-overlap-detection
How to detect an overlap with any of the confetti already positioned on screen? When a confetti is placed on screen its coordinates will be appended to a list. Each time a new set of coordinates is generated we will iterate through the list of confetti one at a time (using a for loop) to check if an overlap is detected. If so, we will generate a new set of random (x,y) coordinates and repeat this process until no overlap is detected. We will then append this final set of coordinates to the list of confetti.
How to randomise the colour of a confetti? We want all confetti to have a purple shade. To do so we will randomise their colour code using the RGB codes with a random Red value (between 50 and 255), a Green value set to 0, a random Blue value (between 50 and 255).

Implementation


Check the Python code for this challenge:

Your Python Challenge


Generate confetti of random sizes (random radius between 10 and 30 pixels).
Adapt your algorithm to make sure these confetti still don’t overlap.
confetti-overlap-radius
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: ,

Binary Shift using Python

Did You Know?

Everything that is stored on a computer is stored as binary code. Binary code is made of bits (0 or 1). We often use Bytes to store data. A Byte is made of eight bits and can be used to store any whole number between 0 to 255. Check it yourself, click on the binary digits to create your own binary number:

1286432168421
11111111

128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255


Binary Left Shift


A binary left shift is used to multiply a binary number by two. It consists of shifting all the binary digits to the left by 1 digit and adding an extra digit at the end with a value of 0.
binary-left-shift

Binary Right Shift


A binary right shift is used to divide a binary number by two. It consists of shifting all the binary digits to the right by 1 digit and adding an extra digit at the beginning (to the left) with a value of 0.
binary-right-shift

Multiple-digit Left and Right Shifts


A two-digit left shift consists of two consecutive left shifts on a binary number and is the equivalent of timing this number by 22=4.

A three-digit left shift consists of three consecutive left shifts on a binary number and is the equivalent of timing this number by 23=8. (and so on…)

A two-digit right shift consists of two consecutive right shifts on a binary number and is the equivalent of dividing this number by 22=4.

A three-digit right shift consists of three consecutive right shifts on a binary number and is the equivalent of dividing this number by 23=8. (and so on…)

Python Challenge


The purpose of this challenge is to write a Python script to perform a binary shift. Our Python program will:

  • Ask the user to enter an 8-bit binary number,
  • Ask the user whether they would like to perform a left shift or a right shift,
  • Ask the user whether the number of digits they want to shift,
  • Output the resulting 8-bit binary number.

Test Plan

Test # Input Values Expected Output Actual Output
Binary Number Left/Right Shift? Number of digits
#1 00111100 Left 1 01111000
#2 00111100 Right 1 00011110
#3 00111100 Left 2 111110000
#4 00111100 Right 2 00001111
#5 00001111 Left 3 01111000
#6 00001111 Right 3 0000001

Python Code



unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Code Breaker Challenges – Series 3

padlock-closed

Crack the Codes! (open full screen)


In this set of challenges, you will analyse some pseudocode to try to get the pass codes required to move on to the next levels. Levels will get more and more complex as your progress through these challenges. Will you be able to crack all the codes?

Tagged with:

Code Breaker Challenges – Series 2

padlock-closed

Crack the Codes! (open full screen)


In this set of challenges, you will analyse some pseudocode to try to get the pass codes required to move on to the next levels. Levels will get more and more complex as your progress through these challenges. Will you be able to crack all the codes?

Tagged with:

Min, Max, Mean, Median and Mod

maths-blackboardIn this Python challenge we will manipulate a list of numbers to calculate the Min, Max, Mean, Median and Mod of all these numbers.

First you may want to refresh your maths skills and check the meaning of these terms: http://www.purplemath.com/modules/meanmode.htm

Our Python code will first generate a random list of numbers.

We then added a few lines of code to calculate the min value. Your task is to complete this code to calculate the max, mean, median and mod values using a similar approach.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: ,

Code Breaker Challenges – Series 1

padlock-closed

Crack the Codes! (open full screen)


In this set of challenges, you will analyse some pseudocode to try to get the pass codes required to move on to the next levels. Levels will get more and more complex as your progress through these challenges. Will you be able to crack all the codes?

Tagged with:

Computer Networks – Quiz!

Take the Quiz! (open full screen)


Tagged with: ,
Privacy Overview

This website will store some information about your preferences on your own computer inside a tiny file called a cookie. A cookie is a small piece of data that a website asks your browser to store on your computer or mobile device. The cookie allows the website to remember your actions or preferences over time.

You can delete all cookies that are already on your computer, and you can set most browsers to prevent them from being placed. However, if you do this, you may have to manually adjust some preferences every time you visit a site, and some services and functionalities may not work.

Most browsers support cookies, but you can set your browser to decline them and can delete them whenever you like. You can find instructions here for how you can do that on various browsers.

This website uses cookies to:

  1. Identify you as a returning user and to count your visits in traffic statistics analysis
  2. Remember your custom display preferences (such as light/dark theme option)
  3. Provide other usability features, including tracking whether you have already given your consent to cookies

Enabling cookies is not strictly necessary for the website to work but it will provide you with a better browsing experience.

The cookie-related information is not used to identify you personally and is not used for any purpose other than those described here.

There may also be other types of cookies created after you have visited this website. This site uses Google Analytics, a popular web analytics service that uses cookies to help to analyse how users use the site. The information generated by the cookie about your use of this website (including your IP address) will be transmitted to and stored by Google on servers in the United States. Google will use this information for the purpose of evaluating your use of other website, compiling reports on website activity, and providing other services relating to website activity and internet usage. Google may also transfer this information to third parties where required to do so by law, or where such third parties process the information on Google’s behalf. Google undertakes not to associate your IP address with any other data held by Google.