// Rainbow Example // Source code file: MainActivity.kt // Draw a circle with spokes connecting // its center to its perimeter. package it372.ssmith.rainbow import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.foundation.Canvas import androidx.compose.foundation.background import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.size import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.drawscope.Fill import androidx.compose.ui.graphics.drawscope.Stroke import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { MainLayout() } } } @Composable fun MainLayout( ) { Column( modifier = Modifier.padding(20.dp) .fillMaxSize( )) { Canvas( modifier = Modifier .padding(20.dp) .size(300.dp, 300.dp) .background(Color(0xFFC0C0C0)) .fillMaxSize( )) { // Use the acronym ROYGBIV to remember // the order of the rainbow colors // Draw red stripe drawRect(color = Color(0xFFFF0000), topLeft = Offset(x=0f, y=100f), size = Size(width=775f, height=50f), style = Fill ) // Draw orange stripe drawRect(color = Color(0xFFFF8000), topLeft = Offset(x=0f, y=150f), size = Size(width=775f, height=50f), style = Fill ) // Draw yellow stripe drawRect(color = Color(0xFFFFFF00), topLeft = Offset(x=0f, y=200f), size = Size(width=775f, height=50f), style = Fill ) // Draw green stripe drawRect(color = Color(0xFF00FF00), topLeft = Offset(x=0f, y=250f), size = Size(width=775f, height=50f), style = Fill ) // Draw blue stripe drawRect(color = Color(0xFF0080FF), topLeft = Offset(x=0f, y=300f), size = Size(width=775f, height=50f), style = Fill ) // Draw indigo stripe drawRect(color = Color(0xFF8000FF), topLeft = Offset(x=0f, y=350f), size = Size(width=775f, height=50f), style = Fill ) // Draw magenta stripe drawRect(color = Color(0xFFE000E0), topLeft = Offset(x=0f, y=400f), size = Size(width=775f, height=50f), style = Fill ) } } } @Preview(showBackground = true) @Composable fun GreetingPreview() { MainLayout( ) }