EN
Cloud
R1BBIT · COMMUNITY

Projects

A question from the R1BBIT community

Washing Machine Mini-Game

This example uses an ESP32-P4 board with a 720×720 IPS display.

It demonstrates how easy it is to create your own mini-games, limited only by your imagination!
Washing Machine Mini-Game

You can also integrate real-world data into your mini-games, including weather forecasts, stock and cryptocurrency prices, readings from any sensor in the R1BBIT ecosystem, and virtually any data available through an API.

R1 BASIC
// =====================================================================
// WASHING MACHINE for R1BBIT
// Waveshare ESP32-P4 Smart 86 Box, ST7703 720x720
//
// A front-loading washing machine in a room. Behind the door glass the
// drum turns (holes and lifters move), colourful laundry tumbles,
// soapy water sloshes with a wavy surface, a thick white foam layer
// floats on top and soap bubbles rise.
//
// The power button (left of the display) starts a 3-minute programme:
// 0:00-0:12 FILL water and foam come in, the drum turns slowly
// 0:12-2:00 WASH the drum turns fast, reversing every 7 seconds
// 2:00-2:22 DRAIN the water runs out, the foam melts away
// 2:22-3:00 SPIN the drum spins up, laundry is pressed to the wall,
// then it spins down and the display shows END
// Pressing the button while running switches the machine off; the next
// press starts the programme again. The round power button left of the display turns
// the machine on and off (tap it): the drum slows down and stops, the
// display goes dark; tap again and it spins up and carries on.
//
// Only the door glass is redrawn every frame; the room and the machine
// body are drawn once.
// =====================================================================
CONFIG
// --------------------------------------------------
// Display: ST7703 720x720, MIPI-DSI
// --------------------------------------------------
DISPLAY_DRIVER ST7703
DISPLAY_BUS DSI
DISPLAY_W 720
DISPLAY_H 720
DISPLAY_RST 27 // display hardware reset pin
DISPLAY_BL 26 // backlight control pin
// --------------------------------------------------
// I2C: shared by touch controller and audio codec
// --------------------------------------------------
I2C0_SDA 7
I2C0_SCL 8
I2C0_FREQ 400000
// --------------------------------------------------
// Touch: GT911
// --------------------------------------------------
TOUCH_DRIVER GT911
TOUCH_I2C 0
TOUCH_RST 46 // touch controller reset pin
TOUCH_ADDR 0x5D // I2C device address
// --------------------------------------------------
// Audio codec: ES8311
// --------------------------------------------------
CODEC ES8311
CODEC_ADDR 0x18
CODEC_I2C 0
CODEC_I2S 0
CODEC_PA_PIN 53 // speaker amplifier
CODEC_PA_ACTIVE_LOW 0
// --------------------------------------------------
// I2S between ESP32 and ES8311
// --------------------------------------------------
I2S_MCLK 13
I2S_BCLK 12
I2S_WS 10
I2S_DOUT 9
I2S_DIN 11
AUDIO_OUT CODEC
AUDIO_IN CODEC
// --------------------------------------------------
// MicroSD, SDMMC 4-bit
// --------------------------------------------------
SDMMC_WIDTH 4
SDMMC_CLK 43
SDMMC_CMD 44
SDMMC_D0 39
SDMMC_D1 40
SDMMC_D2 41
SDMMC_D3 42
END_CONFIG
DISPLAY_INIT
// Canvas over the whole panel; frames are pushed with DISPLAY_UPDATE.
DISPLAY_INIT_CANVAS(0, 0, 720, 720)
TIMER_RESET
// ----------------------------- settings ------------------------------
CONST PI = 3.14159265
VAR CX = 360 // door centre
VAR CY = 425
VAR RG = 140 // radius of the door glass (everything animated is inside)
VAR WFULL = 30 // full water level, px below the centre
VAR WEMPTY = 152 // "no water": below the bottom of the drum
VAR FRAMEMS = 33 // ~30 fps
VAR REVMS = 7000 // the drum reverses every 7 s
VAR DRUMSPD = 0.255 // wash speed, rad per frame (3x the first version)
VAR SPINSPD = 0.62 // spin speed, rad per frame
// programme: end of each phase, seconds from the start
VAR TFILL = 12
VAR TWASH = 120
VAR TDRAIN = 142
VAR TEND = 180
VAR PBX = 318 // power button centre
VAR PBY = 121
// ------------------------------ laundry ------------------------------
// 9 pieces: distance from the drum centre, phase, own spin, size, colours,
// and a stripe flag (striped T-shirts and towels)
VAR NC = 9
VAR LR[9] = {94, 70, 100, 58, 86, 76, 50, 96, 66}
VAR LPH[9] = {0, 0.7, 1.4, 2.1, 2.8, 3.5, 4.2, 4.9, 5.6}
VAR LSP[9] = {0.05, -0.07, 0.04, 0.08, -0.05, 0.06, -0.09, 0.03, -0.06}
VAR LSZ[9] = {38, 32, 36, 30, 38, 33, 28, 34, 30}
VAR LCOL[9] = {0xE53950, 0xFFC233, 0x2F7DE1, 0x2EBF6B, 0x9B4DDB, 0xFF7A2E, 0xFF6FB5, 0x1FC7C7, 0xF2F2F2}
VAR LDRK[9] = {0x9E1F33, 0xB8861C, 0x1B4F99, 0x1C7F46, 0x63308F, 0xB2511C, 0xB34A7E, 0x138686, 0xA9B1BA}
VAR LLIT[9] = {0xFF8296, 0xFFE08A, 0x8CBBFF, 0x8CE8B4, 0xCDA0F5, 0xFFB48A, 0xFFB2DA, 0x8FF0F0, 0xFFFFFF}
VAR LSTR[9] = {0, 1, 0, 0, 1, 0, 0, 1, 0}
VAR LSH[5] = {1.0, 0.72, 0.95, 0.68, 0.86} // irregular outline of a cloth
// ------------------------------ bubbles ------------------------------
VAR NBB = 12
VAR BX[12], BY[12], BR[12], BW[12]
// ------------------------------- state -------------------------------
VAR T, A, SPD, DIR, LREV, TILT, T0, FT, BLINK, LBLK
VAR GRV, WR, WLV, FOAM, SPN, PH, PST, ELS, LSEC, ST, WT, FTG, RT, DEG, SPAN, S0, RR
VAR PWR, TCNT, TX, TY, PC
VAR I, J, AN, PX, PY, K, SA, X, DX, H, YT, YB, Y2, SXV, SYV, CC, CD, CL
VAR P0X, P0Y, P1X, P1Y, P2X, P2Y, P3X, P3Y, P4X, P4Y
VAR FX, FY, FR, HW
VAR WPX, WPY
T = 0
A = 0
SPD = 0
DIR = 1
LREV = 0
WLV = WEMPTY // the drum starts empty
FOAM = 0
SPN = 0
PH = 0
PST = 0
ELS = 0
LSEC = -1
BLINK = 0
LBLK = 0
PWR = 1
TCNT = 0
FOR I = 0 TO NBB - 1
BX[I] = CX - 100 + RND(200)
BY[I] = CY + WLV - RND(150)
BR[I] = 2 + RND(4)
BW[I] = RND(6.28)
NEXT
// ---------------------------- static scene ---------------------------
GOSUB DrawRoom
GOSUB DrawMachine
GOSUB DrawDisplay
GOSUB DrawPower
// ------------------------------ main loop ----------------------------
WHILE 1
T0 = TIMER_GET
// power button: one toggle per tap. A press counts on its second poll,
// so the touch controller has already reported the fresh coordinates.
IF TOUCH_PRESSED = 1 THEN
TCNT = TCNT + 1
IF TCNT = 2 THEN
TX = TOUCH_X - PBX
TY = TOUCH_Y - PBY
IF TX * TX + TY * TY <= 34 * 34 THEN
PWR = 1 - PWR
IF PWR = 1 THEN
// a new programme from the beginning
PST = T0
PH = 0
LREV = T0
LSEC = -1
ENDIF
GOSUB DrawPower
GOSUB DrawDisplay
ENDIF
ENDIF
ELSE
TCNT = 0
ENDIF
GOSUB Physics
GOSUB DrawGlass
// display: remaining time, once a second
IF PWR = 1 AND FLOOR(ELS) <> LSEC THEN
LSEC = FLOOR(ELS)
GOSUB DrawDisplay
ENDIF
// blinking "running" LED
IF T0 - LBLK >= 500 THEN
LBLK = T0
BLINK = 1 - BLINK
IF PWR = 0 OR PH = 4 THEN BLINK = 0
IF BLINK = 1 THEN
DISPLAY_FILL_CIRCLE(462, 104, 4, 0x38E1FF)
ELSE
DISPLAY_FILL_CIRCLE(462, 104, 4, 0x1B2A33)
ENDIF
ENDIF
DISPLAY_UPDATE
FT = TIMER_GET - T0
IF FT < FRAMEMS THEN
PAUSE FRAMEMS - FT
ELSE
PAUSE 1
ENDIF
WEND
END
// =====================================================================
// MOTION
// =====================================================================
// The programme phase sets targets for drum speed ST, water level WT
// and foam FTG; the real values ease towards them, so water flows in and
// out, foam grows and melts, and the drum speeds up and slows down
// smoothly. The water surface tilts with the speed.
Physics:
T = T + 1
ST = 0
WT = WLV
FTG = FOAM
IF PWR = 1 THEN
ELS = (T0 - PST) / 1000
IF ELS < TFILL THEN
PH = 0
ELSEIF ELS < TWASH THEN
PH = 1
ELSEIF ELS < TDRAIN THEN
PH = 2
ELSEIF ELS < TEND THEN
PH = 3
ELSE
PH = 4
ENDIF
// reverse the drum every REVMS while washing (not in the spin)
IF PH < 3 AND T0 - LREV >= REVMS THEN
LREV = T0
DIR = -DIR
ENDIF
IF PH = 0 THEN
ST = DIR * DRUMSPD * 0.4
WT = WFULL
FTG = 1
ELSEIF PH = 1 THEN
ST = DIR * DRUMSPD
WT = WFULL
FTG = 1
ELSEIF PH = 2 THEN
ST = DIR * DRUMSPD * 0.35
WT = WEMPTY
FTG = 0
ELSEIF PH = 3 THEN
ST = SPINSPD
// last 6 seconds: spin down
IF ELS > TEND - 6 THEN ST = 0
WT = WEMPTY
FTG = 0
ENDIF
ENDIF
// ease: the spin ramps up slowly, everything else faster
RT = 0.035
IF PH = 3 THEN RT = 0.012
SPD = SPD + (ST - SPD) * RT
// water flows in smoothly; it drains at a steady pace (about 20 s)
IF PH = 2 OR PH = 3 THEN
IF WLV < WEMPTY THEN WLV = WLV + 0.2
ELSE
WR = 0.025
WLV = WLV + (WT - WLV) * WR
ENDIF
FOAM = FOAM + (FTG - FOAM) * 0.02
IF PH = 3 AND PWR = 1 THEN
SPN = SPN + (1 - SPN) * 0.03
ELSE
SPN = SPN * 0.97
ENDIF
A = A + SPD
// GRV: 1 when the drum stands still - the laundry settles at the bottom
GRV = 1 - ABS(SPD) / 0.12
IF GRV < 0 THEN GRV = 0
TILT = SPD * 0.47
IF TILT > 0.15 THEN TILT = 0.15
IF TILT < -0.15 THEN TILT = -0.15
RETURN
// water surface height at x = SXV -> SYV
SurfY:
SYV = CY + WLV + TILT * (SXV - CX) + 4 * SIN(SXV * 0.045 + T * 0.25) + 2 * SIN(SXV * 0.11 - T * 0.4)
RETURN
// =====================================================================
// ROOM (drawn once)
// =====================================================================
DrawRoom:
// light wallpaper: cream background with thin vertical stripes
DISPLAY_FILL_RECT(0, 0, 720, 588, #F0E8DA)
FOR WPX = 0 TO 719 STEP 48
DISPLAY_FILL_RECT(WPX, 0, 12, 588, #E9DFCE)
DISPLAY_LINE(WPX + 15, 0, WPX + 15, 587, #F9F3E8)
DISPLAY_LINE(WPX + 45, 0, WPX + 45, 587, #DDD2BF)
NEXT
// repeating floral pattern
FOR WPY = 40 TO 560 STEP 80
FOR WPX = 24 TO 696 STEP 96
// stem and leaves
DISPLAY_LINE(WPX, WPY + 7, WPX, WPY + 29, #98A58A, 1)
DISPLAY_FILL_TRIANGLE(WPX, WPY + 22, WPX - 11, WPY + 13, WPX - 9, WPY + 23, #A6B299)
DISPLAY_FILL_TRIANGLE(WPX, WPY + 27, WPX + 11, WPY + 18, WPX + 9, WPY + 28, #A6B299)
// four petals and a golden centre
DISPLAY_FILL_CIRCLE(WPX - 5, WPY, 5, #CCA99D)
DISPLAY_FILL_CIRCLE(WPX + 5, WPY, 5, #CCA99D)
DISPLAY_FILL_CIRCLE(WPX, WPY - 5, 5, #D9B9AC)
DISPLAY_FILL_CIRCLE(WPX, WPY + 5, 5, #D9B9AC)
DISPLAY_FILL_CIRCLE(WPX, WPY, 3, #B79B62)
// small diamond between the flowers
DISPLAY_FILL_TRIANGLE(WPX + 48, WPY + 32, WPX + 45, WPY + 37, WPX + 51, WPY + 37, #B9BCA5)
DISPLAY_FILL_TRIANGLE(WPX + 48, WPY + 42, WPX + 45, WPY + 37, WPX + 51, WPY + 37, #B9BCA5)
NEXT
NEXT
// skirting board
DISPLAY_FILL_RECT(0, 588, 720, 14, 0xF2F4F6)
DISPLAY_LINE(0, 602, 719, 602, 0xA9B0B8, 2)
// tiled floor in perspective
DISPLAY_FILL_RECT(0, 604, 720, 116, 0xB9B2A8)
DISPLAY_FILL_RECT(0, 640, 720, 40, 0xB2AAA0)
DISPLAY_FILL_RECT(0, 680, 720, 40, 0xAAA297)
DISPLAY_LINE(0, 640, 719, 640, 0x9B9389, 1)
DISPLAY_LINE(0, 680, 719, 680, 0x9B9389, 1)
FOR I = -6 TO 6
DISPLAY_LINE(360 + I * 60, 604, 360 + I * 110, 719, 0x9B9389, 1)
NEXT
// soft shadow under the machine
DISPLAY_FILL_RECT(118, 640, 484, 34, 0x8E877E, 17)
DISPLAY_FILL_RECT(132, 644, 456, 24, 0x7A746C, 12)
RETURN
// =====================================================================
// MACHINE BODY (drawn once)
// =====================================================================
DrawMachine:
// feet
DISPLAY_FILL_RECT(172, 640, 42, 18, 0x33383E, 4)
DISPLAY_FILL_RECT(506, 640, 42, 18, 0x33383E, 4)
// body: rounded base + vertical strips = curved white enamel
DISPLAY_FILL_RECT(150, 58, 420, 594, 0xC9CFD7, 24)
FOR I = 0 TO 19
K = (I - 7) / 12
K = 1 - K * K
IF K < 0 THEN K = 0
CC = FLOOR(205 + 45 * K)
DISPLAY_FILL_RECT(160 + I * 20, 66, 20, 578, CC * 65536 + (CC + 2) * 256 + (CC + 4))
NEXT
DISPLAY_LINE(176, 62, 544, 62, 0xFFFFFF, 2)
DISPLAY_LINE(176, 646, 544, 646, 0xA6AEB8, 2)
// control panel: seam line
DISPLAY_LINE(160, 178, 560, 178, 0xAEB6C0, 2)
DISPLAY_LINE(160, 181, 560, 181, 0xFFFFFF, 1)
// detergent drawer
DISPLAY_FILL_RECT(176, 90, 110, 64, 0xEEF1F4, 8)
DISPLAY_RECT(176, 90, 110, 64, 0xAAB2BD, 2, 8)
DISPLAY_FILL_RECT(190, 136, 82, 9, 0xBFC6CF, 4)
DISPLAY_LINE(192, 137, 270, 137, 0x9AA2AD, 1)
DISPLAY_TEXT(176, 160, "R1BBIT", 0x6C7682, 12)
// display window
DISPLAY_FILL_RECT(344, 88, 132, 66, 0x9EA6B1, 12)
DISPLAY_FILL_RECT(348, 92, 124, 58, 0x0D1317, 10)
DISPLAY_TEXT(344, 160, "40C 1200 RPM COTTON", 0x7D8794, 12)
// program knob with tick marks
FOR I = 0 TO 11
AN = I * PI / 6
DISPLAY_LINE(512 + COS(AN) * 40, 122 + SIN(AN) * 40, 512 + COS(AN) * 45, 122 + SIN(AN) * 45, 0x8C95A1, 2)
NEXT
DISPLAY_FILL_CIRCLE(514, 126, 35, 0xA9B1BC)
DISPLAY_FILL_CIRCLE(512, 122, 34, 0xE4E8ED)
DISPLAY_FILL_CIRCLE(512, 122, 29, 0xC8CFD8)
DISPLAY_FILL_CIRCLE(510, 119, 25, 0xF3F5F8)
DISPLAY_FILL_CIRCLE(505, 113, 9, 0xFFFFFF)
DISPLAY_LINE(512, 122, 512 + COS(-2.2) * 22, 122 + SIN(-2.2) * 22, 0x3A4048, 4)
DISPLAY_FILL_CIRCLE(512 + COS(-2.2) * 22, 122 + SIN(-2.2) * 22, 3, 0x38E1FF)
// door: shadow, chrome ring, gasket
DISPLAY_FILL_CIRCLE(CX + 5, CY + 7, 179, 0xA6AEB9)
DISPLAY_FILL_CIRCLE(CX, CY, 178, 0xBCC4CE)
DISPLAY_FILL_CIRCLE(CX - 2, CY - 2, 172, 0xF3F6F9)
DISPLAY_FILL_CIRCLE(CX, CY, 166, 0xDDE2E8)
DISPLAY_FILL_CIRCLE(CX + 1, CY + 1, 158, 0xB4BCC7)
DISPLAY_FILL_CIRCLE(CX, CY, 152, 0x7A8390)
DISPLAY_FILL_CIRCLE(CX, CY, 146, 0x454D58)
DISPLAY_ARC(CX, CY, 169, 3, 190, 260, 0xFFFFFF)
// hinges on the left, handle on the right
DISPLAY_FILL_RECT(CX - 190, CY - 78, 16, 38, 0x99A2AE, 5)
DISPLAY_FILL_RECT(CX - 190, CY + 40, 16, 38, 0x99A2AE, 5)
DISPLAY_FILL_RECT(CX + 166, CY - 34, 20, 68, 0x9EA7B2, 9)
DISPLAY_FILL_RECT(CX + 169, CY - 30, 13, 60, 0xE8ECF0, 7)
// service hatch bottom-right
DISPLAY_FILL_RECT(488, 610, 62, 26, 0xE6EAEE, 6)
DISPLAY_RECT(488, 610, 62, 26, 0xA9B1BC, 1, 6)
RETURN
// phase name + remaining time "2:59", or "END" / "OFF"
DrawDisplay:
DISPLAY_FILL_RECT(352, 95, 104, 52, 0x0D1317)
IF PWR = 0 THEN
DISPLAY_TEXT(376, 110, "OFF", 0x3A4A52, 32)
ELSEIF PH = 4 THEN
DISPLAY_TEXT(376, 110, "END", 0x2EE57A, 32)
ELSE
IF PH = 0 THEN DISPLAY_TEXT(356, 97, "FILL", 0x2A8FA6, 12)
IF PH = 1 THEN DISPLAY_TEXT(356, 97, "WASH", 0x2A8FA6, 12)
IF PH = 2 THEN DISPLAY_TEXT(356, 97, "DRAIN", 0x2A8FA6, 12)
IF PH = 3 THEN DISPLAY_TEXT(356, 97, "SPIN", 0x2A8FA6, 12)
K = TEND - FLOOR(ELS)
I = K - FLOOR(K / 60) * 60
IF I < 10 THEN
DISPLAY_TEXT(370, 112, "" + FLOOR(K / 60) + ":0" + I, 0x38E1FF, 32)
ELSE
DISPLAY_TEXT(370, 112, "" + FLOOR(K / 60) + ":" + I, 0x38E1FF, 32)
ENDIF
ENDIF
RETURN
// power button: chrome cap, power symbol, LED ring (green on, red off)
DrawPower:
IF PWR = 1 THEN
PC = 0x2EE57A
ELSE
PC = 0xD9483B
ENDIF
DISPLAY_FILL_CIRCLE(PBX + 2, PBY + 3, 23, 0xA9B1BC)
DISPLAY_FILL_CIRCLE(PBX, PBY, 22, PC)
DISPLAY_FILL_CIRCLE(PBX, PBY, 19, 0xD5DBE2)
DISPLAY_FILL_CIRCLE(PBX - 1, PBY - 1, 16, 0xF6F8FA)
// power symbol: open ring + vertical bar
IF PWR = 1 THEN
PC = 0x1FA85A
ELSE
PC = 0x7D8794
ENDIF
DISPLAY_ARC(PBX, PBY + 1, 8, 3, 300, 360, PC)
DISPLAY_ARC(PBX, PBY + 1, 8, 3, 0, 240, PC)
DISPLAY_LINE(PBX, PBY - 10, PBX, PBY - 1, PC, 3)
RETURN
// =====================================================================
// DOOR GLASS (redrawn every frame)
// =====================================================================
DrawGlass:
// drum: dark stainless steel with a soft light in the middle
DISPLAY_FILL_CIRCLE(CX, CY, RG, 0x1C2127)
DISPLAY_FILL_CIRCLE(CX, CY, RG - 14, 0x252B32)
DISPLAY_FILL_CIRCLE(CX - 8, CY - 10, RG - 44, 0x2D343C)
DISPLAY_FILL_CIRCLE(CX - 16, CY - 20, RG - 84, 0x343C45)
IF ABS(SPD) > 0.34 THEN
// spinning too fast to see holes and lifters: they blur into rings
DISPLAY_ARC(CX, CY, 124, 4, 0, 360, 0x15191E)
DISPLAY_ARC(CX, CY, 102, 4, 0, 360, 0x191E24)
DISPLAY_ARC(CX, CY, 118, 34, 0, 360, 0x2E353E)
ELSE
GOSUB DrumParts
ENDIF
// soapy water: columns from the wavy surface down to the drum edge,
// lighter near the surface, deeper blue at the bottom
IF WLV < RG THEN
GOSUB DrawWater
ENDIF
// laundry tumbling with the drum
FOR I = 0 TO NC - 1
GOSUB DrawCloth
NEXT
// foam and bubbles only while there is foam
IF FOAM > 0.06 AND WLV < RG THEN
GOSUB DrawFoam
ENDIF
// glass: reflections and the rubber rim
DISPLAY_ARC(CX, CY, RG - 16, 8, 200, 248, 0xB9C5D1)
DISPLAY_ARC(CX, CY, RG - 32, 3, 208, 236, 0x8D99A6)
DISPLAY_FILL_CIRCLE(CX - 70, CY - 92, 5, 0xE6EDF4)
DISPLAY_ARC(CX, CY, RG - 22, 4, 20, 50, 0x5A6672)
DISPLAY_ARC(CX, CY, RG + 3, 7, 0, 360, 0x454D58)
RETURN
// perforation and lifters turning with the drum
// (few enough holes that the fast drum never seems to turn backwards:
// the spacing is more than twice the turn per frame)
DrumParts:
FOR I = 0 TO 11
AN = A + I * PI / 6
DISPLAY_FILL_CIRCLE(CX + COS(AN) * 124, CY + SIN(AN) * 124, 3, 0x111418)
NEXT
FOR I = 0 TO 7
AN = A + I * PI / 4 + 0.39
DISPLAY_FILL_CIRCLE(CX + COS(AN) * 102, CY + SIN(AN) * 102, 3, 0x161A1F)
NEXT
// three lifters (paddles)
FOR I = 0 TO 2
AN = A + I * 2 * PI / 3
DISPLAY_FILL_TRIANGLE(CX + COS(AN) * 98, CY + SIN(AN) * 98, CX + COS(AN - 0.16) * 138, CY + SIN(AN - 0.16) *
138, CX + COS(AN + 0.16) * 138, CY + SIN(AN + 0.16) * 138, 0x4B5560)
DISPLAY_LINE(CX + COS(AN) * 100, CY + SIN(AN) * 100, CX + COS(AN - 0.14) * 136, CY + SIN(AN - 0.14) * 136,
0x6E7884, 2)
NEXT
RETURN
DrawWater:
FOR X = CX - RG + 3 TO CX + RG - 3 STEP 6
DX = X + 3 - CX
H = SQRT(RG * RG - DX * DX) - 2
SXV = X + 3
GOSUB SurfY
YT = SYV
IF YT < CY - H THEN YT = CY - H
YB = CY + H
IF YB > YT THEN
Y2 = YT + 10
IF Y2 > YB THEN Y2 = YB
DISPLAY_FILL_RECT(X, YT, 6, Y2 - YT + 1, 0x7FB0D8)
IF YB > Y2 THEN
YT = Y2 + 28
IF YT > YB THEN YT = YB
DISPLAY_FILL_RECT(X, Y2, 6, YT - Y2 + 1, 0x4C7FB0)
IF YB > YT THEN DISPLAY_FILL_RECT(X, YT, 6, YB - YT + 1, 0x2F5987)
ENDIF
ENDIF
NEXT
RETURN
// white foam on the surface (two layers of puffs, scaled by FOAM) and
// soap bubbles rising in the drum
DrawFoam:
FOR I = 0 TO 17
FX = CX - 122 + I * 14.5 + 4 * SIN(T * 0.07 + I)
SXV = FX
GOSUB SurfY
FY = SYV - 3 + 2 * SIN(T * 0.11 + I * 1.7)
FR = (10 + 5 * ABS(SIN(I * 2.3)) + 2 * SIN(T * 0.09 + I)) * FOAM
GOSUB DrawPuff
NEXT
FOR I = 0 TO 10
FX = CX - 105 + I * 21 + 5 * SIN(T * 0.05 + I * 0.8)
SXV = FX
GOSUB SurfY
FR = (7 + 3 * ABS(SIN(I * 1.9)) + 1.5 * SIN(T * 0.13 + I)) * FOAM
FY = SYV - 13 * FOAM - FR * 0.6 + 2 * SIN(T * 0.08 + I * 2.1)
GOSUB DrawPuff
NEXT
IF FOAM >= 0.3 THEN
GOSUB Bubbles
ENDIF
RETURN
Bubbles:
FOR I = 0 TO NBB - 1
BY[I] = BY[I] - 0.8 - BR[I] * 0.25
BW[I] = BW[I] + 0.12
PX = BX[I] + 3 * SIN(BW[I])
DX = PX - CX
DX = DX * DX + (BY[I] - CY) * (BY[I] - CY)
IF BY[I] < CY - RG + 18 OR DX > (RG - 10) * (RG - 10) THEN
BX[I] = CX - 100 + RND(200)
SXV = BX[I]
GOSUB SurfY
BY[I] = SYV - 6
BR[I] = 2 + RND(4)
ELSE
DISPLAY_CIRCLE(PX, BY[I], BR[I], 0xDDEAF5)
DISPLAY_FILL_CIRCLE(PX - BR[I] * 0.35, BY[I] - BR[I] * 0.35, 1, 0xFFFFFF)
ENDIF
NEXT
RETURN
// one piece of laundry I: an irregular pentagon with a sleeve, a fold and
// a highlight. Below the water line it is darker (wet, under water).
// In the spin (SPN -> 1) the laundry is pressed against the drum wall and
// turns with it; at full speed it smears into coloured arcs (motion blur).
DrawCloth:
AN = A * (0.9 + 0.1 * SPN) + LPH[I]
RR = LR[I] + (100 - LR[I]) * SPN
IF ABS(SPD) > 0.3 AND SPN > 0.8 THEN
GOSUB ClothBlur
ELSE
GOSUB ClothShape
ENDIF
RETURN
ClothShape:
PX = CX + RR * (1 - 0.15 * GRV) * COS(AN)
PY = CY + (24 + 40 * GRV) * (1 - SPN) + RR * (0.7 + 0.3 * SPN - 0.35 * GRV) * SIN(AN)
SA = T * LSP[I] + LPH[I] * 2
K = LSZ[I]
SXV = PX
GOSUB SurfY
IF PY > SYV + 6 THEN
CC = LDRK[I]
CD = LDRK[I]
CL = LCOL[I]
ELSE
CC = LCOL[I]
CD = LDRK[I]
CL = LLIT[I]
ENDIF
P0X = PX + COS(SA) * K * LSH[0]
P0Y = PY + SIN(SA) * K * LSH[0]
P1X = PX + COS(SA + 1.257) * K * LSH[1]
P1Y = PY + SIN(SA + 1.257) * K * LSH[1]
P2X = PX + COS(SA + 2.513) * K * LSH[2]
P2Y = PY + SIN(SA + 2.513) * K * LSH[2]
P3X = PX + COS(SA + 3.770) * K * LSH[3]
P3Y = PY + SIN(SA + 3.770) * K * LSH[3]
P4X = PX + COS(SA + 5.027) * K * LSH[4]
P4Y = PY + SIN(SA + 5.027) * K * LSH[4]
// sleeve / corner sticking out
DISPLAY_FILL_CIRCLE(P1X, P1Y, K * 0.34, CD)
DISPLAY_FILL_POLYGON(P0X, P0Y, P1X, P1Y, P2X, P2Y, P3X, P3Y, P4X, P4Y, CC)
// fold and highlight
DISPLAY_LINE(P0X, P0Y, P3X, P3Y, CD, 3)
DISPLAY_LINE((P1X + PX) / 2, (P1Y + PY) / 2, (P4X + PX) / 2, (P4Y + PY) / 2, CD, 2)
// stripes across striped pieces
IF LSTR[I] = 1 THEN
DISPLAY_LINE((P0X + P1X) / 2, (P0Y + P1Y) / 2, (P3X + P4X) / 2, (P3Y + P4Y) / 2, 0xFFFFFF, 3)
DISPLAY_LINE((P1X * 3 + P2X) / 4, (P1Y * 3 + P2Y) / 4, (P4X * 3 + P3X) / 4, (P4Y * 3 + P3Y) / 4, 0xFFFFFF, 3)
ENDIF
DISPLAY_FILL_CIRCLE(PX - K * 0.25, PY - K * 0.25, K * 0.18, CL)
RETURN
// laundry piece I as a blurred arc along the drum wall
ClothBlur:
DEG = AN * 57.29578
SPAN = ABS(SPD) * 57.3 * 1.6
IF SPAN > 150 THEN SPAN = 150
IF SPD > 0 THEN DEG = DEG - SPAN
S0 = DEG - FLOOR(DEG / 360) * 360
K = LSZ[I] * 0.75
IF S0 + SPAN <= 360 THEN
DISPLAY_ARC(CX, CY, RR, K, S0, S0 + SPAN, LCOL[I])
ELSE
DISPLAY_ARC(CX, CY, RR, K, S0, 360, LCOL[I])
DISPLAY_ARC(CX, CY, RR, K, 0, S0 + SPAN - 360, LCOL[I])
ENDIF
RETURN
// one foam puff at FX, FY, radius FR: grey shadow, white body, highlight.
// Puffs that would cross the drum edge are skipped.
DrawPuff:
DX = FX - CX
HW = SQRT(DX * DX + (FY - CY) * (FY - CY)) + FR
IF HW < RG - 6 AND FR >= 2 THEN
DISPLAY_FILL_CIRCLE(FX + 2, FY + 3, FR, 0xAFBCC9)
DISPLAY_FILL_CIRCLE(FX, FY, FR, 0xEEF3F7)
DISPLAY_FILL_CIRCLE(FX - FR * 0.15, FY - FR * 0.2, FR * 0.75, 0xF9FBFD)
DISPLAY_FILL_CIRCLE(FX - FR * 0.35, FY - FR * 0.4, FR * 0.28, 0xFFFFFF)
ENDIF
RETURN

Video

1
0 replies

Sign in to reply